Skip to content

Commit 0629afd

Browse files
committed
address PR comments
1 parent 62f5e8a commit 0629afd

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
@@ -113,7 +113,7 @@ def _handle_request_impl(self: "RequestHandler") -> "Generator[None, None, None]
113113

114114
weak_handler = weakref.ref(self)
115115
client = sentry_sdk.get_client()
116-
span_streaming = has_span_streaming_enabled(client.options)
116+
is_span_streaming_enabled = has_span_streaming_enabled(client.options)
117117

118118
with sentry_sdk.isolation_scope() as scope:
119119
headers = self.request.headers
@@ -124,7 +124,7 @@ def _handle_request_impl(self: "RequestHandler") -> "Generator[None, None, None]
124124

125125
span_ctx: "ContextManager[Union[Span, StreamedSpan, None]]"
126126

127-
if span_streaming:
127+
if is_span_streaming_enabled:
128128
sentry_sdk.traces.continue_trace(dict(headers))
129129
scope.set_custom_sampling_context({"tornado_request": self.request})
130130

@@ -135,6 +135,7 @@ def _handle_request_impl(self: "RequestHandler") -> "Generator[None, None, None]
135135
"sentry.origin": TornadoIntegration.origin,
136136
"sentry.span.source": SegmentSource.ROUTE,
137137
},
138+
parent_span=None,
138139
)
139140
else:
140141
transaction = continue_trace(
@@ -161,12 +162,12 @@ def _handle_request_impl(self: "RequestHandler") -> "Generator[None, None, None]
161162

162163
method = getattr(self, self.request.method.lower(), None)
163164
if method is not None:
164-
tx_name = transaction_from_function(method) or ""
165-
if tx_name:
166-
span.name = tx_name
165+
span_name = transaction_from_function(method) or ""
166+
if span_name:
167+
span.name = span_name
167168
span.set_attribute(
168169
"sentry.span.source",
169-
SegmentSource.COMPONENT.value,
170+
SegmentSource.COMPONENT,
170171
)
171172

172173
try:

tests/integrations/tornado/test_tornado.py

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

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

166157
if code == 500:
167158
assert len(errors) == 1
@@ -527,10 +518,7 @@ def test_span_origin(
527518
sentry_sdk.flush()
528519

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

0 commit comments

Comments
 (0)