trace
Trace Package
The trace package provides an easy-to-use utility for adding distributed tracing to Go applications using OpenTelemetry. With support for multiple trace exporters, function-level tracing, and integration with web frameworks like Gin, this package simplifies instrumentation and performance monitoring across services.
Key Features:
Tracer Provider Initialization: Easily initialize and configure OpenTelemetry's Tracer Provider with support for multiple exporters, including:
gRPC Exporter: Export traces to remote tracing backends.Stdout Exporter: Print traces to the console for local development and debugging.Function-Level Tracing (TraceFunc): Automatically trace the execution of any Go function, including capturing function start/end times, execution status, and errors.
Installation
go get github.com/kittipat1413/go-common/framework/traceDocumentation
For detailed API documentation, examples, and usage patterns, visit the Go Package Documentation.
Usage
1. Initialize Tracer Provider
To initialize the Tracer Provider, call InitTracerProvider with the service name and desired exporter:
You can also set the
OTEL_SERVICE_NAMEenvironment variable to override the service name dynamically. Additionally, you can set theOTEL_RESOURCE_ATTRIBUTESenvironment variable to specify additional resource attributes.
2. Function-Level Tracing (TraceFunc)
TraceFunc)Wrap any function in TraceFunc to automatically trace its execution:
Example
You can find a complete working example in the repository under framework/trace/example.
Last updated