@@ -109,13 +109,14 @@ def _finish_tracing_callback(
109
109
description = None
110
110
exc = future .exception ()
111
111
112
- response = future .result ()
113
-
114
112
if span .is_recording () and exc :
115
113
if isinstance (exc , HTTPError ):
116
114
status_code = exc .code
117
115
description = f"{ type (exc ).__name__ } : { exc } "
118
- else :
116
+
117
+ response = None
118
+ if not exc :
119
+ response = future .result ()
119
120
status_code = response .code
120
121
121
122
if status_code is not None :
@@ -127,15 +128,16 @@ def _finish_tracing_callback(
127
128
)
128
129
)
129
130
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 ))
133
135
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 )
139
141
140
142
if response_hook :
141
143
response_hook (span , future )
0 commit comments