Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4791 pages
Servers, nginx and Docker

Python app logs dropped traces because the Datadog Agent cannot be reached

Your error

failed to send, dropping 1 traces to intake at http://localhost:8126/v0.4/traces after 3 retries2 more lines it can show

Fix it fast

Most common cause, 1 of 4

The app runs in a container but still sends to localhost

Give the tracer the Agent's address.

Fix
# Docker: same network, Agent container named datadog-agent
docker run -d --name app --network my-net -e DD_AGENT_HOST=datadog-agent company/app:latest
# Kubernetes Deployment, container env:
#   - name: DD_AGENT_HOST
#     valueFrom:
#       fieldRef:
#         fieldPath: status.hostIP
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

ddtrace 4.x logs "failed to send, dropping N traces to intake at ... after 3 retries" when the Python tracer cannot reach the Datadog Agent's trace receiver, port 8126 by default. In containers the app often still targets localhost, or the Agent refuses traffic from other containers. Set DD_AGENT_HOST, set DD_APM_NON_LOCAL_TRAFFIC=true on the Agent, and confirm APM runs.

  • Applies to ddtrace 4.17 (Python), Datadog Agent 7.85, Docker, Kubernetes and host installs
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Run both lines from inside the application container or host. ddtrace-run --info shows the address the tracer writes to and whether it got an answer; the curl shows whether anything listens there at all.

Run this first
ddtrace-run --info | grep -E "Writing traces to|Agent error"
curl -sS "http://${DD_AGENT_HOST:-localhost}:8126/info"

Then find the line you see in this list and open its fix:

  1. 1The app runs in a container but still sends to localhost--info prints Writing traces to: http://localhost:8126 inside a container, while the Agent runs in a different container or on the node
  2. 2The Agent container does not accept traces from other containersDD_AGENT_HOST is right, yet curl to that host on port 8126 fails when run from the app container
  3. 3The Agent is stopped or its APM part is switched offagent status shows an APM Agent section with Status: Not running or unreachable on localhost:8126
  4. 4There is no Agent on purpose: local runs, tests or CIThe log appears on a laptop or in a CI job where no Datadog Agent was ever installed

What does the error look like?

  • failed to send, dropping 1 traces to intake at http://localhost:8126/v0.4/traces after 3 retries
  • DATADOG TRACER DIAGNOSTIC - Agent not reachable at http://localhost:8126
  • Status: Not running or unreachable on localhost:8126.

Cause 1 of 4

The app runs in a container but still sends to localhost

You see--info prints Writing traces to: http://localhost:8126 inside a container, while the Agent runs in a different container or on the node

Check

Dropped traces while the Agent is healthy somewhere else often mean the tracer kept its default target. Datadog's connection guide says localhost or 127.0.0.1 is often wrong in containerized setups (Fargate is the exception), because the Agent lives at another address. ddtrace falls back to localhost when DD_AGENT_HOST, DD_TRACE_AGENT_HOSTNAME and DD_TRACE_AGENT_URL are all unset and no socket exists.

Check
env | grep -E '^DD_(AGENT_HOST|TRACE_AGENT_URL|TRACE_AGENT_PORT)='

Fix

Give the tracer the Agent's address. With Docker, attach the app and the Agent to a shared user-defined network, then use the Agent's container name as the host. On Kubernetes, pass the node IP from the downward API. On ECS or EKS on Fargate, leave DD_AGENT_HOST unset.

Fix
# Docker: same network, Agent container named datadog-agent
docker run -d --name app --network my-net -e DD_AGENT_HOST=datadog-agent company/app:latest
# Kubernetes Deployment, container env:
#   - name: DD_AGENT_HOST
#     valueFrom:
#       fieldRef:
#         fieldPath: status.hostIP

Verify

--info now names the Agent's host and its Agent error line reads None.

Verify
ddtrace-run --info | grep -E "Writing traces to|Agent error"

Confirmed by docs.datadoghq.com

Did this fix it?

Cause 2 of 4

The Agent container does not accept traces from other containers

You seeDD_AGENT_HOST is right, yet curl to that host on port 8126 fails when run from the app container

Check

When the tracer has the correct host but still drops payloads, look at the Agent side. DD_APM_NON_LOCAL_TRAFFIC defaults to false, so a containerized Agent only takes local traces; Datadog asks you to set it to true when tracing from other containers. For apps on the Docker host, port 8126/tcp also has to be published.

Check
curl -X GET http://datadog-agent:8126/info

Fix

Recreate the Agent container with non-local APM traffic allowed, on the same network as the app. Publish the port only if host processes send traces too.

Fix
docker run -d --name datadog-agent --network my-net \
  -e DD_API_KEY=<DATADOG_API_KEY> \
  -e DD_APM_ENABLED=true \
  -e DD_APM_NON_LOCAL_TRAFFIC=true \
  registry.datadoghq.com/agent:latest

Verify

From the app container, curl to datadog-agent:8126/info returns a JSON answer instead of a connection error.

Verify
curl -sS http://datadog-agent:8126/info

Confirmed by docs.datadoghq.com

Did this fix it?

Cause 3 of 4

The Agent is stopped or its APM part is switched off

You seeagent status shows an APM Agent section with Status: Not running or unreachable on localhost:8126

Check

A host install where the app and Agent share a machine should send to localhost:8126, so a failure there points at the Agent itself. Its status output reports whether the trace receiver is up. Since Agent 7.80 on Linux, the trace-agent starts only after the first trace arrives, so that status alone can look like a failure on an idle host.

Check
sudo datadog-agent status
# Docker: sudo docker exec -it <CONTAINER_NAME> agent status

Fix

Start the Agent if it is down, and look for another program holding port 8126. If APM was turned off in a container Agent, run it again with DD_APM_ENABLED=true and the port published for host processes. If you want status to report the receiver before the first trace on Linux, set DD_APM_SOCKET_ACTIVATION_ENABLED=false.

Fix
docker run -d -p 127.0.0.1:8126:8126/tcp \
  -e DD_API_KEY=<DATADOG_API_KEY> \
  -e DD_APM_ENABLED=true \
  registry.datadoghq.com/agent:latest

Verify

Once the app has sent some traffic, the APM Agent section reads Status: Running and lists its Receiver address.

Verify
sudo datadog-agent status | grep -A3 'APM Agent'

Confirmed by docs.datadoghq.com

Did this fix it?

Cause 4 of 4

There is no Agent on purpose: local runs, tests or CI

You seeThe log appears on a laptop or in a CI job where no Datadog Agent was ever installed

Check

With no Agent listening anywhere, every flush ends in the same dropped-trace error, so test runs and local shells fill up with it. The Python configuration reference documents DD_TRACE_ENABLED: set to false, instrumentation still runs but no trace data is sent.

Check
echo "DD_TRACE_ENABLED=${DD_TRACE_ENABLED:-unset}"

Fix

Turn sending off for those environments only, through the environment rather than code, so production keeps tracing.

Fix
export DD_TRACE_ENABLED=false

Verify

The test or local run finishes with no failed to send lines in its output.

Verify
DD_TRACE_ENABLED=false ddtrace-run python app.py

Confirmed by docs.datadoghq.com

Did this fix it?

How do I stop it coming back?

  • Set DD_AGENT_HOST (or DD_TRACE_AGENT_URL) in the same manifest or compose file that defines the app, never only on one engineer's machine.
  • Add ddtrace-run --info to the container's start-up smoke check and fail the deploy when its Agent error line is not None.
  • Keep DD_TRACE_ENABLED=false in the test and CI environment files so missing Agents never fill build logs.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine on the same stack: Dispatch Pro, TaxiDex, stegnor.com.

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.