Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,4 @@ _testmain.go
/dogstatsd

/datadog/testdata/fuzz
.claude/settings.local.json
55 changes: 55 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,60 @@
# History

### v5.9.0 (February 6, 2026)

Add full OpenTelemetry OTLP exporter support with official SDK integration.

**New Feature: OpenTelemetry OTLP Exporter**

The `otlp` package now includes a production-ready `SDKHandler` that uses the
official OpenTelemetry SDK with comprehensive support for modern observability
requirements:

- **Dual Transport Support**: Both gRPC and HTTP/Protobuf protocols
- **Environment Variables**: Full support for all standard `OTEL_*` environment
variables including `OTEL_EXPORTER_OTLP_ENDPOINT`, `OTEL_EXPORTER_OTLP_PROTOCOL`,
`OTEL_RESOURCE_ATTRIBUTES`, etc.
- **Automatic Resource Detection**: Built-in support for AWS (EC2, ECS, EKS, Lambda),
GCP (Compute Engine), Azure (VM), Kubernetes, host, and process metadata
- **All Metric Types**: Counter, Gauge, and Histogram with proper semantics
- **Tag Preservation**: Automatic conversion of stats tags to OpenTelemetry attributes
- **Production Ready**: Thread-safe instrument caching, proper context handling,
and comprehensive error handling

**Usage Example:**

```go
import (
"context"
"github.com/segmentio/stats/v5"
"github.com/segmentio/stats/v5/otlp"
)

// Simple usage with environment variables
handler, err := otlp.NewSDKHandlerFromEnv(ctx)
if err != nil {
log.Fatal(err)
}
defer handler.Shutdown(ctx)
stats.Register(handler)

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

**Implementation Details:**

- Gauges use `UpDownCounter` with delta calculation to maintain absolute value
semantics (workaround until stable OTel SDK adds Gauge instrument)
- Background context for metric recording to prevent context cancellation issues
- Lock-free reads for instrument lookup in the hot path
- Comprehensive documentation including cloud resource detector examples

See the [otlp package documentation](./otlp/README.md) for complete details and examples.

### v5.8.0 (December 15, 2025)

When reporting go/stats versions, ensure that any user provided tags are
Expand Down
82 changes: 82 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,88 @@ func main() {
}
```

## Supported Backends

The stats package supports multiple metric backends out of the box:

### OpenTelemetry (OTLP)

The [github.com/segmentio/stats/v5/otlp](https://pkg.go.dev/github.com/segmentio/stats/v5/otlp) package provides full OpenTelemetry Protocol (OTLP) support using the official OpenTelemetry SDK.

**Features:**

- gRPC and HTTP/Protobuf transports
- Full support for OTEL_* environment variables
- Automatic resource detection (cloud, Kubernetes, host, process)
- Production-ready with official OTel SDK exporters

```go
import (
"context"
"github.com/segmentio/stats/v5"
"github.com/segmentio/stats/v5/otlp"
)

func main() {
ctx := context.Background()

// Using gRPC (recommended)
handler, err := otlp.NewSDKHandler(ctx, otlp.SDKConfig{
Protocol: otlp.ProtocolGRPC,
Endpoint: "localhost:4317",
})
if err != nil {
panic(err)
}
defer handler.Shutdown(ctx)

stats.Register(handler)
defer stats.Flush()

// Or use environment variables (simplest)
// export OTEL_EXPORTER_OTLP_ENDPOINT=http://localhost:4318
// export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
handler, err = otlp.NewSDKHandlerFromEnv(ctx)
}
```

See the [otlp package documentation](./otlp/README.md) for complete details.

### Datadog

The [github.com/segmentio/stats/v5/datadog](https://godoc.org/github.com/segmentio/stats/v5/datadog) package provides support for sending metrics to Datadog via DogStatsD protocol over UDP or Unix Domain Sockets.

```go
import "github.com/segmentio/stats/v5/datadog"

stats.Register(datadog.NewClient("localhost:8125"))
```

### Prometheus

The [github.com/segmentio/stats/v5/prometheus](https://godoc.org/github.com/segmentio/stats/v5/prometheus) package exposes an HTTP handler that serves metrics in Prometheus format.

```go
import (
"net/http"
"github.com/segmentio/stats/v5/prometheus"
)

handler := prometheus.NewHandler()
stats.Register(handler)
http.Handle("/metrics", handler)
```

### InfluxDB

The [github.com/segmentio/stats/v5/influxdb](https://godoc.org/github.com/segmentio/stats/v5/influxdb) package sends metrics to InfluxDB using the line protocol over HTTP.

```go
import "github.com/segmentio/stats/v5/influxdb"

stats.Register(influxdb.NewClient("http://localhost:8086"))
```

### Metrics

- [Gauges](https://godoc.org/github.com/segmentio/stats#Gauge)
Expand Down
Loading
Loading