Go
<!-- status: ga language: go verified_by: go/sdk/wtotel/wtotel_test.go::TestInitSendsTracesWithKeyHeader -->
Go
Send traces from a Go service to Watchtower over OTLP/HTTP with the standard OpenTelemetry SDK. Nothing Watchtower-specific is installed: the SDK reads the standard OTEL_* variables.
Create a project, then an ingestion key (
wti_...) with theingest:tracesscope. The key is shown once.Point the SDK at the gateway and pass the key in the
x-watchtower-keyheader (Authorization: Bearer wti_...works too):
export OTEL_EXPORTER_OTLP_ENDPOINT=https://ingest.example.com
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_EXPORTER_OTLP_HEADERS=x-watchtower-key=wti_YOUR_KEY
export OTEL_SERVICE_NAME=my-serviceAdd the SDK and run this once. The endpoint above is the gateway's base URL; the SDK appends
/v1/traces.
go get go.opentelemetry.io/otel go.opentelemetry.io/otel/sdk go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttppackage main
import (
"context"
"go.opentelemetry.io/otel"
"go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp"
sdktrace "go.opentelemetry.io/otel/sdk/trace"
)
func main() {
ctx := context.Background()
exp, err := otlptracehttp.New(ctx) // reads OTEL_EXPORTER_OTLP_*
if err != nil {
panic(err)
}
tp := sdktrace.NewTracerProvider(sdktrace.WithBatcher(exp))
defer tp.Shutdown(ctx)
otel.SetTracerProvider(tp)
_, span := otel.Tracer("onboarding").Start(ctx, "hello-watchtower")
span.End()
}Open the project's onboarding screen. It polls
GET /v1/projects/{prj}/onboarding/first-eventand turns green when the first span arrives. Then open the trace in the trace explorer.