diff --git a/ddtrace/debugging/_uploader.py b/ddtrace/debugging/_uploader.py index 49ca7ac60e9..e2e8683af44 100644 --- a/ddtrace/debugging/_uploader.py +++ b/ddtrace/debugging/_uploader.py @@ -154,7 +154,7 @@ def _write(self, payload: bytes, endpoint: str) -> None: if not (200 <= resp.status < 300): log.error("Failed to upload payload to endpoint %s: [%d] %r", endpoint, resp.status, resp.read()) meter.increment("upload.error", tags={"status": str(resp.status)}) - if 400 <= resp.status < 500: + if 400 <= resp.status: msg = "Failed to upload payload" raise SignalUploaderError(msg) else: diff --git a/releasenotes/notes/fix-debugger-write-retries-e097ff1f0836531b.yaml b/releasenotes/notes/fix-debugger-write-retries-e097ff1f0836531b.yaml new file mode 100644 index 00000000000..ef7ae7191f1 --- /dev/null +++ b/releasenotes/notes/fix-debugger-write-retries-e097ff1f0836531b.yaml @@ -0,0 +1,4 @@ +--- +fixes: + - | + dynamic instrumentation: uploading snapshots now retries on all HTTP error codes. diff --git a/tests/debugging/test_uploader.py b/tests/debugging/test_uploader.py index b99d7d4a698..f8d0cc8154c 100644 --- a/tests/debugging/test_uploader.py +++ b/tests/debugging/test_uploader.py @@ -70,3 +70,35 @@ def test_uploader_full_buffer(): # wakeup to mimic next interval uploader.periodic() assert uploader.queue.qsize() == 0 + + +def test_uploader_502_error(): + """Test that _write raises SignalUploaderError for 502 Bad Gateway errors.""" + from ddtrace.debugging._uploader import SignalUploader + from ddtrace.debugging._uploader import SignalUploaderError + + class MockResponse: + status = 502 + + def read(self): + return b"Bad Gateway" + + class MockConnection: + def __enter__(self): + return self + + def __exit__(self, *args): + pass + + def request(self, *args, **kwargs): + pass + + def getresponse(self): + return MockResponse() + + uploader = SignalUploader(interval=LONG_INTERVAL) + uploader._connect = lambda: MockConnection() + + # Assert that 502 errors raise SignalUploaderError + with pytest.raises(SignalUploaderError): + uploader._write(b'{"test": "data"}', "/debugger/v1/input")