Documentation
¶
Overview ¶
Package trace provides distributed tracing functionality for Braintrust experiments.
This package is built on OpenTelemetry and integrates with the Braintrust Client for session-based authentication.
To enable tracing, create a TracerProvider and Braintrust client:
tp := trace.NewTracerProvider()
defer tp.Shutdown(context.Background())
bt, err := braintrust.New(tp,
braintrust.WithAPIKey(os.Getenv("BRAINTRUST_API_KEY")),
braintrust.WithProject("my-project"),
)
if err != nil {
log.Fatal(err)
}
Once the client is created, create spans using OpenTelemetry:
tracer := bt.Tracer("my-app")
ctx, span := tracer.Start(ctx, "my-operation")
span.SetAttributes(attribute.String("user.id", "123"))
span.End()
Index ¶
- Constants
- func AddSpanProcessor(tp *sdktrace.TracerProvider, session *auth.Session, cfg Config) error
- func GetSpanProcessor(session *auth.Session, cfg Config) (sdktrace.SpanProcessor, error)
- func Permalink(span oteltrace.Span) (string, error)
- func SetParent(ctx context.Context, parent Parent) context.Context
- type Config
- type Parent
- type ParentType
- type SpanFilterFunc
Constants ¶
const ParentOtelAttrKey = "braintrust.parent"
ParentOtelAttrKey is the OpenTelemetry attribute key used to associate spans with Braintrust parents. This enables spans to be grouped under specific projects or experiments in the Braintrust platform. Parents are formatted as "project_id:{uuid}" or "experiment_id:{uuid}".
Variables ¶
This section is empty.
Functions ¶
func AddSpanProcessor ¶
AddSpanProcessor creates and registers a Braintrust span processor.
func GetSpanProcessor ¶
GetSpanProcessor creates a Braintrust span processor.
func SetParent ¶
SetParent will add a parent to the given context. Any span started with that context will be marked with that parent, and sent to the given project or experiment in Braintrust.
The parent is stored in both context values (for same-process access) and W3C baggage (for distributed tracing across process boundaries).
Example:
ctx = trace.SetParent(ctx, trace.Parent{Type: trace.ParentTypeProjectName, ID: "my-project"})
_, span := tracer.Start(ctx, "database-query")
Types ¶
type Config ¶
type Config struct {
// Default parent for spans
DefaultProjectID string
DefaultProjectName string
// Span filtering
FilterAISpans bool
EnableBuiltinAdkTraces bool // if false (default), drop spans from Google ADK (gcp.vertex.agent) to avoid duplicates
SpanFilterFuncs []SpanFilterFunc
// Debug
EnableConsoleLog bool
// Test override: provide custom exporter (e.g., memory exporter for tests)
Exporter sdktrace.SpanExporter
// Logger
Logger logger.Logger
}
Config holds configuration for Braintrust tracing
type Parent ¶
type Parent struct {
Type ParentType
ID string
}
Parent represents where data goes in Braintrust - a project, an experiment, etc.
func GetParent ¶
GetParent returns the parent from the context and a boolean indicating if it was set. It first checks the context value (for same-process access), then falls back to baggage (for distributed tracing across process boundaries).
func NewParent ¶ added in v0.0.3
func NewParent(t ParentType, id string) Parent
NewParent creates a new parent with the given type and ID.
type ParentType ¶
type ParentType string
ParentType represents the different places spans can be sent to in Braintrust - projects, experiments, etc.
const ( // ParentTypeProjectName is the type of parent that represents a project by name. ParentTypeProjectName ParentType = "project_name" // ParentTypeProjectID is the type of parent that represents a project by ID. ParentTypeProjectID ParentType = "project_id" // ParentTypeExperimentID is the type of parent that represents an experiment by ID. ParentTypeExperimentID ParentType = "experiment_id" )
func (ParentType) IsValid ¶
func (p ParentType) IsValid() bool
IsValid returns true if the ParentType is a valid type.
type SpanFilterFunc ¶
type SpanFilterFunc func(span sdktrace.ReadOnlySpan) int
SpanFilterFunc decides which spans to send to Braintrust. Return >0 to keep, <0 to drop, 0 to not influence.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package attachment provides utilities for creating and managing attachments in Braintrust traces.
|
Package attachment provides utilities for creating and managing attachments in Braintrust traces. |
|
contrib
|
|
|
adk
Package adk provides OpenTelemetry tracing callbacks for Google ADK agents.
|
Package adk provides OpenTelemetry tracing callbacks for Google ADK agents. |
|
all
Package all imports all available Braintrust tracing integrations for use with Orchestrion.
|
Package all imports all available Braintrust tracing integrations for use with Orchestrion. |
|
anthropic
Package anthropic provides automatic instrumentation for the Anthropic Go SDK.
|
Package anthropic provides automatic instrumentation for the Anthropic Go SDK. |
|
genai
Package genai provides automatic instrumentation for google.golang.org/genai.
|
Package genai provides automatic instrumentation for google.golang.org/genai. |
|
github.com/sashabaranov/go-openai
Package traceopenai provides automatic instrumentation for github.com/sashabaranov/go-openai.
|
Package traceopenai provides automatic instrumentation for github.com/sashabaranov/go-openai. |
|
langchaingo
Package langchaingo provides OpenTelemetry tracing for LangChainGo applications.
|
Package langchaingo provides OpenTelemetry tracing for LangChainGo applications. |
|
openai
Package openai provides automatic instrumentation for the OpenAI Go SDK.
|
Package openai provides automatic instrumentation for the OpenAI Go SDK. |
|
a2a
module
|
|
|
bedrockruntime
module
|
|
|
cloudwego/eino
module
|
|
|
genkit
module
|
|
|
Package internal provides shared middleware functionality for OpenTelemetry tracers.
|
Package internal provides shared middleware functionality for OpenTelemetry tracers. |