-
Notifications
You must be signed in to change notification settings - Fork 30
Add OpenTelemetry OTLP exporter with full SDK support #218
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,3 +31,4 @@ _testmain.go | |
| /dogstatsd | ||
|
|
||
| /datadog/testdata/fuzz | ||
| .claude/settings.local.json | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -121,6 +121,97 @@ 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). Note the field is EndpointURL, not Endpoint, | ||
| // and the value must include the scheme. | ||
| handler, err := otlp.NewSDKHandler(ctx, otlp.SDKConfig{ | ||
| Protocol: otlp.ProtocolGRPC, | ||
| EndpointURL: "http://localhost:4317", | ||
| }) | ||
| if err != nil { | ||
| panic(err) | ||
| } | ||
| defer handler.Shutdown(ctx) | ||
|
|
||
| stats.Register(handler) | ||
| defer stats.Flush() | ||
|
|
||
| // Or configure everything from environment variables (simplest). Note this | ||
| // example changes two things relative to the one above: it moves the | ||
| // configuration from in-code to env vars, AND it switches the transport | ||
| // from gRPC to HTTP/protobuf. | ||
| // 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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is dumb but for people who have never used Prometheus before, the pull model vs. push can be counterintuitive, could we just add a sentence explaining that's how this works? "Note that with Prometheus, the metric server will poll your client for changes - metrics are not pushed from a client to the server" |
||
|
|
||
| Note that with Prometheus the metric server polls your client for changes — | ||
| metrics are pulled by the server, not pushed from the client. This is the | ||
| opposite of most other backends here (Datadog, InfluxDB, OTLP), where the | ||
| client pushes metrics to the server. | ||
|
|
||
| ```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) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This example switches from GRPC to HTTP in addition to switching from env vars to in memory - that's fine but let's be explicit this is making two changes (env var AND protocol) instead of just one