The Go SDK is designed so that a TruLayer ingest outage never becomes an application outage. This page documents the default behavior and the dry-run mode for teams who want zero network activity.Documentation Index
Fetch the complete documentation index at: https://docs.trulayer.ai/llms.txt
Use this file to discover all available pages before exploring further.
Default — drop and warn
When the ingest API is unreachable (network error) or returns a transient status (5xx or 429), the SDK:
- Retries the batch up to 3× with exponential backoff (500 ms, 1 s, 2 s).
- On the third failure, drops the batch and logs a warning via
log.Printf. - Returns control to the background goroutine immediately — user code never blocks on network I/O.
4xx responses (other than 429) are dropped on the first attempt with a single log.Printf warning. These indicate a permanent rejection (bad API key, malformed payload) that retrying cannot fix.
User code never sees a batch failure surface as an error. Trace.End enqueues the trace and returns immediately; the background batch sender owns all retry and discard logic.
This is the right default for almost every production service. A dead ingest endpoint should degrade observability, not customer-facing behavior.
TRULAYER_DRY_RUN=true — zero network activity
Set TRULAYER_DRY_RUN to 1, true, or yes (case-insensitive) to disable all network calls entirely. The SDK constructs traces and spans as normal, but no HTTP requests are made and no warnings are emitted.
FlushandShutdownreturnnilimmediately.SubmitFeedbackis a no-op and returnsnil.- No API key is required (pass an empty string or any placeholder value).
Local mock server — full payload inspection
When you need to assert on the exact payloads the SDK sends (field values, span ordering, token counts), point the client at a localhttptest.Server instead of using dry-run mode. See Testing for the complete pattern.
Shutdown error handling
Shutdown(ctx) returns an error only when the context is cancelled or times out before the final flush completes. A non-nil error from Shutdown means some buffered traces may not have been sent.
In production, always set a deadline and log the error:
Shutdown does not return an error when the ingest API rejects or drops a batch. Batch failures are logged, not propagated. If you need programmatic detection of flush failures, use a custom WithHTTPClient with a transport that records responses.
Decision guide
| Scenario | Recommended approach |
|---|---|
| Production HTTP server | Default (drop + warn) |
| Background worker with SLO on ingest | Default (drop + warn); monitor log.Printf output |
| CI unit tests — verify no panics | TRULAYER_DRY_RUN=true |
| CI integration tests — assert on payloads | httptest.Server + WithBaseURL |
| Local development without an API key | TRULAYER_DRY_RUN=true |
| Tests with custom transport or proxy | WithHTTPClient |
See also
- Testing —
httptest.Serverpattern for asserting on captured payloads. - Configuration — all
ClientOptionfunctions and theTRULAYER_DRY_RUNenv var. - Go SDK reference — full signatures for
Client,Flush, andShutdown.