Repository navigation
fix(boto3): Trace the complete botocore client-call lifecycle - #7538
pabloDeputter merged 9 commits into
Conversation
Codecov Results 📊✅ 132487 passed | ⏭️ 7220 skipped | Total: 139707 | Pass Rate: 94.83% | Execution Time: 454m 48s 📊 Comparison with Base Branch
➖ Removed Tests (60)View removed tests
All tests are passing successfully. ✅ Patch coverage is 95.51%. Project has 2551 uncovered lines. Files with missing lines (3)
Coverage diff@@ Coverage Diff @@
## master #PR +/-##
==========================================
+ Coverage 90.31% 90.35% +0.04%
==========================================
Files 195 199 +4
Lines 26261 26422 +161
Branches 9798 9834 +36
==========================================
+ Hits 23714 23871 +157
- Misses 2547 2551 +4
- Partials 1485 1491 +6Generated by Codecov Action |
53a8717 to
4efce4b
Compare
4efce4b to
05501d2
Compare
ericapisani
left a comment
There was a problem hiding this comment.
Minor things but overall looking good. Will take a look at tests on my 2nd pass
| from sentry_sdk.integrations.boto3 import Boto3Integration | ||
| @contextmanager | ||
| def _activate_client_span(span: "StreamedSpan") -> "Iterator[StreamedSpan]": | ||
| """Temporarily activate an inactive boto span without ending it.""" |
There was a problem hiding this comment.
Worth adding context on why we're doing this.
| # use unknown if `service_id_hyphenized` so span name can still be created. | ||
| # e.g. "aws.unkown.GetObject" | ||
| service_name = ctx.service_id_hyphenized or "unknown" | ||
| span_name = "aws.%s.%s" % (service_name, ctx.operation_name) |
There was a problem hiding this comment.
f-strings are generally the preferred way to construct strings like this in modern python these days
| span_name = "aws.%s.%s" % (service_name, ctx.operation_name) | |
| span_name = f"aws.{service_name}.{ctx.operation_name}" |
There was a problem hiding this comment.
yupp, I took over the old code, but I usually also use f-strings.
| SPANDATA.SENTRY_ORIGIN: span_origin, | ||
| } | ||
| if ctx.service_id: | ||
| attributes[SPANDATA.RPC_METHOD] = "%s/%s" % ( |
| "sentry.op": OP.HTTP_CLIENT_STREAM, | ||
| "sentry.origin": Boto3Integration.origin, | ||
| SPANDATA.SENTRY_OP: OP.HTTP_CLIENT_STREAM, | ||
| SPANDATA.SENTRY_ORIGIN: Boto3Integration.origin, |
| if isinstance(span, StreamedSpan) and ( | ||
| span.get_attributes().get(SPANDATA.SENTRY_ORIGIN) != Boto3Integration.origin | ||
| ): |
There was a problem hiding this comment.
Because of the length of this conditional, I think it'd be a bit cleaner to pull this into a variable
| if isinstance(span, StreamedSpan) and ( | |
| span.get_attributes().get(SPANDATA.SENTRY_ORIGIN) != Boto3Integration.origin | |
| ): | |
| is_span_origin_from_boto = span.get_attributes().get(SPANDATA.SENTRY_ORIGIN) == Boto3Integration.origin | |
| if isinstance(span, StreamedSpan) and is_span_origin_from_boto: |
There was a problem hiding this comment.
I agree, but then you get the issue that the legacy span doesn't support get_attributes(); I fixed it like this:
# an ignored streamed span is not activated; avoid enriching its parent.
if isinstance(span, StreamedSpan):
if not (span.get_attributes().get(SPANDATA.SENTRY_ORIGIN) == ORIGIN):
return| }, | ||
| # boto3 integration owns span's lifecycle; keep child inactive so it | ||
| # can't restore boto3 span later on. | ||
| active=not is_inactive_boto3_span, |
There was a problem hiding this comment.
Apologies for this slight nitpick, but can we add a space after the = and before the not?
The "not" almost blends in with the =, especially because the syntax highlighting of Github and IDEs use the same colour for the two. 😭
There was a problem hiding this comment.
I agree, but the linter doesn't really like that 🤣 I fixed it by adding fmt: off and fmt: on for that specific block; I haven't seen it being used anywhere else in the codebase, so not sure whether this is correct.
05501d2 to
421da22
Compare
c3e8f5b to
66d4665
Compare
fe64ae9 to
add0913
Compare
f649477 to
4423557
Compare
4423557 to
c622458
Compare
c622458 to
3e4fcfd
Compare
ericapisani
left a comment
There was a problem hiding this comment.
Some minor things but otherwise LGTM 🚀 Approving to not block
| Track a single API call, including retries, serialization, and endpoint | ||
| resolution. For streaming responses, keep the span open until the | ||
| response body is consumed or closed. | ||
| https://github.com/boto/botocore/blob/develop/botocore/client.py |
There was a problem hiding this comment.
I think something got borked in a merge conflict resolution - I can see you made the change in this commit but for some reason it's still using the old path 🤔
There was a problem hiding this comment.
yeah I vaguely remember fixing it; so don't know why it was removed
| origin=ORIGIN, | ||
| return None | ||
|
|
||
| # use unknown if `service_id_hyphenized` so span name can still be created. |
There was a problem hiding this comment.
This looks like a partially incomplete comment - is it supposed to instead be the following?
| # use unknown if `service_id_hyphenized` so span name can still be created. | |
| # use unknown if `service_id_hyphenized` is not set so span name can still be created. |
| return None | ||
|
|
||
| # use unknown if `service_id_hyphenized` so span name can still be created. | ||
| # e.g. "aws.unkown.GetObject" |
There was a problem hiding this comment.
| # e.g. "aws.unkown.GetObject" | |
| # e.g. "aws.unknown.GetObject" |
5b894cb to
440b19a
Compare
440b19a to
04d968a
Compare
04d968a to
33807b8
Compare
| assert len(http_spans) == 1 | ||
| assert len(stream_spans) == 1 | ||
| client_span = client_spans[0] | ||
| http_span = http_spans[0] |
There was a problem hiding this comment.
AWS connection putrequest wrapper bypasses the stdlib span wrapper
_install_httplib wraps AWSHTTPConnection.putrequest before replacing HTTPConnection.putrequest, so the AWS wrapper captures the unpatched inherited method. The AWS class then shadows the patched base method, and boto HTTP requests skip stdlib HTTP span setup, including setting _sentrysdk_real_url (the boto client span is still created). Install the base wrapper before wrapping the AWS classes.
Evidence
_install_httplibsaves the originalHTTPConnection.putrequestand defines the sentry wrapper that creates the HTTP span and sets_sentrysdk_real_url.- It calls
_patch_aws_connection()before assigning that wrapper toHTTPConnection.putrequest. _patch_aws_connection()wrapsAWSHTTPConnection.putrequestat that point, capturing the unpatched method; the AWS class method then shadows the later base-class patch, so requests through it skip sentryputrequest.
Identified by Warden · code-review, find-bugs · GUM-LY4
33807b8 to
2647da1
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 2647da1. Configure here.

Description
Move boto3 span creation from individual HTTP request attempts to full botocore client-call lifecycle.
Previously, the client span was created from the botocore
request-createdevent; since botocore creates a newAwsRequestevent for every retry, these spans represent individual retries rather than the full event. Following OTel (https://opentelemetry.io/docs/specs/semconv/rpc/rpc-spans/#rpc-client-span) the span should cover the entire call lifecycle including all retries. Wrapping_make_api_call()covers all retries performed by botocore, including serialization, endpoint resolution, the final response or failures (https://github.com/boto/botocore/blob/develop/botocore/client.py:999).BaseClient._make_api_call()so one span represents a single boto operation; this span is also kept active across every retry attempt.request-createdis kept for breadcrumbs, HTTP request attributes, and trace propagation.StreamingBodyare kept open until body is consumed or closed.Issues
Resolves #7474