feat(client): allow propagating trace name #1478
Merged
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
Add support for propagating
trace_nameinpropagate_attributes()with validation and comprehensive tests.trace_nametopropagate_attributes()inpropagation.pyto propagate trace names to all child spans.trace_namemust be a US-ASCII string, ≤200 characters. Non-string or overly long values are dropped with a warning.as_baggage=True.TestPropagateAttributesTraceNameintest_propagate_attributes.pyto verifytrace_namepropagation to child and grandchild spans.trace_namewith other attributes likeuser_id,session_id,version, andmetadata.trace_namevalues.This description was created by
for 439b33d. You can customize this summary. It will automatically update as commits are pushed.
Disclaimer: Experimental PR review
Greptile Summary
Added
trace_nameparameter to thepropagate_attributes()context manager, enabling users to set a consistent trace name for all spans created within a context.Key Changes:
trace_nametoPropagatedKeysliteral type andpropagated_keyslisttrace_nameparameter topropagate_attributes()and_propagate_attributes()functions with proper documentationtrace_nametoLangfuseOtelSpanAttributes.TRACE_NAMEin_get_propagated_span_key()user_id,session_id,version,metadata), validation edge cases, nested contexts, baggage propagationImplementation Quality:
user_id,session_id,version,tags)Confidence Score: 5/5
Important Files Changed
trace_nameparameter to propagation system following existing patterns foruser_id,session_id,version, andtags. Includes validation, documentation, and proper integration with OpenTelemetry context.trace_namepropagation covering all edge cases: child/grandchild propagation, combination with other attributes, validation (200 char limit, non-string), nested contexts, and baggage propagation.Sequence Diagram
sequenceDiagram participant User participant PropagateAttrs as propagate_attributes participant Context as OpenTelemetry Context participant Validation as _validate_propagated_value participant CurrentSpan as Current Span participant ChildSpan as Child Spans User->>PropagateAttrs: propagate_attributes(trace_name="my-trace") PropagateAttrs->>Context: get_current() PropagateAttrs->>CurrentSpan: get_current_span() PropagateAttrs->>Validation: validate trace_name alt valid (≤200 chars, string) Validation-->>PropagateAttrs: validated value PropagateAttrs->>Context: set_value("langfuse.propagated.trace_name") PropagateAttrs->>CurrentSpan: set_attribute("langfuse.trace.name") PropagateAttrs->>Context: attach(context) loop for each child span User->>ChildSpan: start_span() ChildSpan->>Context: get_propagated_attributes() Context-->>ChildSpan: trace_name="my-trace" ChildSpan->>ChildSpan: set_attribute("langfuse.trace.name") end PropagateAttrs->>Context: detach(token) else invalid (>200 chars or non-string) Validation-->>PropagateAttrs: None (dropped with warning) end