Skip to main content
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.

Default — drop and warn

When the ingest API is unreachable (network error) or returns a transient status (5xx or 429), the SDK:
  1. Retries the batch up to with exponential backoff (500 ms, 1 s, 2 s).
  2. On the third failure, drops the batch and logs a warning via log.Printf.
  3. Returns control to the background goroutine immediately — user code never blocks on network I/O.
Non-retryable 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.
In dry-run mode:
  • Flush and Shutdown return nil immediately.
  • SubmitFeedback is a no-op and returns nil.
  • No API key is required (pass an empty string or any placeholder value).
Dry-run mode is the recommended default for CI pipelines and unit tests that just need to verify your instrumentation code runs without panics.

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 local httptest.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

See also

  • Testinghttptest.Server pattern for asserting on captured payloads.
  • Configuration — all ClientOption functions and the TRULAYER_DRY_RUN env var.
  • Go SDK reference — full signatures for Client, Flush, and Shutdown.