Skip to content

fix(shim): Map OpenTracing span.kind tag to OTel SpanKind#5080

Open
Nik-Reddy wants to merge 1 commit intoopen-telemetry:mainfrom
Nik-Reddy:fix/opentracing-shim-span-kind-2549
Open

fix(shim): Map OpenTracing span.kind tag to OTel SpanKind#5080
Nik-Reddy wants to merge 1 commit intoopen-telemetry:mainfrom
Nik-Reddy:fix/opentracing-shim-span-kind-2549

Conversation

@Nik-Reddy
Copy link
Copy Markdown

@Nik-Reddy Nik-Reddy commented Apr 12, 2026

Description

The OpenTracing compatibility shim ignores the span.kind tag when creating spans via TracerShim.start_span(). All spans default to SpanKind.INTERNAL regardless of the OpenTracing span.kind value (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.kind from the tags dict before span creation, maps it to the corresponding SpanKind enum value (including internal), passes it as the kind= parameter, and removes span.kind from the tags so it does not appear as a duplicate attribute — it is a semantic control tag, not a regular user attribute.

Note: A previous attempt in #4953 was auto-closed by the stale bot (no activity for 28 days). This PR differs in two key ways:

  1. It removes span.kind from span attributes after extraction, preventing duplication (the previous PR preserved it as an attribute).
  2. The mapping logic is separated into a testable helper function in util.py with dedicated unit tests.

Fixes #2549

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

All existing shim tests plus new test cases pass:

pytest shim/opentelemetry-opentracing-shim/tests/ -v
  • test_span_kind_from_tags — 7 sub-tests covering all four OpenTracing kinds + unknown + absent + None
  • test_span_kind_tag_removed_from_attributes — verifies span.kind is removed from attributes while other tags are preserved
  • test_opentracing_kind_to_otel_kind — 7 sub-tests for the util.py helper (all five valid kinds + unknown + empty)

61 tests passed, 0 failures.

Does This PR Require a Contrib Repo Change?

  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Copy link
Copy Markdown
Member

@MikeGoldsmith MikeGoldsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good - thanks @Nik-Reddy. I've left a couple of suggestions and queries.

Also, please add a changelog entry.

@github-project-automation github-project-automation bot moved this to Reviewed PRs that need fixes in Python PR digest Apr 13, 2026
@Nik-Reddy Nik-Reddy force-pushed the fix/opentracing-shim-span-kind-2549 branch from d8e751e to 0532d05 Compare April 14, 2026 17:56
@Nik-Reddy Nik-Reddy requested a review from MikeGoldsmith April 14, 2026 21:28
@Nik-Reddy Nik-Reddy force-pushed the fix/opentracing-shim-span-kind-2549 branch from 0532d05 to 81b3ada Compare April 14, 2026 21:35
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
@Nik-Reddy Nik-Reddy force-pushed the fix/opentracing-shim-span-kind-2549 branch from 81b3ada to 0a528ec Compare April 14, 2026 21:38
@Nik-Reddy
Copy link
Copy Markdown
Author

Nik-Reddy commented Apr 14, 2026

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.

Copy link
Copy Markdown
Member

@MikeGoldsmith MikeGoldsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"]
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

del tags["span.kind"] mutates the caller's dict in place. Could you make a copy first to avoid the side effect?

Suggested change
del tags["span.kind"]
tags = dict(tags)
del tags["span.kind"]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Reviewed PRs that need fixes

Development

Successfully merging this pull request may close these issues.

In Opentracing Shim, set the Kind attribute

2 participants