Skip to content

Commit 1684e7f

Browse files
committed
move request attrs to finally
1 parent 51f05cb commit 1684e7f

1 file changed

Lines changed: 15 additions & 17 deletions

File tree

sentry_sdk/integrations/tornado.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -157,30 +157,28 @@ def _handle_request_impl(self: "RequestHandler") -> "Generator[None, None, None]
157157
)
158158

159159
with span_ctx as span:
160-
if isinstance(span, StreamedSpan) and not isinstance(
161-
span, NoOpStreamedSpan
162-
):
163-
with capture_internal_exceptions():
164-
for attr, value in _get_request_attributes(self.request).items():
165-
span.set_attribute(attr, value)
166-
167-
method = getattr(self, self.request.method.lower(), None)
168-
if method is not None:
169-
span_name = transaction_from_function(method)
170-
if span_name:
171-
span.name = span_name
172-
span.set_attribute(
173-
"sentry.span.source",
174-
SegmentSource.COMPONENT,
175-
)
176-
177160
try:
178161
yield
179162
finally:
180163
if isinstance(span, StreamedSpan) and not isinstance(
181164
span, NoOpStreamedSpan
182165
):
183166
with capture_internal_exceptions():
167+
for attr, value in _get_request_attributes(
168+
self.request
169+
).items():
170+
span.set_attribute(attr, value)
171+
172+
method = getattr(self, self.request.method.lower(), None)
173+
if method is not None:
174+
span_name = transaction_from_function(method)
175+
if span_name:
176+
span.name = span_name
177+
span.set_attribute(
178+
"sentry.span.source",
179+
SegmentSource.COMPONENT,
180+
)
181+
184182
status_int = self.get_status()
185183
span.set_attribute(SPANDATA.HTTP_STATUS_CODE, status_int)
186184
span.status = "error" if status_int >= 400 else "ok"

0 commit comments

Comments
 (0)