mirror of
https://github.com/hanzokv/go.git
synced 2026-09-24 00:31:51 +00:00
Workspace-wide sync. luxfi/node already shipped on 1.26.4 in v1.30.6 (commit 121aca1fa9); nested module catch-up.
OpenTelemetry Metrics Example
This example demonstrates how to enable OpenTelemetry metrics for Redis operations using the extra/redisotel-native package.
Features
- ✅ OTLP exporter configuration
- ✅ Periodic metric export (every 10 seconds)
- ✅ Concurrent Redis operations
- ✅ Automatic metric collection for:
- Operation duration
- Connection metrics
- Error tracking
Prerequisites
- Go 1.24.0 or later
- Redis server running on
localhost:6379 - OTLP collector running on
localhost:4317(optional)
Running the Example
# Start Redis (if not already running)
redis-server
# Optional: Start OTLP collector
# See: https://opentelemetry.io/docs/collector/
# Run the example
go run main.go
What It Does
- Creates an OTLP exporter that sends metrics to a collector
- Sets up a meter provider with periodic export (every 10 seconds)
- Initializes Redis client with OTel instrumentation
- Executes concurrent Redis operations (SET commands)
- Waits for metrics to be exported
Metrics Collected
The example automatically collects:
- db.client.operation.duration - Operation latency histogram
- db.client.connection.create_time - Connection creation time
- db.client.connection.count - Active connection count
- db.client.errors - Error counter with error type classification
Configuration
To use with a production OTLP collector:
exporter, err := otlpmetricgrpc.New(ctx,
otlpmetricgrpc.WithEndpoint("your-collector:4317"),
otlpmetricgrpc.WithTLSCredentials(credentials.NewClientTLSFromCert(certPool, "")),
)