Skip to content

Feature: Include trace flags in spans exported by the OTLPSpanExporter - #5667

Open
gavalur-sfdc wants to merge 2 commits into
open-telemetry:mainfrom
gavalur-sfdc:issue_4666-spanexporter_include_traceflags
Open

gavalur-sfdc wants to merge 2 commits into
open-telemetry:mainfrom
gavalur-sfdc:issue_4666-spanexporter_include_traceflags

Conversation

@gavalur-sfdc

Copy link
Copy Markdown

Description

Update OTLP JSON and protobuf span encoders to include a span context’s trace flags, such as the sampled flag, in exported span flags.

Fixes # (4666)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Test A

Does This PR Require a Contrib Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

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

@gavalur-sfdc
gavalur-sfdc requested a review from a team as a code owner September 16, 2026 20:58
@linux-foundation-easycla

linux-foundation-easycla Bot commented Sep 16, 2026

Copy link
Copy Markdown

CLA Not Signed

def test_span_flags(self):
has_remote = int(JSONSpanFlags.SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK)
is_remote = int(JSONSpanFlags.SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK)
sampled = int(TraceFlags.SAMPLED)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

For completeness, can we add test cases that include the random trace id flag.

@herin049

Copy link
Copy Markdown
Contributor

Please add a changelog entry too.



def _span_flags(parent_span_context: SpanContext | None) -> int:
def _span_flags(span_context: SpanContext | None) -> int:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Probably ideal to not rename from parent_span_context to span_context since the context here represents the parent span.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not just the rename, but _span_flags is called with the parent span context down in _encode_span, not the current span, so this implementation would actually be buggy.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

The same comment by @lzchen also applies to the protobuf _span_flags function as well.



def _span_flags(parent_span_context: SpanContext | None) -> int:
def _span_flags(span_context: SpanContext | None) -> int:

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Probably ideal to not rename from parent_span_context to span_context since the context here represents the parent span.

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Sep 17, 2026

Copy link
Copy Markdown

Pull request dashboard status

Waiting on the author · refreshed 2026-09-18 01:51 UTC

Two things need attention:

  • Required checks are failing — investigate the failures.
  • 4 review items — respond to each (e.g. link a commit, explain why not, ask a follow-up):
    • Inline threads: 1, 2, 3
    • Top-level threads: 4
Status above doesn't look right?
  • Just replied or pushed? Anything around or after the refresh time above may not be picked up yet — give it a few minutes.
  • Should this be with reviewers? Comment /dashboard route:reviewers to route it to them.
  • Anything wrong — including the routing? Report it with what you expected; it helps us improve the dashboard.

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

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

4 participants