A collection of Go utilities for simplifying OpenTelemetry integration in Go applications.
This project offers a suite of tools designed to reduce the boilerplate code required to properly implement OpenTelemetry tracing and logging in Go applications. The utilities are designed with sensible defaults while allowing the flexibility to customize as needed.
The project consists of the following packages:
An opinionated helper library for easily setting up OpenTelemetry trace and log providers with batteries included. The package handles the common initialization patterns and provides a clean API for your applications. See full documentation in otelprovider/README.md
- Simple initialization of OpenTelemetry trace providers
- Structured logging with OpenTelemetry integration
- Automatic resource detection for environment information
- Support for multiple exporters (OTLP, Console)
- Environment-aware configuration
A wrapper for the popular zap logging library that integrates seamlessly with OpenTelemetry. This package enables correlation between logs and traces for better observability. See full documentation in otelzap/README.md
Install the packages you need:
# For just the OpenTelemetry provider utilities
go get github.com/spechtlabs/go-otel-utils/otelprovider
# For zap integration with OpenTelemetry
go get github.com/spechtlabs/go-otel-utils/otelzap
package main
import (
"context"
"log"
"github.com/spechtlabs/go-otel-utils/otelprovider"
)
func main() {
ctx := context.Background()
// Initialize trace provider
tp, err := otelprovider.NewTraceProvider(ctx, "my-service")
if err != nil {
log.Fatalf("Failed to initialize trace provider: %v", err)
}
defer tp.Shutdown(ctx)
// Initialize logger
logger, err := otelprovider.NewLogger("my-service", "development")
if err != nil {
log.Fatalf("Failed to initialize logger: %v", err)
}
// Your application code here
logger.Info("Application started successfully")
}
Explore the example/ directory for a complete working demonstration of these utilities in action.
The utilities support configuration through environment variables:
OTEL_EXPORTER_OTLP_ENDPOINT
: Endpoint for the OTLP exporterOTEL_SERVICE_NAME
: Default service name if not specifiedOTEL_ENVIRONMENT
: Environment (development, staging, production)LOG_LEVEL
: Logging level (debug, info, warn, error)
The go-otel-utils project follows these principles:
- Simplicity First: Provide straightforward APIs that hide complexity
- Sensible Defaults: Work well out-of-the-box with minimal configuration
- Production Ready: Built with real-world production use cases in mind
- Extensibility: Allow customization when the defaults don't fit
- Standards Compliance: Follow OpenTelemetry best practices and standards
Contributions are welcome! Please feel free to submit issues or pull requests.