Skip to content

Commit 38ebaf6

Browse files
committed
fix(tornado): ensure reading future.result() won't throw an exception in client.py _finish_tracing_callback
1 parent 25e429a commit 38ebaf6

File tree

1 file changed

+13
-11
lines changed
  • instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado

1 file changed

+13
-11
lines changed

Diff for: instrumentation/opentelemetry-instrumentation-tornado/src/opentelemetry/instrumentation/tornado/client.py

+13-11
Original file line numberDiff line numberDiff line change
@@ -109,13 +109,14 @@ def _finish_tracing_callback(
109109
description = None
110110
exc = future.exception()
111111

112-
response = future.result()
113-
114112
if span.is_recording() and exc:
115113
if isinstance(exc, HTTPError):
116114
status_code = exc.code
117115
description = f"{type(exc).__name__}: {exc}"
118-
else:
116+
117+
response = None
118+
if not exc:
119+
response = future.result()
119120
status_code = response.code
120121

121122
if status_code is not None:
@@ -127,15 +128,16 @@ def _finish_tracing_callback(
127128
)
128129
)
129130

130-
metric_attributes = _create_metric_attributes(response)
131-
request_size = int(response.request.headers.get("Content-Length", 0))
132-
response_size = int(response.headers.get("Content-Length", 0))
131+
if response is not None:
132+
metric_attributes = _create_metric_attributes(response)
133+
request_size = int(response.request.headers.get("Content-Length", 0))
134+
response_size = int(response.headers.get("Content-Length", 0))
133135

134-
duration_histogram.record(
135-
response.request_time, attributes=metric_attributes
136-
)
137-
request_size_histogram.record(request_size, attributes=metric_attributes)
138-
response_size_histogram.record(response_size, attributes=metric_attributes)
136+
duration_histogram.record(
137+
response.request_time, attributes=metric_attributes
138+
)
139+
request_size_histogram.record(request_size, attributes=metric_attributes)
140+
response_size_histogram.record(response_size, attributes=metric_attributes)
139141

140142
if response_hook:
141143
response_hook(span, future)

0 commit comments

Comments
 (0)