Getting started
Você está visualizando a versão em versão em inglês desta página porque ela ainda não foi traduzida. Possui interesse em ajudar? Veja como contribuir.
This page shows you how to build a Go application with compile-time instrumentation and see the telemetry it produces.
Prerequisites
- Go 1.25 or newer
gitandmake
Build the tool
The otelc tool is built from the project repository:
git clone https://github.com/open-telemetry/opentelemetry-go-compile-instrumentation.git
cd opentelemetry-go-compile-instrumentation
make build
This produces an otelc binary in the repository root. Add it to your PATH,
or note its location — the following steps assume otelc is on your PATH:
export PATH=$PATH:$(pwd)
Instrument your application
From your application’s module directory, prefix your usual go build command
with otelc:
otelc go build -o myapp .
The tool intercepts the build, applies the instrumentation rules that match your
application and its dependencies, and produces an instrumented binary.
Everything else about the build — flags, package arguments, output paths — works
exactly as it does with plain go build.
Run the application and export telemetry
Instrumented applications are configured through the standard OpenTelemetry environment variables. For example, to send telemetry to a local Collector over OTLP:
export OTEL_SERVICE_NAME=myapp
export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4317
./myapp
See Configuration for the full list of environment variables the instrumentation recognizes.
Try the demo
The repository ships demo applications and a complete observability stack (Collector, Jaeger, Prometheus, and Grafana) so you can see the produced telemetry end to end. The stack runs on Docker, so make sure Docker is available first. From the repository root, run:
cd demo/infrastructure/docker-compose
make start
See the demo directory for details on the demo applications and infrastructure.
Next steps
- Check which libraries are instrumented out of the box.
- Learn how to configure the tool and the telemetry it produces.
Feedback
Esta página foi útil?
Thank you. Your feedback is appreciated!
Please let us know how we can improve this page. Your feedback is appreciated!