Table of contents
Part of nurago, a collection of independent Go packages for backend services.
import "github.com/tecnickcom/nurago/pkg/metrics/opentel/opentelgrpc"
OpenTelemetry tracing and metrics for grpcserver and grpcclient, built on the otelgrpc stats handlers.
in, err := opentelgrpc.New()
grpcserver.WithInstrumenter(in)
grpcclient.WithInstrumenter(in)
No further wiring after opentel
With no options, the global tracer, meter and propagator providers are used, and opentel installs those in New. A service that already exports HTTP telemetry through opentel gets gRPC spans and metrics on the same exporters, with the same resource attributes, by adding one option to each side.
WithTracerProvider, WithMeterProvider and WithPropagators set explicit providers, which is what a test uses to capture spans without touching global state.
What it produces
- A span for every RPC, on both sides, with trace context propagated through the request metadata. A trace that starts at an HTTP handler continues across the gRPC call and into the downstream service.
- The
rpc.server.*andrpc.client.*metrics of the OpenTelemetry semantic conventions.
It uses stats handlers rather than interceptors, as otelgrpc recommends: they see transport events, such as message sizes and the end of a stream, that interceptors do not.
Health and reflection are filtered out
By default grpc.health.v1.Health and grpc.reflection.* RPCs produce neither spans nor metrics. A probe every few seconds per instance would otherwise fill the trace backend with traces nobody reads, and on a sampled backend crowd out the ones that matter. WithFilter adds filters; WithoutDefaultFilter removes the default one.
Dependencies
Reaches otelgrpc, the OpenTelemetry API modules and google.golang.org/grpc: 15 external modules in total. The SDK and exporters come from opentel.
Links
- Reference documentation
- Source code
- The providers and exporters: opentel
- The Prometheus alternative: prometheusgrpc
- The guide: /docs/grpc-services/
- All nurago packages