Skip to content

Commit 036b60a

Browse files
committed
address PR comments
1 parent a58538d commit 036b60a

2 files changed

Lines changed: 9 additions & 20 deletions

File tree

sentry_sdk/integrations/tornado.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ def _handle_request_impl(self: "RequestHandler") -> "Generator[None, None, None]
120120

121121
weak_handler = weakref.ref(self)
122122
client = sentry_sdk.get_client()
123-
span_streaming = has_span_streaming_enabled(client.options)
123+
is_span_streaming_enabled = has_span_streaming_enabled(client.options)
124124

125125
with sentry_sdk.isolation_scope() as scope:
126126
headers = self.request.headers
@@ -131,7 +131,7 @@ def _handle_request_impl(self: "RequestHandler") -> "Generator[None, None, None]
131131

132132
span_ctx: "ContextManager[Union[Span, StreamedSpan, None]]"
133133

134-
if span_streaming:
134+
if is_span_streaming_enabled:
135135
sentry_sdk.traces.continue_trace(dict(headers))
136136
scope.set_custom_sampling_context({"tornado_request": self.request})
137137

@@ -142,6 +142,7 @@ def _handle_request_impl(self: "RequestHandler") -> "Generator[None, None, None]
142142
"sentry.origin": TornadoIntegration.origin,
143143
"sentry.span.source": SegmentSource.ROUTE,
144144
},
145+
parent_span=None,
145146
)
146147
else:
147148
transaction = continue_trace(
@@ -168,12 +169,12 @@ def _handle_request_impl(self: "RequestHandler") -> "Generator[None, None, None]
168169

169170
method = getattr(self, self.request.method.lower(), None)
170171
if method is not None:
171-
tx_name = transaction_from_function(method) or ""
172-
if tx_name:
173-
span.name = tx_name
172+
span_name = transaction_from_function(method) or ""
173+
if span_name:
174+
span.name = span_name
174175
span.set_attribute(
175176
"sentry.span.source",
176-
SegmentSource.COMPONENT.value,
177+
SegmentSource.COMPONENT,
177178
)
178179

179180
try:

tests/integrations/tornado/test_tornado.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -153,16 +153,7 @@ def test_transactions(
153153
spans = [i.payload for i in items if i.type == "span"]
154154
errors = [i.payload for i in items if i.type == "event"]
155155

156-
# client tx + server segment span
157-
assert len(spans) >= 2
158-
server_segment = next(
159-
s for s in spans if s["attributes"].get("sentry.op") == "http.server"
160-
)
161-
client_segment = next(
162-
s
163-
for s in spans
164-
if s["attributes"].get("sentry.op") != "http.server" and s.get("is_segment")
165-
)
156+
client_segment, server_segment = spans
166157

167158
if code == 500:
168159
assert len(errors) == 1
@@ -528,10 +519,7 @@ def test_span_origin(
528519
sentry_sdk.flush()
529520

530521
if span_streaming:
531-
spans = [i.payload for i in items]
532-
segment = next(
533-
s for s in spans if s["attributes"].get("sentry.op") == "http.server"
534-
)
522+
(segment,) = [i.payload for i in items]
535523
assert segment["attributes"]["sentry.origin"] == "auto.http.tornado"
536524
else:
537525
(_, event) = events

0 commit comments

Comments
 (0)