How open-telemetry/opentelemetry-go-compile-instrumentation works
otelc is a Go compile-time OpenTelemetry instrumentation tool: a developer prefixes a Go build with otelc, which configures and transforms the build so instrumentation is injected without application-source edits. Its runtime product includes the transformation engine, shared runtime setup, and hooks for supported libraries and protocols. The README documents the user workflow and broad capabilities; source-index references support the internal links shown here. Several integration directories are represented as subsystems because their individual source was not sampled.
Main entry points: runtime/setup.go Runtime setup · context.go Hook context · setup/setup.go Build setup · trampoline.go Code transformer
Components 19
Build entry
- otelc CLI
tool/cmd/otelc/main.go
Instrumentation engine
- Build setup
tool/internal/setup/setup.go - Instrumentation rules
tool/internal/rule - Go AST parser
tool/internal/ast/parser.go - Code transformer
tool/internal/instrument/trampoline.go - Go build utilities
tool/util/go.go
Shared runtime
- Runtime setup
pkg/runtime/setup.go - Hook context
pkg/hook/context.go
Library instrumentation
- SQL database hooks
instrumentation/database/sql/client.go - Linode API hooks
instrumentation/github.com/linode/linodego/v2 - Redis hooks
instrumentation/github.com/redis/go-redis/v9/client_hook.go - MongoDB hooks
instrumentation/go.mongodb.org/mongo-driver/mongo/client_hook.go - Other library hooks
instrumentation - Kubernetes hooks
instrumentation/k8s.io/client-go
Protocol instrumentation
- gRPC client hooks
instrumentation/google.golang.org/grpc/client/client_hook.go - gRPC server hooks
instrumentation/google.golang.org/grpc/server/server_hook.go - HTTP client hooks
instrumentation/net/http/client/client_hook.go - HTTP server hooks
instrumentation/net/http/server
Other components
- Go developer
Connections 23
- Go developer → otelc CLI: runs before build
README.md - otelc CLI → Build setup: configures build
- Build setup → Code transformer: invokes transformation
tool/internal/setup/setup.go - Build setup → Instrumentation rules: uses rules
tool/internal/setup/setup.go - Build setup → Go build utilities: uses build utilities
tool/internal/setup/setup.go - Code transformer → Go AST parser: parses source
tool/internal/instrument/trampoline.go - Code transformer → Instrumentation rules: applies rules
tool/internal/instrument/trampoline.go - Code transformer → Go build utilities: uses utilities
tool/internal/instrument/trampoline.go - Runtime setup → otelc CLI: initializes instrumentation
- SQL database hooks → Hook context: uses hook context
instrumentation/database/sql/client.go - SQL database hooks → Runtime setup: checks runtime state
instrumentation/database/sql/client.go - Linode API hooks → Hook context: uses hook context
instrumentation/github.com/linode/linodego/v2/gen/main.go - Redis hooks → Hook context: uses hook context
instrumentation/github.com/redis/go-redis/v9/client_hook.go - Redis hooks → Runtime setup: checks runtime state
instrumentation/github.com/redis/go-redis/v9/client_hook.go - MongoDB hooks → Hook context: uses hook context
instrumentation/go.mongodb.org/mongo-driver/mongo/client_hook.go - MongoDB hooks → Runtime setup: checks runtime state
instrumentation/go.mongodb.org/mongo-driver/mongo/client_hook.go - gRPC client hooks → Hook context: uses hook context
instrumentation/google.golang.org/grpc/client/client_hook.go - gRPC client hooks → Runtime setup: checks runtime state
instrumentation/google.golang.org/grpc/client/client_hook.go - gRPC server hooks → Hook context: uses hook context
instrumentation/google.golang.org/grpc/server/server_hook.go - gRPC server hooks → Runtime setup: checks runtime state
instrumentation/google.golang.org/grpc/server/server_hook.go - HTTP client hooks → Hook context: uses hook context
instrumentation/net/http/client/client_hook.go - HTTP client hooks → Runtime setup: checks runtime state
instrumentation/net/http/client/client_hook.go - Kubernetes hooks → Runtime setup: checks runtime state
instrumentation/k8s.io/client-go/k8s_otel_handler.go