Skip to content

Commit ffa75d3

Browse files
authored
fix(debugger): retry writes when any error occurs (#15246)
1 parent 67bfc69 commit ffa75d3

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

ddtrace/debugging/_uploader.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def _write(self, payload: bytes, endpoint: str) -> None:
154154
if not (200 <= resp.status < 300):
155155
log.error("Failed to upload payload to endpoint %s: [%d] %r", endpoint, resp.status, resp.read())
156156
meter.increment("upload.error", tags={"status": str(resp.status)})
157-
if 400 <= resp.status < 500:
157+
if 400 <= resp.status:
158158
msg = "Failed to upload payload"
159159
raise SignalUploaderError(msg)
160160
else:
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
dynamic instrumentation: uploading snapshots now retries on all HTTP error codes.

tests/debugging/test_uploader.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,35 @@ def test_uploader_full_buffer():
7070
# wakeup to mimic next interval
7171
uploader.periodic()
7272
assert uploader.queue.qsize() == 0
73+
74+
75+
def test_uploader_502_error():
76+
"""Test that _write raises SignalUploaderError for 502 Bad Gateway errors."""
77+
from ddtrace.debugging._uploader import SignalUploader
78+
from ddtrace.debugging._uploader import SignalUploaderError
79+
80+
class MockResponse:
81+
status = 502
82+
83+
def read(self):
84+
return b"Bad Gateway"
85+
86+
class MockConnection:
87+
def __enter__(self):
88+
return self
89+
90+
def __exit__(self, *args):
91+
pass
92+
93+
def request(self, *args, **kwargs):
94+
pass
95+
96+
def getresponse(self):
97+
return MockResponse()
98+
99+
uploader = SignalUploader(interval=LONG_INTERVAL)
100+
uploader._connect = lambda: MockConnection()
101+
102+
# Assert that 502 errors raise SignalUploaderError
103+
with pytest.raises(SignalUploaderError):
104+
uploader._write(b'{"test": "data"}', "/debugger/v1/input")

0 commit comments

Comments
 (0)