Skip to content

Conversation

majanjua-amzn
Copy link

@majanjua-amzn majanjua-amzn commented Sep 23, 2025

Description

The problem: Currently, the AWS X-Ray propagator overrides the trace state when returning the context by providing the default trace.TraceState() instead of attempting to retrieve this information from the provided context.

The solution: Check for a valid trace state in the provided context and propagate it to the new context if it exists.

Type of change

Please delete options that are not relevant.

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

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

  • Unit tests

Does This PR Require a Core Repo Change?

  • No.

Checklist:

See contributing.md for styleguide, changelog guidelines, and more.

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

Copy link

linux-foundation-easycla bot commented Sep 23, 2025

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: majanjua-amzn / name: Mahad Janjua (dfb5e15)

@majanjua-amzn majanjua-amzn force-pushed the main branch 6 times, most recently from 35bf7b4 to 67c4eb1 Compare September 23, 2025 16:29
@majanjua-amzn majanjua-amzn marked this pull request as ready for review September 23, 2025 16:29
@majanjua-amzn majanjua-amzn requested a review from a team as a code owner September 23, 2025 16:29
@xrmx xrmx moved this to Ready for review in @xrmx's Python PR digest Sep 24, 2025
Comment on lines +147 to +150
try:
tracestate = trace.get_current_span(context=context).get_span_context().trace_state
except AttributeError:
tracestate = trace.TraceState()
Copy link
Contributor

Choose a reason for hiding this comment

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

Instead of letting this code trigger AttributeError, can you check if trace.get_current_span(context=context) and trace.get_current_span(context=context).get_span_context() and trace.get_current_span(context=context).get_span_context().trace_state are not none to set trace_state?

Comment on lines 120 to 121
if context is None:
context = Context()
Copy link
Contributor

Choose a reason for hiding this comment

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

        tracestate = trace.TraceState()
        if context is None:
            context = Context()
        else:
            # put your logic here to update `trace_state` if it exists in `context`

Suggestion if you want to avoid the possibility of extracting trace_state from a new Context() when "context is None".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Ready for review
Development

Successfully merging this pull request may close these issues.

2 participants