otelgrpc: add WithSpanKind option#8506
Conversation
Add WithSpanKind option to allow overriding the default span kind for handlers. By default, NewServerHandler creates spans with SpanKindServer and NewClientHandler creates spans with SpanKindClient. This is useful when gRPC is used behind protocol translation layers (e.g., grpc-gateway, vanguard-go) where the outer HTTP handler already creates a SERVER span, and the inner gRPC handler should use SpanKindInternal to avoid duplicate service boundaries in traces. Fixes open-telemetry#8490
|
Please sign the CLA |
Co-authored-by: Damien Mathieu <42@dmathieu.com>
|
Should I squash and force push? |
|
No. We'll auto-squash when merging. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #8506 +/- ##
=====================================
Coverage 82.2% 82.2%
=====================================
Files 179 179
Lines 13692 13700 +8
=====================================
+ Hits 11257 11265 +8
Misses 2033 2033
Partials 402 402
🚀 New features to boost your workflow:
|
|
CLA is signed, changes are approved. @dmathieu blocked label is still there. |
|
We require for PRs to be open for at least 24h before they are merged. |
|
Sorry, although it has been merged, we might need to make some adjustments. I checked the semantic conventions for gRPC, and I think for Reference: https://opentelemetry.io/docs/specs/semconv/rpc/grpc/#client-span This means we must enforce the definition of the corresponding |
|
Did you see the reasoning in #8490? |
Sorry, I missed it. Currently, this PR seems reasonable. |
|
Had me worried for a second there. 😄 |
Summary
WithSpanKindoption to override the default span kind for handlersDetails
This adds a
WithSpanKindoption toNewServerHandlerandNewClientHandlerthat allows overriding the default span kind.By default:
NewServerHandlercreates spans withSpanKindServerNewClientHandlercreates spans withSpanKindClientUse Case
When gRPC is used behind HTTP-to-gRPC transcoding layers (e.g., grpc-gateway, vanguard-go), the outer HTTP handler already creates a
SERVERspan. The inner gRPC handler creating anotherSERVERspan results in duplicate service boundaries in trace visualizations.Using
WithSpanKind(trace.SpanKindInternal)allows marking these internal protocol translations correctly.Example
Fixes #8490