Skip to main content
This page documents the public surface of github.com/trulayer/client-go. For narrative usage, see the overview and tutorial. For auto-instrumentation, see instruments.
Status: Alpha. APIs are pre-1.0.0 and may change between minor releases. Pin a specific version in production until 1.0.0 ships.

Source and issues

Client

The entry point for the SDK. Construct once per process and reuse — Client is safe for concurrent use from multiple goroutines.

NewClient

Constructs a client. Pass your API key as the first argument. Call Shutdown when the process exits to drain the send queue.
Pass an empty string for apiKey and set TRULAYER_DRY_RUN=true for offline development or CI.

Client options

NewTrace

Begins a new trace. Returns the *Trace and a child context that carries the trace — pass the child context to downstream calls so spans can link to it.

Trace options

Flush

Blocks until all enqueued traces have been attempted. The context bounds how long Flush waits. Use this at the end of a short-lived process (e.g. a Lambda handler) to ensure all traces ship before the runtime reclaims memory.

Shutdown

Drains the queue, performs a final flush, and stops the background goroutine. Subsequent NewTrace calls still succeed but the resulting traces will not be sent. Call at process exit — typically via defer. Pass a context with a deadline to cap the drain time:

SubmitFeedback

Posts a feedback record for a previously ingested trace. Returns a non-nil error on transport or server failure. In dry-run mode it is a no-op and returns nil.

Trace

A unit of work that groups one or more spans. Create via Client.NewTrace.

Methods

NewSpan

Creates a new span attached to this trace. The returned context carries the span, so nested spans can find their parent automatically.

Span options

Span

A unit of work inside a trace (e.g. an LLM call, a tool invocation, a retrieval step). Create via Trace.NewSpan.

Methods

SpanType

Pass one of these constants to Trace.NewSpan. The TruLayer dashboard uses the span type to group and filter spans.

Context helpers

TraceFromContext

Returns the active *Trace stored in ctx by NewTrace, or nil if no trace is present. Use this in middleware or auto-instrumentation code that receives a context from the caller rather than constructing a trace itself.

SpanFromContext

Returns the active *Span stored in ctx by NewSpan, or nil if no span is present. Useful for attaching metadata inside deeply nested helpers without threading the span explicitly.

Types

TraceData

Wire representation of a trace. Returned when you read traces from the API; also the shape of the payload sent to the ingest endpoint.

SpanData

Wire representation of a span.

FeedbackData

Payload for Client.SubmitFeedback.

Auto-instrumentation

InstrumentOpenAI and InstrumentAnthropic live in optional sub-modules. See auto-instrumentation for full documentation.

Environment variables

When dry-run mode is active, NewTrace and NewSpan still return valid objects so your code runs normally — no traces are sent over the network.

Error handling

The SDK never panics and never propagates transport or serialisation errors to your call site. Failed flushes are logged with log.Printf and the traces are dropped. In dry-run mode all network operations are skipped silently.
  • Batches that fail to send are retried up to three times with exponential backoff.
  • After retries are exhausted, the batch is dropped and a log.Printf warning is emitted.
  • NewTrace and NewSpan never return errors — failures are contained inside the SDK.
To detect dropped traces in production, watch for trulayer: prefixed log lines at ERROR level from the SDK’s logger. A future release will expose an OnError hook — track github.com/trulayer/client-go/issues for availability.