File tree Expand file tree Collapse file tree
sentry_sdk/integrations/boto3 Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55from sentry_sdk .integrations .boto3 import Boto3Integration
66from sentry_sdk .integrations .boto3 ._context import AwsCallContext
77from sentry_sdk .integrations .boto3 ._instrumentation import (
8+ _finish_active_http_child_span ,
89 _finish_client_span ,
910 _sentry_before_sign ,
1011 _sentry_request_created ,
@@ -65,11 +66,13 @@ def sentry_patched_make_api_call(
6566 except BaseException as exc :
6667 if span is not None :
6768 with capture_internal_exceptions ():
69+ _finish_active_http_child_span (span )
6870 span .__exit__ (type (exc ), exc , exc .__traceback__ )
6971 raise
7072
7173 if span is not None :
7274 with capture_internal_exceptions ():
75+ _finish_active_http_child_span (span )
7376 _finish_client_span (span , parsed )
7477 return parsed
7578
Original file line number Diff line number Diff line change 3333
3434
3535_AWS_RPC_SYSTEM_NAME = "aws-api"
36+ _STDLIB_HTTP_SPAN_ORIGIN = "auto.http.stdlib.httplib"
3637
3738
3839def _set_span_attributes (
@@ -140,6 +141,30 @@ def _start_client_span(
140141 return span
141142
142143
144+ def _finish_active_http_child_span (
145+ span : "Union[Span, StreamedSpan]" ,
146+ ) -> None :
147+ if not isinstance (span , StreamedSpan ):
148+ return
149+
150+ http_span = sentry_sdk .traces .get_current_span ()
151+ if (
152+ http_span is None
153+ or http_span is span
154+ or http_span .get_attributes ().get (SPANDATA .SENTRY_ORIGIN )
155+ != _STDLIB_HTTP_SPAN_ORIGIN
156+ or http_span ._parent_span_id != span .span_id
157+ ):
158+ return
159+
160+ # Stdlib normally keeps its HTTP span open until the response body is read.
161+ # Boto3 has a separate `http.client.stream` span for that work, so finish the
162+ # HTTP span after the headers and preserve LIFO scope restoration. OTel permits
163+ # HTTP client spans to end after response headers are read.
164+ # https://opentelemetry.io/docs/specs/semconv/http/http-spans/#http-client-span-duration
165+ http_span .end ()
166+
167+
143168def _finish_client_span (
144169 span : "Union[Span, StreamedSpan]" ,
145170 parsed : "Dict[str, Any]" ,
You can’t perform that action at this time.
0 commit comments