ref: Support outgoing trace propagation in span first (18) #5638
3 issues
find-bugs: Found 3 issues (1 high, 2 medium)
High
API signature mismatch causes TypeError when span streaming is enabled - `sentry_sdk/ai/utils.py:530-536`
The get_start_span_function() returns sentry_sdk.traces.start_span when span streaming is enabled or when current span is a StreamedSpan. However, sentry_sdk.traces.start_span has signature (name, attributes, parent_span, active) while all callers use (op=..., name=..., origin=...) kwargs. This will cause TypeError: start_span() got an unexpected keyword argument 'op' at runtime when span streaming mode is active.
Medium
Early return in set_transaction_name skips _transaction_info update for NoOpStreamedSpan - `sentry_sdk/scope.py:843`
When set_transaction_name is called with a source argument and the scope has a NoOpStreamedSpan, the function returns early at line 843, skipping the self._transaction_info["source"] = source update at line 857-858. This causes the transaction source to be lost and not applied to events via _apply_transaction_info_to_event(). The NoOpStreamedSpan check should either not return early or the _transaction_info update should happen before the return.
NoOpStreamedSpan will crash when inherited _iter_headers, _get_baggage, etc. methods are called - `sentry_sdk/traces.py:504-512`
The new methods _dynamic_sampling_context, _to_baggage, _get_baggage, _iter_headers, and _get_trace_context added to StreamedSpan access self._segment and self._baggage attributes. However, NoOpStreamedSpan extends StreamedSpan but does not initialize these attributes in its __init__. When scope.iter_trace_propagation_headers() is called with a NoOpStreamedSpan on the scope, it calls span._iter_headers() without a guard (unlike get_traceparent, get_baggage, get_trace_context which check not isinstance(self.span, NoOpStreamedSpan)), causing an AttributeError: 'NoOpStreamedSpan' object has no attribute '_segment'.
Also found at:
sentry_sdk/tracing_utils.py:1123-1124
Duration: 14m 55s · Tokens: 9.9M in / 60.6k out · Cost: $13.18 (+extraction: $0.01, +merge: $0.00)
Annotations
Check failure on line 536 in sentry_sdk/ai/utils.py
sentry-warden / warden: find-bugs
API signature mismatch causes TypeError when span streaming is enabled
The `get_start_span_function()` returns `sentry_sdk.traces.start_span` when span streaming is enabled or when current span is a `StreamedSpan`. However, `sentry_sdk.traces.start_span` has signature `(name, attributes, parent_span, active)` while all callers use `(op=..., name=..., origin=...)` kwargs. This will cause `TypeError: start_span() got an unexpected keyword argument 'op'` at runtime when span streaming mode is active.
Check warning on line 843 in sentry_sdk/scope.py
sentry-warden / warden: find-bugs
Early return in set_transaction_name skips _transaction_info update for NoOpStreamedSpan
When `set_transaction_name` is called with a `source` argument and the scope has a `NoOpStreamedSpan`, the function returns early at line 843, skipping the `self._transaction_info["source"] = source` update at line 857-858. This causes the transaction source to be lost and not applied to events via `_apply_transaction_info_to_event()`. The `NoOpStreamedSpan` check should either not return early or the `_transaction_info` update should happen before the return.
Check warning on line 512 in sentry_sdk/traces.py
sentry-warden / warden: find-bugs
NoOpStreamedSpan will crash when inherited _iter_headers, _get_baggage, etc. methods are called
The new methods `_dynamic_sampling_context`, `_to_baggage`, `_get_baggage`, `_iter_headers`, and `_get_trace_context` added to `StreamedSpan` access `self._segment` and `self._baggage` attributes. However, `NoOpStreamedSpan` extends `StreamedSpan` but does not initialize these attributes in its `__init__`. When `scope.iter_trace_propagation_headers()` is called with a `NoOpStreamedSpan` on the scope, it calls `span._iter_headers()` without a guard (unlike `get_traceparent`, `get_baggage`, `get_trace_context` which check `not isinstance(self.span, NoOpStreamedSpan)`), causing an `AttributeError: 'NoOpStreamedSpan' object has no attribute '_segment'`.
Check warning on line 1124 in sentry_sdk/tracing_utils.py
sentry-warden / warden: find-bugs
[7WR-SET] NoOpStreamedSpan will crash when inherited _iter_headers, _get_baggage, etc. methods are called (additional location)
The new methods `_dynamic_sampling_context`, `_to_baggage`, `_get_baggage`, `_iter_headers`, and `_get_trace_context` added to `StreamedSpan` access `self._segment` and `self._baggage` attributes. However, `NoOpStreamedSpan` extends `StreamedSpan` but does not initialize these attributes in its `__init__`. When `scope.iter_trace_propagation_headers()` is called with a `NoOpStreamedSpan` on the scope, it calls `span._iter_headers()` without a guard (unlike `get_traceparent`, `get_baggage`, `get_trace_context` which check `not isinstance(self.span, NoOpStreamedSpan)`), causing an `AttributeError: 'NoOpStreamedSpan' object has no attribute '_segment'`.