Skip to main content
Module: 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 via client.Span / client.Start - see the Go SDK guide. Framework coverage status: Frameworks overview.

Package Constants

Constructor

NewClient

Option

WithServiceURL

WithEnabled

When 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

Executes 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

Start/End-style span for instrumenting existing functions. Always call 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

Waits for all pending background span deliveries, up to timeout. Go has no atexit - always defer client.FlushTraces(...) in main().

(c *Client) GetFunction

(c *Client) GetTraceSpan

Fetches one persisted span without loading its trace. 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

Defaults to traceFunctionKey for Span, or the spanName arg for Start.

WithType

One of "llm", "agent", "function", "guardrail", "handoff", "custom". Validated at span creation time for Span (returns an error on invalid). Defaults to "custom".

WithFunctionName

Recorded as span_data.function_name.

WithInput

One arg stored directly. Multiple args stored as a slice. Only relevant to Span - for Start, use ActiveSpan.SetInput.

type Function

Obtained via (*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

One arg stored directly. Multiple args stored as a slice. No-op on nil receiver.

(s *ActiveSpan) SetOutput

(s *ActiveSpan) SetError

(s *ActiveSpan) AddContext

Appends the map as one entry on span_data.contexts. No-op when context == nil.

(s *ActiveSpan) SetPrompt

Overwrites span_data.prompt. No-op on empty string.

(s *ActiveSpan) End

Idempotent via 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

Returns the active span’s canonical Bitfab span and trace IDs. GetCurrentSpan returns nil outside a span; both methods are safe on a nil receiver and return "".

type CurrentTrace

Returned by GetCurrentTrace.

(ct *CurrentTrace) TraceID

Returns the canonical Bitfab trace ID. Safe on a nil receiver, where it returns "".

(ct *CurrentTrace) SetSessionID

(ct *CurrentTrace) SetMetadata

Shallow-merges with existing trace metadata. Later keys win.

(ct *CurrentTrace) AddContext

Appends. Accumulates across calls.

(ct *CurrentTrace) Drop

Flags the trace to be dropped. Once flagged, spans that complete afterward are not uploaded at all, and the flag rides out on the completion payload, so at completion the server scrubs any payloads that already raced out (the trace, its external trace, and sibling spans), deletes the archived S3 objects, and marks it 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

Returns 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. FlushTraces drains them
  • Trace state is stored in a mutex-protected package-level map keyed by traceID

Error Behavior Summary