github.com/Project-White-Rabbit/bitfab-go. Go ≥ 1.25. Runtime dependencies: github.com/google/uuid, go.opentelemetry.io/otel, go.opentelemetry.io/otel/trace, go.opentelemetry.io/otel/sdk.
Framework Integrations
No framework-native adapters are shipped for Go yet. Instrument Go code manually viaclient.Span / client.Start - see the Go SDK guide. Framework coverage status: Frameworks overview.
Package Constants
Constructor
NewClient
Option
WithServiceURL
WithEnabled
false: Span still executes the callback, Start returns a no-op *ActiveSpan, no data sent.
Transport environment variables
type Client
Opaque struct. Construct via NewClient.
Span lookup types
CapturedSpan contains the normalized span identity, parent, name, type, input, output, contexts, prompt, metadata, metrics, errors, and timestamps.
(c *Client) Span
fn inside a traced span. fn’s return value is captured as the span output.
Returns: fn’s (any, error) return values.
Errors: Only fn’s own error, captured on the span and returned to the caller. Tracing never fails the call: an unknown WithType value degrades to custom (with a one-time warning) instead of returning an error, and any internal instrumentation failure runs fn untraced rather than crashing the host.
(c *Client) Start
defer span.End().
Returns a child context carrying the span, and an *ActiveSpan for recording data. When enabled == false, returns the original context and a zero *ActiveSpan whose methods are all no-ops.
Spans exist only where you create them: nesting is automatic, but only between spans that exist. One wrapper around the outermost function records a single-node trace. See Instrumentation.
(c *Client) FlushTraces
timeout. Returns false when an export failed or the deadline expired. Use it for a mid-run flush, such as before reading a span back with GetTraceSpan.
(c *Client) Close
false when an export failed or the deadline expired. A closed client no longer records spans.
Go has no atexit - always defer client.Close(...) in main().
(c *Client) GetFunction
(c *Client) GetTraceSpan
traceID is the canonical Bitfab trace ID. Set exactly one of the span’s Bitfab SpanLookup.ID or SpanLookup.Name. Name lookup defaults to the last match; use FirstSpanOccurrence or SpanOccurrenceAt(index) to override it. A miss returns nil, nil.
type SpanFunc
type SpanOption
WithName
traceFunctionKey for Span, or the spanName arg for Start.
WithType
"llm", "agent", "function", "guardrail", "handoff", "custom". Validated at span creation time for Span (returns an error on invalid). Defaults to "custom".
WithFunctionName
span_data.function_name.
WithInput
Span - for Start, use ActiveSpan.SetInput.
WithCaptureWhen
CaptureWhenNested records the span only when ctx contains an active Bitfab parent span. Without a parent, Span runs the callback untraced and Start returns the original context with a no-op ActiveSpan. The default is CaptureWhenAlways; unknown values warn once and use that default.
type Function
(*Client).GetFunction(key). Fluent wrapper that binds traceFunctionKey.
(f *Function) Span
(f *Function) Start
type ActiveSpan
Returned by Start. All methods are safe on nil, safe under recover(), and idempotent where noted.
(s *ActiveSpan) SetInput
nil receiver.
(s *ActiveSpan) SetOutput
(s *ActiveSpan) SetError
(s *ActiveSpan) AddContext
span_data.contexts. No-op when context == nil.
(s *ActiveSpan) SetPrompt
span_data.prompt. No-op on empty string.
(s *ActiveSpan) End
sync.Once. Sends the span in a background goroutine. Any panic inside the send path is recovered so the host app never crashes.
Trace-Level API
type ContextEntry
type CurrentSpan
GetCurrentSpan returns nil outside a span; both methods are safe on a nil receiver and return "".
type CurrentTrace
GetCurrentTrace.
(ct *CurrentTrace) TraceID
nil receiver, where it returns "".
(ct *CurrentTrace) SetSessionID
(ct *CurrentTrace) SetMetadata
(ct *CurrentTrace) AddContext
(ct *CurrentTrace) Drop
dropped instead of completed, keeping only a skeleton audit row. Safe on a nil receiver (a no-op, so GetCurrentTrace(ctx).Drop() outside a span does nothing). Never panics.
GetCurrentTrace
nil when ctx carries no active span. Callers must nil-check.
Concurrency Model
- Nested span context is carried on
context.Context- safe across goroutines that inherit the context - Goroutines that do not inherit the context will not see the parent span
- Spans are queued on a private OpenTelemetry batching worker, one per client, started lazily on the first span. Queueing is non-blocking;
FlushTracesandClosedrain the worker - Trace state is stored in a mutex-protected package-level map keyed by
traceID