Module:Documentation Index
Fetch the complete documentation index at: https://docs.bitfab.ai/llms.txt
Use this file to discover all available pages before exploring further.
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
| Param | Type | Description |
|---|---|---|
apiKey | string | Empty/whitespace disables tracing with log.Println |
opts | ...Option | Functional options |
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.
(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: Returns fmt.Errorf with message bitfab: invalid span type %q, must be one of: llm, agent, function, guardrail, handoff, custom if WithType is given an unknown value. fn’s own error is captured on the span and returned to the caller.
(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
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 CurrentTrace
GetCurrentTrace.
(ct *CurrentTrace) SetSessionID
(ct *CurrentTrace) SetMetadata
(ct *CurrentTrace) AddContext
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
Error Behavior Summary
| Situation | Behavior |
|---|---|
Empty apiKey | log.Println warning, enabled forced to false |
SpanFunc returns error | Captured on span, returned to caller |
Invalid WithType value | (*Client).Span returns an error; Start does not validate |
| Panic inside user code | Not recovered — your code panics. The SDK only recovers panics on its own send path |
| Span transport failure | Swallowed. User’s return value / error passes through |
ActiveSpan methods on nil receiver | No-op |
End() called multiple times | Only the first call has effect (sync.Once) |
GetCurrentTrace(ctx) outside a span | Returns nil |