Skip to content

Commit 07151ce

Browse files
committed
fix: Fix httplib tests
1 parent 8be17f2 commit 07151ce

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

sentry_sdk/integrations/stdlib.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,21 @@ def putrequest(self, method, url, *args, **kwargs):
4343
url,
4444
)
4545

46-
self._sentrysdk_recorder = record_http_request(hub, real_url, method)
47-
self._sentrysdk_data_dict = self._sentrysdk_recorder.__enter__()
46+
recorder = record_http_request(hub, real_url, method)
47+
data_dict = recorder.__enter__()
4848

4949
try:
5050
rv = real_putrequest(self, method, url, *args, **kwargs)
5151

5252
for key, value in hub.iter_trace_propagation_headers():
5353
self.putheader(key, value)
5454
except Exception:
55-
self._sentrysdk_recorder.__exit__(*sys.exc_info())
56-
self._sentrysdk_recorder = self._sentrysdk_data_dict = None
55+
recorder.__exit__(*sys.exc_info())
5756
raise
5857

58+
self._sentrysdk_recorder = recorder
59+
self._sentrysdk_data_dict = data_dict
60+
5961
return rv
6062

6163
def getresponse(self, *args, **kwargs):
@@ -72,7 +74,6 @@ def getresponse(self, *args, **kwargs):
7274
finally:
7375
if recorder is not None:
7476
recorder.__exit__(*sys.exc_info())
75-
self._sentrysdk_recorder = self._sentrysdk_data_dict = None
7677

7778
return rv
7879

sentry_sdk/integrations/wsgi.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ def __call__(self, environ, start_response):
8484
scope._name = "wsgi"
8585
scope.add_event_processor(_make_wsgi_event_processor(environ))
8686

87-
with hub.trace(span=Span.continue_from_environ(environ)):
87+
with hub.span(Span.continue_from_environ(environ)):
8888
try:
8989
rv = self.app(environ, start_response)
9090
except BaseException:

sentry_sdk/tracing.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import re
2+
import sys
23
import uuid
34
import contextlib
45

@@ -186,15 +187,17 @@ def record_http_request(hub, url, method):
186187
yield data_dict
187188
finally:
188189
httplib_response = data_dict.pop("httplib_response", None)
190+
189191
if span is not None:
190192
if "status_code" in data_dict:
191193
span.set_tag("http.status_code", data_dict["status_code"])
192194
for k, v in data_dict.items():
193195
span.set_data(k, v)
194196

195-
hub.add_breadcrumb(
196-
type="http",
197-
category="httplib",
198-
data=data_dict,
199-
hint={"httplib_response": httplib_response},
200-
)
197+
if sys.exc_info()[1] is None:
198+
hub.add_breadcrumb(
199+
type="http",
200+
category="httplib",
201+
data=data_dict,
202+
hint={"httplib_response": httplib_response},
203+
)

0 commit comments

Comments
 (0)