Skip to content

Commit d7140f0

Browse files
committed
Merge branch 'potel-base' into potel-base-run-all-tests
2 parents 18ec5cc + c4f2a2a commit d7140f0

File tree

6 files changed

+26
-18
lines changed

6 files changed

+26
-18
lines changed

sentry_sdk/integrations/boto3.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,20 +116,19 @@ def _sentry_after_call(context, parsed, **kwargs):
116116
data=span_data,
117117
)
118118

119-
span.__exit__(None, None, None)
120-
121119
body = parsed.get("Body")
122120
if not isinstance(body, StreamingBody):
121+
span.__exit__(None, None, None)
123122
return
124123

125-
streaming_span = span.start_child(
124+
streaming_span = sentry_sdk.start_span(
126125
op=OP.HTTP_CLIENT_STREAM,
127-
name=span.description,
126+
name=span.name,
128127
origin=Boto3Integration.origin,
128+
only_if_parent=True,
129129
)
130130

131131
orig_read = body.read
132-
orig_close = body.close
133132

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

145144
body.read = sentry_streaming_body_read
146145

146+
orig_close = body.close
147+
147148
def sentry_streaming_body_close(*args, **kwargs):
148149
# type: (*Any, **Any) -> None
149150
streaming_span.finish()
150151
orig_close(*args, **kwargs)
151152

152153
body.close = sentry_streaming_body_close
153154

155+
span.__exit__(None, None, None)
156+
154157

155158
def _sentry_after_call_error(context, exception, **kwargs):
156159
# type: (Dict[str, Any], Type[BaseException], **Any) -> None

sentry_sdk/integrations/huey.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ def _sentry_execute(self, task, timestamp=None):
162162

163163
sentry_headers = task.kwargs.pop("sentry_headers", {})
164164
with sentry_sdk.continue_trace(sentry_headers):
165-
with sentry_sdk.start_transaction(
165+
with sentry_sdk.start_span(
166166
name=task.name,
167167
op=OP.QUEUE_TASK_HUEY,
168168
source=TRANSACTION_SOURCE_TASK,

sentry_sdk/tracing.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,12 @@ def __exit__(self, ty, value, tb):
13131313
if value is not None:
13141314
self.set_status(SPANSTATUS.INTERNAL_ERROR)
13151315
else:
1316-
self.set_status(SPANSTATUS.OK)
1316+
status_unset = (
1317+
hasattr(self._otel_span, "status")
1318+
and self._otel_span.status.status_code == StatusCode.UNSET
1319+
)
1320+
if status_unset:
1321+
self.set_status(SPANSTATUS.OK)
13171322

13181323
self.finish()
13191324
context.detach(self._ctx_token)

tests/integrations/boto3/test_s3.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def test_basic(sentry_init, capture_events):
2121
events = capture_events()
2222

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

4646
try:
4747
s3 = session.resource("s3")
48-
with sentry_sdk.start_transaction(), MockResponse(
48+
with sentry_sdk.start_span(), MockResponse(
4949
s3.meta.client, 200, {}, read_fixture("s3_list.xml")
5050
):
5151
bucket = s3.Bucket("bucket")
@@ -75,7 +75,7 @@ def test_streaming(sentry_init, capture_events):
7575
events = capture_events()
7676

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

115115
s3 = session.resource("s3")
116-
with sentry_sdk.start_transaction() as transaction, MockResponse(
116+
with sentry_sdk.start_span() as transaction, MockResponse(
117117
s3.meta.client, 200, {}, b"hello"
118118
):
119119
obj = s3.Bucket("bucket").Object("foo.pdf")
@@ -142,7 +142,7 @@ def test_omit_url_data_if_parsing_fails(sentry_init, capture_events):
142142
"sentry_sdk.integrations.boto3.parse_url",
143143
side_effect=ValueError,
144144
):
145-
with sentry_sdk.start_transaction() as transaction, MockResponse(
145+
with sentry_sdk.start_span() as transaction, MockResponse(
146146
s3.meta.client, 200, {}, read_fixture("s3_list.xml")
147147
):
148148
bucket = s3.Bucket("bucket")
@@ -170,7 +170,7 @@ def test_span_origin(sentry_init, capture_events):
170170
events = capture_events()
171171

172172
s3 = session.resource("s3")
173-
with sentry_sdk.start_transaction(), MockResponse(
173+
with sentry_sdk.start_span(), MockResponse(
174174
s3.meta.client, 200, {}, read_fixture("s3_list.xml")
175175
):
176176
bucket = s3.Bucket("bucket")

tests/integrations/cohere/test_cohere.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ def test_bad_chat(sentry_init, capture_events):
152152
with pytest.raises(httpx.HTTPError):
153153
client.chat(model="some-model", message="hello")
154154

155-
(event, _) = events
155+
(event,) = events
156156
assert event["level"] == "error"
157157

158158

tests/integrations/huey/test_huey.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import pytest
22
from decimal import DivisionByZero
33

4-
from sentry_sdk import start_transaction
4+
import sentry_sdk
55
from sentry_sdk.integrations.huey import HueyIntegration
66
from sentry_sdk.utils import parse_version
77

@@ -160,7 +160,7 @@ def dummy_task():
160160

161161
events = capture_events()
162162

163-
with start_transaction() as transaction:
163+
with sentry_sdk.start_span() as transaction:
164164
dummy_task()
165165

166166
(event,) = events
@@ -182,7 +182,7 @@ def test_huey_propagate_trace(init_huey, capture_events):
182182
def propagated_trace_task():
183183
pass
184184

185-
with start_transaction() as outer_transaction:
185+
with sentry_sdk.start_span() as outer_transaction:
186186
execute_huey_task(huey, propagated_trace_task)
187187

188188
assert (
@@ -200,7 +200,7 @@ def dummy_task():
200200

201201
events = capture_events()
202202

203-
with start_transaction():
203+
with sentry_sdk.start_span():
204204
dummy_task()
205205

206206
(event,) = events

0 commit comments

Comments
 (0)