fix(shim): Map OpenTracing span.kind tag to OTel SpanKind#5080
fix(shim): Map OpenTracing span.kind tag to OTel SpanKind#5080Nik-Reddy wants to merge 1 commit intoopen-telemetry:mainfrom
Conversation
MikeGoldsmith
left a comment
There was a problem hiding this comment.
Looks good - thanks @Nik-Reddy. I've left a couple of suggestions and queries.
Also, please add a changelog entry.
d8e751e to
0532d05
Compare
81b3ada to
0a528ec
Compare
|
Hi @MikeGoldsmith, added the internal kind as suggested, updated the test, and added a CHANGELOG entry. Added \internal\ SpanKind mapping, corresponding test, and CHANGELOG entry. |
MikeGoldsmith
left a comment
There was a problem hiding this comment.
Thanks for the update @Nik-Reddy. I've left one more suggestion around mutating the tags dic.
| mapped_kind = util.opentracing_kind_to_otel_kind(tags["span.kind"]) | ||
| if mapped_kind is not None: | ||
| kind = mapped_kind | ||
| del tags["span.kind"] |
There was a problem hiding this comment.
del tags["span.kind"] mutates the caller's dict in place. Could you make a copy first to avoid the side effect?
| del tags["span.kind"] | |
| tags = dict(tags) | |
| del tags["span.kind"] |
0a528ec to
b1cdff0
Compare
Extract span.kind from OpenTracing tags, map to the corresponding OpenTelemetry SpanKind, and remove it from attributes to avoid duplication. Unrecognized kinds default to SpanKind.INTERNAL. Fixes open-telemetry#2549
b1cdff0 to
e50a246
Compare
lmolkova
left a comment
There was a problem hiding this comment.
OpenTracing support is deprecated since March 2026 - https://github.com/open-telemetry/opentelemetry-specification/blob/49ef085d79fd4b9a0ff88135bb7ee6eed74fe8f3/specification/compatibility/opentracing.md
This PR attempts to fix issue from 2022 with no upvotes. It does not seem like fixing this issue would help anyone. I'll leave a comment suggesting to close the issue as not planned.
c29c0be to
e50a246
Compare
|
Fair point, makes sense to close this given the deprecation. Thanks for the context. |
Description
The OpenTracing compatibility shim ignores the
span.kindtag when creating spans viaTracerShim.start_span(). All spans default toSpanKind.INTERNALregardless of the OpenTracingspan.kindvalue (client,server,producer,consumer). This breaks interoperability for users migrating from OpenTracing to OpenTelemetry, as span kind is critical for trace visualization and backend processing.This PR extracts
span.kindfrom the tags dict before span creation, maps it to the correspondingSpanKindenum value (includinginternal), passes it as thekind=parameter, and removesspan.kindfrom the tags so it does not appear as a duplicate attribute — it is a semantic control tag, not a regular user attribute.Fixes #2549
Type of change
How Has This Been Tested?
All existing shim tests plus new test cases pass:
test_span_kind_from_tags— 7 sub-tests covering all four OpenTracing kinds + unknown + absent + Nonetest_span_kind_tag_removed_from_attributes— verifiesspan.kindis removed from attributes while other tags are preservedtest_opentracing_kind_to_otel_kind— 7 sub-tests for theutil.pyhelper (all five valid kinds + unknown + empty)61 tests passed, 0 failures.
Does This PR Require a Contrib Repo Change?
Checklist: