Skip to content

fix: distributed propagation#86

Merged
vabruzzo merged 1 commit into
mainfrom
bugfix/otel-distributed-trace-fix
Jun 20, 2025
Merged

fix: distributed propagation#86
vabruzzo merged 1 commit into
mainfrom
bugfix/otel-distributed-trace-fix

Conversation

@vabruzzo
Copy link
Copy Markdown
Contributor

@vabruzzo vabruzzo commented Jun 19, 2025

Bugfix for distributed propagation

Key Changes:

  • Uses w3c_propagator for distributed trace run continuation

Generated Summary:

  • Introduced handling for cases when the global propagator is a NoExtract instance.
  • Added a fallback mechanism to use the W3C propagator directly with TraceContextTextMapPropagator.
  • Modified context attachment logic to ensure it only occurs if the trace_id from the span context is valid.
  • Implemented a clearer fallback behavior by creating a new span if the provided context is invalid.
  • These changes enhance the robustness of tracing context propagation, ensuring that traces can continue under more conditions.

This summary was generated with ❤️ by rigging

@vabruzzo vabruzzo changed the title fix distributed propagation fix: distributed propagation Jun 19, 2025
@vabruzzo
Copy link
Copy Markdown
Contributor Author

Question for @monoxgas - We utilize the W3C propagator to fix this issue. Should we make this the default global propagator? My inclination is yes, and based on research it seems like that would work fine, but I'm not sure if you've run into anything regarding this issue for non distributed runs?

Comment thread dreadnode/tracing/span.py
# a trace, so we'll bypass it and use the W3C propagator directly.
global_propagator = propagate.get_global_textmap()
if "NoExtract" in type(global_propagator).__name__:
w3c_propagator = TraceContextTextMapPropagator()
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

i think we can just always use this globally rather than switching it out here

Copy link
Copy Markdown
Contributor

@monoxgas monoxgas left a comment

Choose a reason for hiding this comment

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

Like these changes, if I'm understanding correctly this is all a consequence of:

1 - When distributed=False on logfire, it overrides the global textmap provider to a NoExtract variant: https://github.com/pydantic/logfire/blob/e0d3fdff5ce2f2490f62529d47dd12dc58be51ff/logfire/_internal/config.py#L1126C31-L1126C49
2 - This doesn't affect the injection, so we capture context properly, but when we go to use it on the far side it doesn't actually pull out the context we need.

I like these changes, inclined to keep our override as a check for NoExtract. It's similar to how logfire does it on their end: https://github.com/pydantic/logfire/blob/e0d3fdff5ce2f2490f62529d47dd12dc58be51ff/logfire/propagate.py#L68

As an extension at some point, I think we should expose the distributed setting to the logfire.configure call in our settings object and set it to True by default.

@vabruzzo
Copy link
Copy Markdown
Contributor Author

yep that my understanding is aligned here. Thanks

@vabruzzo vabruzzo merged commit 8a0a64e into main Jun 20, 2025
9 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants