Skip to content

Commit a8aabc2

Browse files
Add agent endpoint to log messages (#3003) (#3007)
* Add agent endpoint to log messages * more test fixes (cherry picked from commit ce486c9) Co-authored-by: Tahir H. Butt <[email protected]>
1 parent 662fcd2 commit a8aabc2

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

ddtrace/internal/writer.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ def __init__(
304304
)
305305
self._log_error_payloads = asbool(os.environ.get("_DD_TRACE_WRITER_LOG_ERROR_PAYLOADS", False))
306306

307+
@property
308+
def _agent_endpoint(self):
309+
return "{}/{}".format(self.agent_url, self._endpoint)
310+
307311
def _metrics_dist(self, name, count=1, tags=None):
308312
self._metrics[name]["count"] += count
309313
if tags:
@@ -354,7 +358,7 @@ def _put(self, data, headers):
354358
log_level = logging.WARNING
355359
else:
356360
log_level = logging.DEBUG
357-
log.log(log_level, "sent %s in %.5fs to %s", _human_size(len(data)), t, self.agent_url)
361+
log.log(log_level, "sent %s in %.5fs to %s", _human_size(len(data)), t, self._agent_endpoint)
358362
return Response.from_http_response(resp)
359363
finally:
360364
conn.close()
@@ -412,7 +416,7 @@ def _send_payload(self, payload, count):
412416
elif response.status >= 400:
413417
msg = "failed to send traces to Datadog Agent at %s: HTTP error status %s, reason %s"
414418
log_args = (
415-
self.agent_url,
419+
self._agent_endpoint,
416420
response.status,
417421
response.reason,
418422
)
@@ -509,7 +513,7 @@ def flush_queue(self, raise_exc=False):
509513
if raise_exc:
510514
e.reraise()
511515
else:
512-
log.error("failed to send traces to Datadog Agent at %s", self.agent_url, exc_info=True)
516+
log.error("failed to send traces to Datadog Agent at %s", self._agent_endpoint, exc_info=True)
513517
finally:
514518
if self._report_metrics and self.dogstatsd:
515519
# Note that we cannot use the batching functionality of dogstatsd because

tests/integration/test_encoding.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def _assert_bad_trace_refused_by_agent(self, mock_log):
7373
calls = [
7474
mock.call(
7575
"failed to send traces to Datadog Agent at %s: HTTP error status %s, reason %s",
76-
agent.get_trace_url(),
76+
"{}/{}/traces".format(agent.get_trace_url(), "v0.4"),
7777
400,
7878
"Bad Request",
7979
)

tests/integration/test_integration.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,11 @@ def test_uds_wrong_socket_path(encoding, monkeypatch):
137137
t.trace("client.testing").finish()
138138
t.shutdown()
139139
calls = [
140-
mock.call("failed to send traces to Datadog Agent at %s", "unix:///tmp/ddagent/nosockethere", exc_info=True)
140+
mock.call(
141+
"failed to send traces to Datadog Agent at %s",
142+
"unix:///tmp/ddagent/nosockethere/{}/traces".format(encoding if encoding else "v0.4"),
143+
exc_info=True,
144+
)
141145
]
142146
log.error.assert_has_calls(calls)
143147

@@ -270,7 +274,13 @@ def test_trace_bad_url(encoding, monkeypatch):
270274
pass
271275
t.shutdown()
272276

273-
calls = [mock.call("failed to send traces to Datadog Agent at %s", "http://bad:1111", exc_info=True)]
277+
calls = [
278+
mock.call(
279+
"failed to send traces to Datadog Agent at %s",
280+
"http://bad:1111/{}/traces".format(encoding if encoding else "v0.4"),
281+
exc_info=True,
282+
)
283+
]
274284
log.error.assert_has_calls(calls)
275285

276286

@@ -386,7 +396,7 @@ def encode_traces(self, traces):
386396
calls = [
387397
mock.call(
388398
"failed to send traces to Datadog Agent at %s: HTTP error status %s, reason %s",
389-
"http://localhost:8126",
399+
"http://localhost:8126/v0.4/traces",
390400
400,
391401
"Bad Request",
392402
)
@@ -419,7 +429,7 @@ def encode_traces(self, traces):
419429
calls = [
420430
mock.call(
421431
"failed to send traces to Datadog Agent at %s: HTTP error status %s, reason %s, payload %s",
422-
"http://localhost:8126",
432+
"http://localhost:8126/v0.4/traces",
423433
400,
424434
"Bad Request",
425435
"6261645f7061796c6f6164",
@@ -463,7 +473,7 @@ def encode_traces(self, traces):
463473
calls = [
464474
mock.call(
465475
"failed to send traces to Datadog Agent at %s: HTTP error status %s, reason %s, payload %s",
466-
"http://localhost:8126",
476+
"http://localhost:8126/v0.4/traces",
467477
400,
468478
"Bad Request",
469479
"bad_payload",
@@ -548,13 +558,15 @@ def test_flush_log(caplog, encoding, monkeypatch):
548558
with mock.patch("ddtrace.internal.writer.log") as log:
549559
writer.write([])
550560
writer.flush_queue(raise_exc=True)
561+
# for latest agent, default to v0.3 since no priority sampler is set
562+
expected_encoding = "v0.3" if AGENT_VERSION == "v5" else (encoding or "v0.3")
551563
calls = [
552564
mock.call(
553565
logging.DEBUG,
554566
"sent %s in %.5fs to %s",
555567
AnyStr(),
556568
AnyFloat(),
557-
writer.agent_url,
569+
"{}/{}/traces".format(writer.agent_url, expected_encoding),
558570
)
559571
]
560572
log.log.assert_has_calls(calls)

0 commit comments

Comments
 (0)