OpenTelemetry-Go-Compile-Instrumentation provides compile time OpenTelemetry instrumentation for Golang.
- Go 1.23.0 or later
- Git
-
Clone the repository:
git clone https://github.com/open-telemetry/opentelemetry-go-compile-instrumentation.git cd opentelemetry-go-compile-instrumentation
-
Build the instrumentation tool:
make build
-
Run the demo with instrumentation:
make demo
This will:
- Build the instrumentation tool (
otel
binary) - Run the demo with compile-time instrumentation
- Execute the instrumented binary
- Build the instrumentation tool (
The instrumentation tool injects OpenTelemetry code at compile time using Go's -toolexec
flag. The process works as follows:
- Setup Phase: Creates
.otel-build
directory and initializes logging - Go Build Phase: Intercepts the
go build
command and adds-toolexec=./otel
flag - Toolexec Phase: The Go toolchain invokes the tool for each compilation step, allowing code injection. This phase is not visible to the user.
The tool provides detailed logging to help debug instrumentation issues:
- Logs are written to
.otel-build/debug.log
for setup and go actions - Toolexec action logs to stdout for immediate feedback
- All logs include structured information about the build process
To see the result of instrumentation, navigate to the WORK directory that appears in the build output:
# Example WORK directory
cd /var/folders/x9/fddsvlt5363c0plvvw8_2mr80000gn/T/go-build2020695287
# Locate the main package under the b001 subdirectory
ls -l b001
# Inspect the modified files
cat modified.go
See the contributing documentation.
OpenTelemetry Go Compile Instrumentation project is licensed under the terms of the [Apache Software License version 2.0]. See the license file for more details.