Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions MIGRATION_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ Looking to upgrade from Sentry SDK 2.x to 3.x? Here's a comprehensive list of wh
- The SDK won't set any tags on its own anymore.
- The `update_current_span` API was removed.
- `SanicIntegration` no longer accepts `unsampled_statuses`.
- The `trace_ignore_status_codes` option was removed.


## Deprecated
Expand Down
36 changes: 5 additions & 31 deletions sentry_sdk/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@
from sentry_sdk.scrubber import EventScrubber
from sentry_sdk.serializer import serialize
from sentry_sdk.sessions import SessionFlusher
from sentry_sdk.traces import SpanStatus, StreamedSpan
from sentry_sdk.traces import trace as streaming_trace
from sentry_sdk.tracing import trace as legacy_trace
from sentry_sdk.tracing_utils import has_span_streaming_enabled
from sentry_sdk.traces import SpanStatus, StreamedSpan, trace
from sentry_sdk.transport import (
AsyncHttpTransport,
HttpTransportCore,
Expand Down Expand Up @@ -364,21 +361,6 @@ def _get_options(*args: "Optional[str]", **kwargs: "Any") -> "Dict[str, Any]":
env_to_bool(os.environ.get("SENTRY_KEEP_ALIVE"), strict=True) or False
)

if rv["trace_ignore_status_codes"] and has_span_streaming_enabled(rv):
logger.warning(
"The `trace_ignore_status_codes` parameter is ignored in span streaming mode.",
)

if rv["ignore_spans"] and not has_span_streaming_enabled(rv):
logger.warning(
"The `ignore_spans` parameter only works when `trace_lifecycle` is set to `stream`.",
)

if rv["before_send_span"] and not has_span_streaming_enabled(rv):
logger.warning(
"The `before_send_span` parameter only works when `trace_lifecycle` is set to `stream`.",
)

return rv


Expand Down Expand Up @@ -512,12 +494,6 @@ def _setup_instrumentation(
"""
Instruments the functions given in the list `functions_to_trace` with a trace decorator.
"""
trace = (
streaming_trace
if has_span_streaming_enabled(self.options)
else legacy_trace
)

for function in functions_to_trace:
class_name = None
function_qualname = function["qualified_name"]
Expand Down Expand Up @@ -640,12 +616,10 @@ def _record_lost_event(
record_lost_func=_record_lost_event,
)

self.span_batcher = None
if has_span_streaming_enabled(self.options):
self.span_batcher = SpanBatcher(
capture_func=_capture_envelope,
record_lost_func=_record_lost_event,
)
self.span_batcher = SpanBatcher(
capture_func=_capture_envelope,
record_lost_func=_record_lost_event,
)

max_request_body_size = ("always", "never", "small", "medium")
if self.options["max_request_body_size"] not in max_request_body_size:
Expand Down
15 changes: 3 additions & 12 deletions sentry_sdk/scope.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,12 +585,9 @@ def get_traceparent(self, *args: "Any", **kwargs: "Any") -> "Optional[str]":
if not has_tracing_enabled(client.options):
return self.get_active_propagation_context().to_traceparent()

span_streaming = has_span_streaming_enabled(client.options)
# If we have an active span, return traceparent from there
if span_streaming and self.streamed_span is not None:
if self.streamed_span is not None:
return self.streamed_span._to_traceparent()
elif not span_streaming and self.span is not None:
return self.span._to_traceparent()

# else return traceparent from the propagation context
return self.get_active_propagation_context().to_traceparent()
Expand All @@ -605,12 +602,9 @@ def get_baggage(self, *args: "Any", **kwargs: "Any") -> "Optional[Baggage]":
if not has_tracing_enabled(client.options):
return self.get_active_propagation_context().get_baggage()

span_streaming = has_span_streaming_enabled(client.options)
# If we have an active span, return baggage from there
if span_streaming and self.streamed_span is not None:
if self.streamed_span is not None:
return self.streamed_span._to_baggage()
elif not span_streaming and self.span is not None:
return self.span._to_baggage()

# else return baggage from the propagation context
return self.get_active_propagation_context().get_baggage()
Expand Down Expand Up @@ -666,8 +660,7 @@ def iter_trace_propagation_headers(

span = kwargs.pop("span", None)
if not span:
span_streaming = has_span_streaming_enabled(client.options)
span = self.streamed_span if span_streaming else self.span
span = self.streamed_span

if (
has_tracing_enabled(client.options)
Expand Down Expand Up @@ -1415,8 +1408,6 @@ def _capture_span(self, span: "Optional[StreamedSpan]") -> None:
return

client = self.get_client()
if not has_span_streaming_enabled(client.options):
return

merged_scope = self._merge_scopes()
client._capture_span(span, scope=merged_scope)
Expand Down
11 changes: 0 additions & 11 deletions sentry_sdk/traces.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,17 +165,6 @@ def start_span(
:return: The span that has been started.
:rtype: StreamedSpan
"""
from sentry_sdk.tracing_utils import has_span_streaming_enabled

client = sentry_sdk.get_client()
if client.is_active() and not has_span_streaming_enabled(client.options):
logger.warning(
"Using span streaming API in non-span-streaming mode. Use "
"sentry_sdk.start_transaction() and sentry_sdk.start_span() "
"instead.",
)
return NoOpStreamedSpan()

return sentry_sdk.get_current_scope().start_streamed_span(
name, attributes, parent_span, active
)
Expand Down
1 change: 0 additions & 1 deletion sentry_sdk/tracing.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,6 @@ def __enter__(self) -> "Span":
old_span = scope.span
scope.span = self
self._context_manager_state = (scope, old_span)
return self

def __exit__(
self, ty: "Optional[Any]", value: "Optional[Any]", tb: "Optional[Any]"
Expand Down
14 changes: 0 additions & 14 deletions sentry_sdk/tracing_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -1158,13 +1158,6 @@ def span_decorator(f: "Any") -> "Any":

@functools.wraps(f)
async def async_wrapper(*args: "Any", **kwargs: "Any") -> "Any":
client = sentry_sdk.get_client()
if client.is_active() and not has_span_streaming_enabled(client.options):
logger.warning(
"Using span streaming API in non-span-streaming mode. Use "
"@sentry_sdk.trace instead.",
)

span_name = name or qualname_from_function(f) or ""

with start_streaming_span(
Expand All @@ -1180,13 +1173,6 @@ async def async_wrapper(*args: "Any", **kwargs: "Any") -> "Any":

@functools.wraps(f)
def sync_wrapper(*args: "Any", **kwargs: "Any") -> "Any":
client = sentry_sdk.get_client()
if client.is_active() and not has_span_streaming_enabled(client.options):
logger.warning(
"Using span streaming API in non-span-streaming mode. Use "
"@sentry_sdk.trace instead.",
)

span_name = name or qualname_from_function(f) or ""

with start_streaming_span(
Expand Down
32 changes: 0 additions & 32 deletions tests/tracing/test_span_streaming.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
SpanStatus,
StreamedSpan,
)
from sentry_sdk.tracing_utils import has_span_streaming_enabled

minimum_python_38 = pytest.mark.skipif(
sys.version_info < (3, 8), reason="Asyncio tests need Python >= 3.8"
Expand Down Expand Up @@ -1773,37 +1772,6 @@ def test_default_attributes(sentry_init, capture_envelopes):
}


@pytest.mark.parametrize(
("options", "expected"),
[
({"trace_lifecycle": "stream"}, True),
({"_experiments": {"trace_lifecycle": "stream"}}, True),
(
{
"trace_lifecycle": "stream",
"_experiments": {"trace_lifecycle": "static"},
},
True,
),
(
{
"trace_lifecycle": "static",
"_experiments": {"trace_lifecycle": "stream"},
},
False,
),
({"trace_lifecycle": "static"}, False),
({"_experiments": {"trace_lifecycle": "static"}}, False),
({}, False),
({"_experiments": {}}, False),
({"_experiments": None}, False),
(None, False),
],
)
def test_has_span_streaming_enabled(options, expected):
assert has_span_streaming_enabled(options) is expected


def test_trace_lifecycle_top_level_enables_streaming(sentry_init, capture_items):
sentry_init(traces_sample_rate=1.0, trace_lifecycle="stream")

Expand Down
Loading