ref: Add streaming trace decorator (7) #1328
Triggered via pull request
March 5, 2026 13:49
sentrivana
synchronize
#5594
Status
Success
Total duration
18s
Artifacts
–
changelog-preview.yml
on: pull_request_target
changelog-preview
/
preview
13s
Annotations
3 errors and 1 warning
|
Circular import will cause ImportError at runtime:
sentry_sdk/tracing_utils.py#L1377
This module-level import from `sentry_sdk.traces` creates a circular import. When `traces.py` is imported first, it attempts to import `Baggage` from `tracing_utils.py` at line 13. This triggers `tracing_utils.py` to load, which now tries to import `LOW_QUALITY_SEGMENT_SOURCES`, `start_span`, and `StreamedSpan` from `traces.py`. However, `traces.py` hasn't finished loading yet (it's still at line 13), so these symbols don't exist, causing an `ImportError`. The existing pattern in this file handles circular imports via deferred/lazy imports inside functions (see `create_streaming_span_decorator` which does `from sentry_sdk.scope import...` inside the function body).
|
|
StreamedSpan lacks context manager methods (__enter__/__exit__) causing decorator to fail at runtime:
sentry_sdk/traces.py#L350
The new `trace` decorator at line 350 calls `create_streaming_span_decorator` which uses `start_streaming_span` in a `with` statement (lines 964-966 and 979-982 in tracing_utils.py). However, `StreamedSpan` (the return type of `start_streaming_span`) does not implement `__enter__` and `__exit__` methods. This will cause a `TypeError: 'StreamedSpan' object does not support the context manager protocol` when any function decorated with `@trace` (from `sentry_sdk.traces`) is called.
|
|
[4SM-ZV7] StreamedSpan lacks context manager methods (__enter__/__exit__) causing decorator to fail at runtime (additional location):
sentry_sdk/tracing_utils.py#L964
The new `trace` decorator at line 350 calls `create_streaming_span_decorator` which uses `start_streaming_span` in a `with` statement (lines 964-966 and 979-982 in tracing_utils.py). However, `StreamedSpan` (the return type of `start_streaming_span`) does not implement `__enter__` and `__exit__` methods. This will cause a `TypeError: 'StreamedSpan' object does not support the context manager protocol` when any function decorated with `@trace` (from `sentry_sdk.traces`) is called.
|
|
Missing test coverage for new streaming trace decorator:
sentry_sdk/traces.py#L350
The PR adds a new `trace` decorator in `traces.py` that wraps `create_streaming_span_decorator`, but there are no corresponding tests for this new functionality. The existing `test_decorator.py` tests only cover the `trace` decorator from `sentry_sdk.tracing`, not the new streaming equivalent in `sentry_sdk.traces`. Tests should verify the decorator works correctly for both sync and async functions, handles parameters (name, attributes, active) properly, and behaves correctly when used with and without parentheses (`@trace` vs `@trace(...)`).
|