Class BraintrustContext

java.lang.Object
dev.braintrust.trace.BraintrustContext

public final class BraintrustContext extends Object
Used to identify the braintrust parent for spans and experiments. SDK users probably don't want to use this and instead should use BraintrustTracing or Eval
  • Method Details

    • ofExperiment

      public static io.opentelemetry.context.Context ofExperiment(@Nonnull String experimentId, @Nonnull io.opentelemetry.api.trace.Span span)
      Creates a context for an experiment parent.
    • setParentInBaggage

      public static io.opentelemetry.context.Context setParentInBaggage(@Nonnull io.opentelemetry.context.Context ctx, @Nonnull String parentType, @Nonnull String parentId)
      Sets the parent in baggage for distributed tracing.

      Baggage propagates automatically via W3C headers when propagators are configured, allowing parent context to flow across process boundaries.

      Parameters:
      ctx - the context to update
      parentType - the type of parent (e.g., "experiment_id", "project_name", "playground_id")
      parentId - the ID of the parent
      Returns:
      updated context with baggage set
    • fromContext

      @Nullable public static BraintrustContext fromContext(io.opentelemetry.context.Context context)
      Retrieves a BraintrustContext from the given Context.
    • projectId

      public Optional<String> projectId()
    • experimentId

      public Optional<String> experimentId()