Skip to main content
The Go SDK does not ship a separate testing package. Instead, tests use the standard library’s net/http/httptest package together with WithBaseURL and WithHTTPClient to intercept every ingest and feedback POST. This gives you full access to the JSON payloads the SDK sends, with no external dependencies and no network calls.

How it works

  1. Start an httptest.Server that records incoming request bodies.
  2. Pass its URL to trulayer.NewClient via WithBaseURL.
  3. Run your instrumented code.
  4. Call c.Flush(ctx) or c.Shutdown(ctx) to drain the buffer synchronously.
  5. Assert on the recorded payloads.
The integration tests in the SDK repository follow this exact pattern and are the canonical reference.

Basic example

Reusable recorder helper

For projects with more than a few tests, extract the recorder into a shared helper:
Use it from any test:

Testing feedback submissions

SubmitFeedback is synchronous, so no flush is needed before asserting:

Smoke tests with dry-run mode

When you just need to verify that your instrumentation code runs without panics — and do not need to assert on payload contents — set TRULAYER_DRY_RUN=true. The SDK constructs all trace and span objects normally but makes no HTTP calls and emits no warnings.
Or set the environment variable in the test itself:
Use the httptest.Server approach when payload correctness matters and dry-run mode when it does not.

See also

  • Failure behavior — drop-and-warn defaults and when Shutdown returns an error.
  • Configuration — all ClientOption functions, including WithBaseURL and WithHTTPClient.
  • Go SDK reference — full signatures for Client, Flush, Shutdown, and SubmitFeedback.