From 5c22a0c451db14a327a4a68f532770f6c6459724 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Thu, 1 Oct 2026 12:48:54 +0200 Subject: [PATCH 1/3] Simplify --- sentry_sdk/integrations/boto3/_client.py | 5 ++--- sentry_sdk/integrations/boto3/_instrumentation.py | 13 ++----------- 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/sentry_sdk/integrations/boto3/_client.py b/sentry_sdk/integrations/boto3/_client.py index ece94bef4a..949687dd1c 100644 --- a/sentry_sdk/integrations/boto3/_client.py +++ b/sentry_sdk/integrations/boto3/_client.py @@ -5,7 +5,6 @@ from sentry_sdk.integrations import DidNotEnable from sentry_sdk.integrations.boto3._context import AwsCallContext from sentry_sdk.integrations.boto3._instrumentation import ( - _finish_span, _get_error_attributes, _get_response_attributes, _instrument_streaming_body, @@ -109,7 +108,7 @@ def sentry_patched_make_api_call( with capture_internal_exceptions(): span.set_attributes(_get_response_attributes(parsed)) except BaseException as error: - _finish_span(span, error) + span.__exit__(type(error), error, error.__traceback__) raise streaming_body_instrumented = False @@ -118,7 +117,7 @@ def sentry_patched_make_api_call( # `StreamingBody`s finish their span when consumed or closed. if not streaming_body_instrumented: - _finish_span(span) + span.end() return parsed BaseClient.__init__ = sentry_patched_init # type: ignore diff --git a/sentry_sdk/integrations/boto3/_instrumentation.py b/sentry_sdk/integrations/boto3/_instrumentation.py index daa44dbea1..c4bc549637 100644 --- a/sentry_sdk/integrations/boto3/_instrumentation.py +++ b/sentry_sdk/integrations/boto3/_instrumentation.py @@ -151,7 +151,6 @@ def _get_error_attributes(exception: "BaseException") -> "Attributes": def _start_client_span(ctx: "AwsCallContext") -> "Optional[Span]": - client = sentry_sdk.get_client() if client.get_integration(IDENTIFIER) is None: return None @@ -189,14 +188,6 @@ def _start_client_span(ctx: "AwsCallContext") -> "Optional[Span]": ) -def _finish_span(span: "Span", error: "Optional[BaseException]" = None) -> None: - with capture_internal_exceptions(): - if error is None: - span.end() - else: - span.__exit__(type(error), error, error.__traceback__) - - def _instrument_streaming_body(span: "Span", parsed: "Dict[str, Any]") -> bool: if isinstance(span, NoOpSpan): return False @@ -235,8 +226,8 @@ def finish_span(error: "Optional[BaseException]" = None) -> None: streaming_span.set_attributes(attributes) span.set_attributes(attributes) - _finish_span(streaming_span, error) - _finish_span(span, error) + streaming_span.__exit__(type(error), error, error.__traceback__) + span.__exit__(type(error), error, error.__traceback__) def content_length_reached() -> bool: content_length = getattr(body, "_content_length", None) From e0a2f172a7a934ca801404ebf0c770e3c881c021 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Thu, 1 Oct 2026 12:50:56 +0200 Subject: [PATCH 2/3] apis --- tests/integrations/asgi/test_asgi.py | 2 +- tests/integrations/sanic/test_sanic.py | 2 +- tests/integrations/wsgi/test_wsgi.py | 4 ++-- tests/tracing/test_span_streaming.py | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/integrations/asgi/test_asgi.py b/tests/integrations/asgi/test_asgi.py index bb2c364807..1f05f26797 100644 --- a/tests/integrations/asgi/test_asgi.py +++ b/tests/integrations/asgi/test_asgi.py @@ -168,7 +168,7 @@ async def app(scope, receive, send): await send({"type": "lifespan.shutdown.complete"}) return - with sentry_sdk.traces.start_span(name="child-span"): + with sentry_sdk.start_span(name="child-span"): pass await send( diff --git a/tests/integrations/sanic/test_sanic.py b/tests/integrations/sanic/test_sanic.py index 53b242b7a0..b54c9faefc 100644 --- a/tests/integrations/sanic/test_sanic.py +++ b/tests/integrations/sanic/test_sanic.py @@ -794,7 +794,7 @@ def test_is_localhost_span_attribute( @app.route("/child-span") def child_span_handler_localhost(request): - with sentry_sdk.traces.start_span(name="child-span"): + with sentry_sdk.start_span(name="child-span"): pass return response.text("ok") diff --git a/tests/integrations/wsgi/test_wsgi.py b/tests/integrations/wsgi/test_wsgi.py index a4f984181a..729d067bb4 100644 --- a/tests/integrations/wsgi/test_wsgi.py +++ b/tests/integrations/wsgi/test_wsgi.py @@ -1086,7 +1086,7 @@ def test_is_localhost_attribute( sentry_init, capture_items, client_kwargs, is_localhost ): def dogpark(environ, start_response): - with sentry_sdk.traces.start_span(name="child-span"): + with sentry_sdk.start_span(name="child-span"): pass start_response("200 OK", []) return ["woof"] @@ -1110,7 +1110,7 @@ def dogpark(environ, start_response): def test_user_agent_attribute(sentry_init, capture_items): def dogpark(environ, start_response): - with sentry_sdk.traces.start_span(name="child-span"): + with sentry_sdk.start_span(name="child-span"): pass start_response("200 OK", []) return ["woof"] diff --git a/tests/tracing/test_span_streaming.py b/tests/tracing/test_span_streaming.py index 826d7395d7..c6a4e0be20 100644 --- a/tests/tracing/test_span_streaming.py +++ b/tests/tracing/test_span_streaming.py @@ -478,7 +478,7 @@ def traces_sampler(sampling_context): items = capture_items("span") - with sentry_sdk.traces.start_span(name="test"): + with sentry_sdk.start_span(name="test"): ... sentry_sdk.flush() From d850d8c7e4a84f5204e515159fdd8d3bdd04a620 Mon Sep 17 00:00:00 2001 From: Ivana Kellyer Date: Thu, 1 Oct 2026 12:53:30 +0200 Subject: [PATCH 3/3] . --- sentry_sdk/integrations/boto3/_instrumentation.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/sentry_sdk/integrations/boto3/_instrumentation.py b/sentry_sdk/integrations/boto3/_instrumentation.py index c4bc549637..3a271510ed 100644 --- a/sentry_sdk/integrations/boto3/_instrumentation.py +++ b/sentry_sdk/integrations/boto3/_instrumentation.py @@ -226,8 +226,11 @@ def finish_span(error: "Optional[BaseException]" = None) -> None: streaming_span.set_attributes(attributes) span.set_attributes(attributes) - streaming_span.__exit__(type(error), error, error.__traceback__) - span.__exit__(type(error), error, error.__traceback__) + streaming_span.__exit__(type(error), error, error.__traceback__) + span.__exit__(type(error), error, error.__traceback__) + else: + streaming_span.end() + span.end() def content_length_reached() -> bool: content_length = getattr(body, "_content_length", None)