Using instrumentation libraries

Go does not support truly automatic instrumentation like other languages today. Instead, you’ll need to depend on instrumentation libraries that generate telemetry data for a particular instrumented library. For example, the instrumentation library for net/http will automatically create spans that track inbound and outbound requests once you configure it in your code.

Setup

Each instrumentation library is a package. In general, this means you need to go get the appropriate package. For example, to get the instrumentation libraries maintained in the Contrib repository run the following:

go get go.opentelemetry.io/contrib/instrumentation/{import-path}/otel{package-name}

Then configure it in your code based on what the library requires to be activated.

Getting Started provides an example showing how to set up instrumentation for a net/http server.

Available packages

A full list of instrumentation libraries available can be found in the OpenTelemetry registry.

Next steps

Instrumentation libraries can do things like generate telemetry data for inbound and outbound HTTP requests, but they don’t instrument your actual application.

To get richer telemetry data, use manual instrumentation to enrich your telemetry data from instrumentation libraries with instrumentation from your running application.

Last modified September 27, 2023: Refine Go: Libraries (#3317) (d84ae9c8)