Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions ddtrace/internal/writer.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ def __init__(
)
self._log_error_payloads = asbool(os.environ.get("_DD_TRACE_WRITER_LOG_ERROR_PAYLOADS", False))

@property
def _agent_endpoint(self):
return "{}/{}".format(self.agent_url, self._endpoint)

def _metrics_dist(self, name, count=1, tags=None):
self._metrics[name]["count"] += count
if tags:
Expand Down Expand Up @@ -358,7 +362,7 @@ def _put(self, data, headers):
log_level = logging.WARNING
else:
log_level = logging.DEBUG
log.log(log_level, "sent %s in %.5fs to %s", _human_size(len(data)), t, self.agent_url)
log.log(log_level, "sent %s in %.5fs to %s", _human_size(len(data)), t, self._agent_endpoint)
return Response.from_http_response(resp)
finally:
conn.close()
Expand Down Expand Up @@ -416,7 +420,7 @@ def _send_payload(self, payload, count):
elif response.status >= 400:
msg = "failed to send traces to Datadog Agent at %s: HTTP error status %s, reason %s"
log_args = (
self.agent_url,
self._agent_endpoint,
response.status,
response.reason,
)
Expand Down Expand Up @@ -513,7 +517,7 @@ def flush_queue(self, raise_exc=False):
if raise_exc:
e.reraise()
else:
log.error("failed to send traces to Datadog Agent at %s", self.agent_url, exc_info=True)
log.error("failed to send traces to Datadog Agent at %s", self._agent_endpoint, exc_info=True)
finally:
if self._report_metrics and self.dogstatsd:
# Note that we cannot use the batching functionality of dogstatsd because
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/test_encoding.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def _assert_bad_trace_refused_by_agent(self, mock_log):
calls = [
mock.call(
"failed to send traces to Datadog Agent at %s: HTTP error status %s, reason %s",
agent.get_trace_url(),
"{}/{}/traces".format(agent.get_trace_url(), "v0.4"),
400,
"Bad Request",
)
Expand Down
24 changes: 18 additions & 6 deletions tests/integration/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ def test_uds_wrong_socket_path(encoding, monkeypatch):
t.trace("client.testing").finish()
t.shutdown()
calls = [
mock.call("failed to send traces to Datadog Agent at %s", "unix:///tmp/ddagent/nosockethere", exc_info=True)
mock.call(
"failed to send traces to Datadog Agent at %s",
"unix:///tmp/ddagent/nosockethere/{}/traces".format(encoding if encoding else "v0.4"),
exc_info=True,
)
]
log.error.assert_has_calls(calls)

Expand Down Expand Up @@ -270,7 +274,13 @@ def test_trace_bad_url(encoding, monkeypatch):
pass
t.shutdown()

calls = [mock.call("failed to send traces to Datadog Agent at %s", "http://bad:1111", exc_info=True)]
calls = [
mock.call(
"failed to send traces to Datadog Agent at %s",
"http://bad:1111/{}/traces".format(encoding if encoding else "v0.4"),
exc_info=True,
)
]
log.error.assert_has_calls(calls)


Expand Down Expand Up @@ -386,7 +396,7 @@ def encode_traces(self, traces):
calls = [
mock.call(
"failed to send traces to Datadog Agent at %s: HTTP error status %s, reason %s",
"http://localhost:8126",
"http://localhost:8126/v0.4/traces",
400,
"Bad Request",
)
Expand Down Expand Up @@ -419,7 +429,7 @@ def encode_traces(self, traces):
calls = [
mock.call(
"failed to send traces to Datadog Agent at %s: HTTP error status %s, reason %s, payload %s",
"http://localhost:8126",
"http://localhost:8126/v0.4/traces",
400,
"Bad Request",
"6261645f7061796c6f6164",
Expand Down Expand Up @@ -463,7 +473,7 @@ def encode_traces(self, traces):
calls = [
mock.call(
"failed to send traces to Datadog Agent at %s: HTTP error status %s, reason %s, payload %s",
"http://localhost:8126",
"http://localhost:8126/v0.4/traces",
400,
"Bad Request",
"bad_payload",
Expand Down Expand Up @@ -548,13 +558,15 @@ def test_flush_log(caplog, encoding, monkeypatch):
with mock.patch("ddtrace.internal.writer.log") as log:
writer.write([])
writer.flush_queue(raise_exc=True)
# for latest agent, default to v0.3 since no priority sampler is set
expected_encoding = "v0.3" if AGENT_VERSION == "v5" else (encoding or "v0.3")
calls = [
mock.call(
logging.DEBUG,
"sent %s in %.5fs to %s",
AnyStr(),
AnyFloat(),
writer.agent_url,
"{}/{}/traces".format(writer.agent_url, expected_encoding),
)
]
log.log.assert_has_calls(calls)
Expand Down