Go compile-time instrumentation

Instrument Go applications at build time, without code changes.

Compile-time instrumentation for Go automatically instruments your application during the build, capturing telemetry from many popular libraries and frameworks without any changes to your source code. It works by hooking into the Go build process and injecting instrumentation as your application is compiled, so the resulting binary contains the instrumentation code with no runtime agent required.

How it works

The otelc tool wraps your regular go build invocation. During the build it:

  1. Intercepts compilation of each package using the Go toolchain’s -toolexec mechanism.
  2. Matches packages and functions against a set of instrumentation rules that describe where telemetry hooks belong.
  3. Injects lightweight hook points into the matched functions and links them to OpenTelemetry instrumentation code.

Because instrumentation is baked into the binary at compile time, it also covers third-party dependencies you don’t control, and it adds no runtime attach or startup steps.

When to use it

Compile-time instrumentation is one of several zero-code options for Go: it complements the Auto SDK, while eBPF-based instrumentation is available through OBI. Compile-time instrumentation is a good fit when you can modify the build pipeline but not the source code, when you want instrumentation inside third-party libraries, or when you can’t run a privileged agent alongside your application.


Getting started

Capture telemetry from a Go application without writing any instrumentation code.

Supported libraries

Libraries and frameworks instrumented out of the box.

Configuration

Configure the otelc tool and the telemetry produced by instrumented applications.

Troubleshooting

Diagnose issues with Go compile-time instrumentation.