trace

package
v0.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 3, 2026 License: Apache-2.0 Imports: 14 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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

func AddSpanProcessor(tp *sdktrace.TracerProvider, session *auth.Session, cfg Config) error

AddSpanProcessor creates and registers a Braintrust span processor.

func GetSpanProcessor

func GetSpanProcessor(session *auth.Session, cfg Config) (sdktrace.SpanProcessor, error)

GetSpanProcessor creates a Braintrust span processor.

func Permalink(span oteltrace.Span) (string, error)

Permalink returns a URL to the span in the Braintrust UI.

func SetParent

func SetParent(ctx context.Context, parent Parent) context.Context

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

func GetParent(ctx context.Context) (bool, Parent)

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.

func (Parent) Attr

func (p Parent) Attr() attribute.KeyValue

Attr returns the OTel attribute for this parent.

func (Parent) String

func (p Parent) String() string

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.
cloudwego/eino
Package eino provides OpenTelemetry tracing for CloudWeGo Eino applications.
Package eino provides OpenTelemetry tracing for CloudWeGo Eino applications.
genai
Package genai provides automatic instrumentation for google.golang.org/genai.
Package genai provides automatic instrumentation for google.golang.org/genai.
genkit
Package genkit provides automatic instrumentation for Firebase Genkit.
Package genkit provides automatic instrumentation for Firebase Genkit.
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
Package internal provides shared middleware functionality for OpenTelemetry tracers.
Package internal provides shared middleware functionality for OpenTelemetry tracers.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL