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
- Source: github.com/trulayer/client-go
- Issues / bug reports: github.com/trulayer/client-go/issues
- Module:
github.com/trulayer/client-goon pkg.go.dev
Client
The entry point for the SDK. Construct once per process and reuse — Client is safe for concurrent use from multiple goroutines.
NewClient
Shutdown when the process exits to drain the send queue.
apiKey and set TRULAYER_DRY_RUN=true for offline development or CI.
Client options
NewTrace
*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
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
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
nil.
Trace
A unit of work that groups one or more spans. Create via Client.NewTrace.
Methods
NewSpan
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
*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
*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 withlog.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.Printfwarning is emitted. NewTraceandNewSpannever return errors — failures are contained inside the SDK.
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.