-
Notifications
You must be signed in to change notification settings - Fork 222
feat(client): propagate trace attributes onto all child spans on update #1415
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Contributor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
10 files reviewed, 1 comment
hassiebp
commented
Oct 21, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Important
Introduces
propagate_attributes()to propagate trace-level attributes to child spans, deprecates older methods, and adds comprehensive tests, with a critical bug identified in baggage handling.propagate_attributes()context manager inpropagation.pyto propagate trace-level attributes to child spans.update_current_trace()andupdate_trace()methods.LangfuseSpanProcessor.on_start()inspan_processor.pyto apply propagated attributes to new spans._get_span_key_from_baggage_key()inpropagation.pyaffecting baggage handling.test_propagate_attributes.pywith 50+ tests for propagation scenarios, including threading, async, and cross-tracer contexts.client.pyandconstants.py.opentelemetry-instrumentation-threadingtopyproject.toml.This description was created by
for 854026a. You can customize this summary. It will automatically update as commits are pushed.
Disclaimer: Experimental PR review
Greptile Overview
Updated On: 2025-10-21 15:07:10 UTC
Summary
Implements attribute propagation for trace-level attributes (user_id, session_id, metadata) to automatically propagate to all child spans within a context.
Key Changes:
propagate_attributes()context manager that sets attributes on the current span AND propagates them to all child spans via OpenTelemetry contextLangfuseSpanProcessor.on_start()to read propagated attributes from context and apply them to new spansupdate_current_trace()andupdate_trace()methods with comprehensive migration guidanceas_baggage=True)Motivation:
The old
update_trace()methods only set attributes on a single span, causing gaps in Langfuse aggregation queries (e.g., filtering byuser_idor calculating costs persession_id) because child spans didn't inherit the attributes.Confidence Score: 3/5
_get_span_key_from_baggage_key()(line 322) that uses substring matching instead of exact equality checks, which will cause incorrect attribute mapping when metadata keys contain "user_id" or "session_id". The bug only affects the optional baggage feature (whenas_baggage=True) which isn't tested. The main propagation path (via OTel context) works correctly._get_span_key_from_baggage_key()functionImportant Files Changed
File Analysis
_get_span_key_from_baggage_key()at line 322 with substring matching logicon_start()to propagate attributes to child spans - clean implementation, inherits baggage bug from propagation.pyas_baggage=TruefunctionalitySequence Diagram
sequenceDiagram participant User participant propagate_attributes participant OTel Context participant Span Processor participant Child Span User->>propagate_attributes: Call with user_id, session_id, metadata propagate_attributes->>propagate_attributes: Validate string values (≤200 chars) propagate_attributes->>OTel Context: Set context values (langfuse.propagated.*) propagate_attributes->>Current Span: Set attributes directly alt as_baggage=True propagate_attributes->>OTel Context: Set baggage (langfuse_user_id, etc) end propagate_attributes->>OTel Context: Attach context User->>Child Span: Create child span Child Span->>Span Processor: on_start(span, parent_context) Span Processor->>OTel Context: _get_propagated_attributes_from_context() OTel Context-->>Span Processor: Return propagated attributes Span Processor->>Child Span: span.set_attributes(propagated_attributes) Child Span-->>User: Span with inherited attributes User->>propagate_attributes: Exit context propagate_attributes->>OTel Context: Detach context