github.com/Project-White-Rabbit/bitfab-go. Go ≥ 1.21. Runtime dependencies: github.com/google/uuid.
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.
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.
(c *Client) FlushTraces
timeout. Go has no atexit - always defer client.FlushTraces(...) 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.
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
- Span HTTP sends run in background goroutines.
FlushTracesdrains them - Trace state is stored in a mutex-protected package-level map keyed by
traceID