Skip to content

Commit ae548de

Browse files
github-actions[bot]P403n1x87emmettbutler
authored
fix(profiling): handle known HTTP request errors [backport 1.14] (#6327)
Backport e097222 from #6249 to 1.14. After the removal of the tenacity dependency, some known HTTP request exceptions are no longer handled as expected and the user is asked to report an issue to the project. This change ensures that we have a similar behaviour in place whereby known issues are handled as before. ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed. If no release note is required, add label `changelog/no-changelog`. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Title is accurate. - [x] No unnecessary changes are introduced. - [x] Description motivates each change. - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [x] Testing strategy adequately addresses listed risk(s). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] Release note makes sense to a user of the library. - [x] Reviewer has explicitly acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment. - [x] Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) Co-authored-by: Gabriele N. Tornetta <[email protected]> Co-authored-by: Emmett Butler <[email protected]>
1 parent c789aaa commit ae548de

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

ddtrace/profiling/exporter/http.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import attr
1414
import six
15+
from six.moves import http_client
1516

1617
import ddtrace
1718
from ddtrace.ext.git import COMMIT_SHA
@@ -233,6 +234,8 @@ def _upload(self, client, path, body, headers):
233234
client.request("POST", path, body=body, headers=headers)
234235
response = client.getresponse()
235236
response.read() # reading is mandatory
237+
except (http_client.HTTPException, EnvironmentError) as e:
238+
raise exporter.ExportError("HTTP upload request failed: %s" % e)
236239
finally:
237240
client.close()
238241

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
fixes:
3+
- |
4+
profiling: Fixed a regression whereby the profile exporter would not handle
5+
known request errors and asks the user to report an issue instead.

tests/profiling/exporter/test_http.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,13 @@
33
import email.parser
44
import json
55
import platform
6-
import socket
76
import sys
87
import threading
98
import time
109

1110
import pytest
1211
import six
1312
from six.moves import BaseHTTPServer
14-
from six.moves import http_client
1513

1614
import ddtrace
1715
from ddtrace.internal import compat
@@ -216,7 +214,7 @@ def test_export_server_down():
216214
max_retry_delay=2,
217215
endpoint_call_counter_span_processor=_get_span_processor(),
218216
)
219-
with pytest.raises(EnvironmentError):
217+
with pytest.raises(exporter.ExportError):
220218
exp.export(test_pprof.TEST_EVENTS, 0, 1)
221219

222220

@@ -228,7 +226,7 @@ def test_export_timeout(endpoint_test_timeout_server):
228226
max_retry_delay=2,
229227
endpoint_call_counter_span_processor=_get_span_processor(),
230228
)
231-
with pytest.raises((TimeoutError, socket.timeout) if six.PY3 else socket.error):
229+
with pytest.raises(exporter.ExportError):
232230
exp.export(test_pprof.TEST_EVENTS, 0, 1)
233231

234232

@@ -240,7 +238,7 @@ def test_export_reset(endpoint_test_reset_server):
240238
max_retry_delay=2,
241239
endpoint_call_counter_span_processor=_get_span_processor(),
242240
)
243-
with pytest.raises(ConnectionResetError if six.PY3 else http_client.BadStatusLine):
241+
with pytest.raises(exporter.ExportError):
244242
exp.export(test_pprof.TEST_EVENTS, 0, 1)
245243

246244

0 commit comments

Comments
 (0)