Go

Embed
Preview of the card
<a href="https://forumulate.com/p/watchtower/docs/instrumentation-go"><img src="https://forumulate.com/api/public/orgs/watchtower/spaces/docs/pages/c53bcf38-6013-4244-99b1-7fbff4fc95b9/social-card.svg?v=3e7ae33eec8b" alt="Go" width="600" height="315"></a>

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

Go: zero-code instrumentation

Go has no runtime to hook, so zero-code means eBPF: the OpenTelemetry Go auto-instrumentation (opentelemetry-go-instrumentation) attaches to a running binary on Linux and records spans for net/http, database/sql, gRPC and Kafka. It needs a privileged process next to the service (CAP_SYS_PTRACE and CAP_BPF, or root); if that is not possible use the SDK route in the onboarding guide for Go.

  1. Create a project, then an ingestion key (wti_...) with the ingest:traces scope. The key is shown once.

  2. Point the instrumentation at the gateway and pass the key in the x-watchtower-key header:

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-service
export OTEL_GO_AUTO_TARGET_EXE=/usr/local/bin/my-service
  1. Run the released otel-go-instrumentation binary (from the opentelemetry-go-instrumentation releases) as root on the same host or in the same pid namespace, with the variables above:

sudo -E ./otel-go-instrumentation
  1. Send one request to the service, then open the project's onboarding screen: it turns green when the first span arrives.

Updated