Automatically adds OpenTelemetry trace spans to Go functions by modifying AST, eliminating manual instrumentation.
go-instrument is a Go tool that automatically injects OpenTelemetry trace spans into functions by modifying the code's Abstract Syntax Tree. It solves the problem of manually adding repetitive tracing code to every function, which is time-consuming and error-prone. The tool specifically targets functions with `context.Context` parameters, inserting span creation, error recording, and cleanup logic.
Go developers and teams implementing distributed tracing and observability in their applications, particularly those using OpenTelemetry and seeking to automate instrumentation.
Developers choose go-instrument because it eliminates the manual overhead of adding tracing code, provides a dependency-light approach using Go's standard AST library, and integrates seamlessly with OpenTelemetry for consistent observability.
⚡️ Automatically add Trace Spans to Go functions
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Inserts OpenTelemetry trace spans, error recording, and cleanup logic into functions with context.Context, eliminating repetitive manual coding as shown in the example where it adds otel.Trace calls.
Uses Go's built-in AST library for code transformation without external dependencies, ensuring reliability and compatibility with the Go ecosystem, as highlighted in the README.
Automatically records errors in spans and sets span status to error, enhancing observability for debugging by adding defer blocks that catch return errors, as demonstrated in the instrumented code snippet.
Adds only essential tracing logic to keep instrumented code clean, aligning with the project's philosophy of practicality and reducing clutter compared to manual instrumentation.
The added defer statements and function calls can prevent Go compiler inlining, potentially degrading performance in hot paths, as explicitly documented in the Performance section with before-and-after examples.
Only instruments functions that accept context.Context arguments, requiring manual adjustments for other functions or missing traces in parts of the codebase without context propagation.
Does not support per-function exclusion commands (e.g., via comments), making it harder to skip specific functions without resorting to file-level exclusion or custom Instrumenter implementations, as noted in the ADR section.