Skip to content

Add OpenTelemetry OTLP exporter with full SDK support#218

Open
etiennep wants to merge 1 commit intomainfrom
add-opentelemetry-otlp-support
Open

Add OpenTelemetry OTLP exporter with full SDK support#218
etiennep wants to merge 1 commit intomainfrom
add-opentelemetry-otlp-support

Conversation

@etiennep
Copy link

@etiennep etiennep commented Feb 6, 2026

Summary

Adds production-ready OpenTelemetry Protocol (OTLP) exporter using the official OpenTelemetry SDK with comprehensive support for both gRPC and HTTP/Protobuf transports.

Features

Dual Transport Support: gRPC and HTTP/Protobuf protocols
Environment Variables: Full OTEL_* environment variable support
Resource Detection: AWS (EC2, ECS, EKS, Lambda), GCP, Azure, K8s, host, process
All Metric Types: Counter, Gauge, Histogram with proper semantics
Tag Conversion: Automatic stats tags → OpenTelemetry attributes
Production Ready: Thread-safe, tested, documented

Usage

// Simple - uses environment variables
handler, err := otlp.NewSDKHandlerFromEnv(ctx)
stats.Register(handler)

// Or explicit configuration
handler, err := otlp.NewSDKHandler(ctx, otlp.SDKConfig{
    Protocol: otlp.ProtocolGRPC,
    Endpoint: "localhost:4317",
})

Implementation Highlights

  • Gauge Semantics: Uses UpDownCounter with delta calculation to maintain absolute value semantics (workaround until stable OTel SDK adds Gauge)
  • Context Handling: Background context for metric recording prevents context cancellation issues
  • Performance: Lock-free reads for instrument lookup, efficient caching
  • Resource Detection: Automatic cloud provider metadata detection

Documentation

Testing

  • ✅ Unit tests for all metric types
  • ✅ Gauge behavior verification
  • ✅ HTTP and gRPC protocol tests
  • ✅ Value type conversion tests
  • ✅ Performance benchmarks

Changes

  • Added otlp/sdk_handler.go - Main OpenTelemetry SDK integration
  • Added otlp/sdk_handler_test.go - Comprehensive tests
  • Added otlp/example_test.go - Usage examples
  • Added otlp/README.md - Complete documentation
  • Added otlp/IMPLEMENTATION_NOTES.md - Design decisions
  • Updated README.md - Added OpenTelemetry backend overview
  • Updated HISTORY.md - Added v5.9.0 release notes
  • Updated version/version.go - Bumped to 5.9.0
  • Updated otlp/go.mod - Added OpenTelemetry SDK dependencies

Backward Compatibility

Fully backward compatible - This is a new feature addition that doesn't change existing APIs. The legacy otlp.Handler remains available for existing users.

🤖 Generated with Claude Code

@etiennep etiennep force-pushed the add-opentelemetry-otlp-support branch from bad79e6 to e6d05d8 Compare February 6, 2026 10:26
sccoache
sccoache previously approved these changes Feb 6, 2026
@etiennep etiennep force-pushed the add-opentelemetry-otlp-support branch 2 times, most recently from 724f5f7 to a82c5e2 Compare February 6, 2026 17:01
Implement production-ready OpenTelemetry Protocol (OTLP) exporter using
the official OpenTelemetry SDK with support for both gRPC and HTTP
transports.

Features:
- gRPC and HTTP/Protobuf protocol support
- Full OTEL_* environment variable integration
- Automatic resource detection (AWS, GCP, Azure, K8s)
- Counter, Gauge, and Histogram metric types
- Tag to attribute conversion
- Thread-safe instrument caching
- Proper gauge semantics via delta calculation

Implementation:
- Uses UpDownCounter for gauges with delta tracking to maintain
  absolute value semantics (workaround until stable SDK adds Gauge)
- Background context for recording to avoid cancellation issues
- Lock-free reads for instrument lookup in hot path
- Comprehensive tests and benchmarks

Documentation:
- Complete README with configuration examples
- Cloud resource detector usage guides
- Implementation notes explaining design decisions
- Example code for common use cases

Bumps version to 5.9.0

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@etiennep etiennep force-pushed the add-opentelemetry-otlp-support branch from a82c5e2 to 82249fe Compare February 6, 2026 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants