otel_grpc 0.2.0
otel_grpc: ^0.2.0 copied to clipboard
OpenTelemetry instrumentation for `package:grpc`. Client and server interceptors emitting rpc.* spans, propagating W3C trace context via gRPC metadata, with recursion suppression.
Changelog #
All notable changes to this project will be documented in this file.
The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.
0.2.0 - 2026-08-10 #
Added #
OTelGrpcClientInterceptor—ClientInterceptorsubclass that wraps every unary and streaming RPC in aCLIENT-kind span, injects W3C trace context into the call metadata, and maps gRPC status codes to OTel span status. Sets the registry-current RPC semconv attributes:rpc.system.name=grpc, fully-qualifiedrpc.method,rpc.response.status_code(canonical status name, e.g.OK/NOT_FOUND). OptionalserverAddress/serverPortconstructor parameters emitserver.address/server.port(interceptors can't see theClientChannel, so the values are caller-supplied — never fabricated).OTelGrpcServerInterceptor— class-basedServerInterceptor(grpc >= 4.1.0) forServer.create(serverInterceptors: ...). The span wraps the whole handler invocation and ends when the response stream completes or errors, so durations and status codes are real (an earlier draft used the function-typedef hook, which fires before the call and cannot observe completion). Extracts W3C trace context fromServiceCall.clientMetadataso server spans parent into the calling trace.grpcStatusCodeName— canonical gRPC status names for therpc.response.status_codevalues; unknown codes emit the numeric code as a string.runWithoutGrpcInstrumentation/runWithoutGrpcInstrumentationAsync— zone-scoped suppression helpers. The interceptors check a zone flag and skip span creation entirely, breaking the recursion hazard when an OTLP/gRPC export call would otherwise pass back through the interceptor.- 8 unit tests against a real in-process gRPC
Serveron an ephemeral port: client happy path, traceparent injection, GrpcError → Error status, suppression, parent-span inheritance; server real-duration span, GrpcError mapping, W3C extraction.
Changed #
- Semantic conventions updated to the current OTel registry:
registry-deprecated keys are no longer emitted —
rpc.system→rpc.system.name,rpc.service→ folded into a fully-qualifiedrpc.method, and the numericrpc.grpc.status_code→ the stringrpc.response.status_code. The localGrpcSemanticsenum is gone with them. - Dependency floors raised to
dartastic_opentelemetry ^1.1.0-beta.12anddartastic_opentelemetry_api ^1.0.0-rc.1. The previous floors declared compatibility with API versions that predate the semconv enums this package uses and could not actually resolve-and-compile. repositoryURL corrected to the canonicalDartasticorg casing so pub.dev repository verification succeeds.
Known limitations #
- Server-side
rpc.methodis unqualified:package:grpc'sServiceMethoddoesn't carry a back-reference to its parentService. The client emits the fully-qualified form.