Skip to content

Fix boto3 tests in POTel #3844

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 4, 2024
Merged
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
13 changes: 8 additions & 5 deletions sentry_sdk/integrations/boto3.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,20 +116,19 @@ def _sentry_after_call(context, parsed, **kwargs):
data=span_data,
)

span.__exit__(None, None, None)

body = parsed.get("Body")
if not isinstance(body, StreamingBody):
span.__exit__(None, None, None)
return

streaming_span = span.start_child(
streaming_span = sentry_sdk.start_span(
op=OP.HTTP_CLIENT_STREAM,
name=span.description,
name=span.name,
origin=Boto3Integration.origin,
only_if_parent=True,
)

orig_read = body.read
orig_close = body.close

def sentry_streaming_body_read(*args, **kwargs):
# type: (*Any, **Any) -> bytes
Expand All @@ -144,13 +143,17 @@ def sentry_streaming_body_read(*args, **kwargs):

body.read = sentry_streaming_body_read

orig_close = body.close

def sentry_streaming_body_close(*args, **kwargs):
# type: (*Any, **Any) -> None
streaming_span.finish()
orig_close(*args, **kwargs)

body.close = sentry_streaming_body_close

span.__exit__(None, None, None)


def _sentry_after_call_error(context, exception, **kwargs):
# type: (Dict[str, Any], Type[BaseException], **Any) -> None
Expand Down
12 changes: 6 additions & 6 deletions tests/integrations/boto3/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def test_basic(sentry_init, capture_events):
events = capture_events()

s3 = session.resource("s3")
with sentry_sdk.start_transaction() as transaction, MockResponse(
with sentry_sdk.start_span() as transaction, MockResponse(
s3.meta.client, 200, {}, read_fixture("s3_list.xml")
):
bucket = s3.Bucket("bucket")
Expand All @@ -45,7 +45,7 @@ def test_breadcrumb(sentry_init, capture_events):

try:
s3 = session.resource("s3")
with sentry_sdk.start_transaction(), MockResponse(
with sentry_sdk.start_span(), MockResponse(
s3.meta.client, 200, {}, read_fixture("s3_list.xml")
):
bucket = s3.Bucket("bucket")
Expand Down Expand Up @@ -75,7 +75,7 @@ def test_streaming(sentry_init, capture_events):
events = capture_events()

s3 = session.resource("s3")
with sentry_sdk.start_transaction() as transaction, MockResponse(
with sentry_sdk.start_span() as transaction, MockResponse(
s3.meta.client, 200, {}, b"hello"
):
obj = s3.Bucket("bucket").Object("foo.pdf")
Expand Down Expand Up @@ -113,7 +113,7 @@ def test_streaming_close(sentry_init, capture_events):
events = capture_events()

s3 = session.resource("s3")
with sentry_sdk.start_transaction() as transaction, MockResponse(
with sentry_sdk.start_span() as transaction, MockResponse(
s3.meta.client, 200, {}, b"hello"
):
obj = s3.Bucket("bucket").Object("foo.pdf")
Expand Down Expand Up @@ -142,7 +142,7 @@ def test_omit_url_data_if_parsing_fails(sentry_init, capture_events):
"sentry_sdk.integrations.boto3.parse_url",
side_effect=ValueError,
):
with sentry_sdk.start_transaction() as transaction, MockResponse(
with sentry_sdk.start_span() as transaction, MockResponse(
s3.meta.client, 200, {}, read_fixture("s3_list.xml")
):
bucket = s3.Bucket("bucket")
Expand Down Expand Up @@ -170,7 +170,7 @@ def test_span_origin(sentry_init, capture_events):
events = capture_events()

s3 = session.resource("s3")
with sentry_sdk.start_transaction(), MockResponse(
with sentry_sdk.start_span(), MockResponse(
s3.meta.client, 200, {}, read_fixture("s3_list.xml")
):
bucket = s3.Bucket("bucket")
Expand Down
Loading