Go

Embed
Preview of the card
<a href="https://forumulate.com/p/watchtower/docs/sdk-go"><img src="https://forumulate.com/api/public/orgs/watchtower/spaces/docs/pages/1bc6c318-2e47-4490-995b-aa903fba40fe/social-card.svg?v=3e7ae33eec8b" alt="Go" width="600" height="315"></a>

<!-- status: ga language: go -->

Go: the wtotel helper

watchtower/sdk/wtotel wires the OpenTelemetry Go SDK (Apache-2.0) to Watchtower in one call: OTLP/HTTP exporters, gzip, batching, retry, the resource attributes service.name, service.version and deployment.environment.name, and an optional disk buffer so telemetry survives offline periods.

shutdown, err := wtotel.Init(ctx, wtotel.Options{
	Endpoint:    "https://ingest.example.com", // gateway base URL, no path
	IngestKey:   os.Getenv("WT_INGEST_KEY"),    // wti_..., scope ingest:traces (+ ingest:metrics, ingest:logs)
	ServiceName: "checkout",
	Environment: "production",
	Signals:     wtotel.Traces | wtotel.Metrics | wtotel.Logs, // default: Traces
	BufferDir:   "/var/lib/checkout/wt-buffer",                // optional offline buffer
})
if err != nil {
	log.Fatal(err)
}
defer shutdown(context.Background()) // flushes batches

After Init, use otel.Tracer, otel.Meter and the OTel log bridge as usual; the helper installs the global providers.

Offline buffer

With BufferDir set, an export that fails (network error, HTTP 429 or 5xx) is written to a disk queue instead of being retried in memory. The next export that succeeds replays the queue, oldest first. Delivery is at-least-once: a crash during replay can send a stored batch twice. The queue is capped at BufferMaxBytes (default 512 MiB); when it is full the oldest segments are dropped. The ingest key is never written to disk.

For zero-code instrumentation see the Go instrumentation guide; for a plain OTel setup without the helper see the Go onboarding guide.

Updated