---
title: Correlate Logs and Traces
description: Connect your logs and traces to correlate them in Datadog.
breadcrumbs: >-
  Docs > APM > Correlate APM Data with Other Telemetry > Correlate Logs and
  Traces
---

# Correlate Logs and Traces

{% image
   source="https://docs.dd-static.net/images/tracing/connect_logs_and_traces/logs-trace-correlation.3fa4d93210758779eeb24beaf35e5da4.png?auto=format&fit=max&w=850 1x, https://docs.dd-static.net/images/tracing/connect_logs_and_traces/logs-trace-correlation.3fa4d93210758779eeb24beaf35e5da4.png?auto=format&fit=max&w=850&dpr=2 2x"
   alt="Logs in Traces" /%}

The correlation between Datadog APM and Datadog Log Management is improved by the injection of trace IDs, span IDs, `env`, `service`, and `version` as attributes in your logs. With these fields you can find the exact logs associated with a specific service and version, or all logs correlated to an observed [trace](https://docs.datadoghq.com/tracing/glossary.md#trace).

It is recommended to configure your application's tracer with `DD_ENV`, `DD_SERVICE`, and `DD_VERSION`. This will provide the best experience for adding `env`, `service`, and `version`. See the [unified service tagging](https://docs.datadoghq.com/getting_started/tagging/unified_service_tagging.md) documentation for more details.

Before correlating traces with logs, ensure your logs are either sent as JSON, or [parsed by the proper language level log processor](https://docs.datadoghq.com/agent/logs.md#enabling-log-collection-from-integrations). Your language level logs *must* be turned into Datadog attributes in order for traces and logs correlation to work.

**Note**: Traces and logs are sampled independently. Even after correlation is configured, a log may contain a trace ID that refers to a trace that was not ingested or not retained due to [trace sampling](https://docs.datadoghq.com/tracing/trace_pipeline/ingestion_controls.md). This does not indicate a configuration error. For more information, see [Log has a trace ID but the associated trace is missing](https://docs.datadoghq.com/logs/troubleshooting.md#log-has-a-trace-id-but-the-associated-trace-is-missing).

To learn more about automatically or manually connecting your logs to your traces, select your language below:

- [Java](https://docs.datadoghq.com/tracing/other_telemetry/connect_logs_and_traces/java/)
- [Python](https://docs.datadoghq.com/tracing/other_telemetry/connect_logs_and_traces/python/)
- [go](https://docs.datadoghq.com/tracing/other_telemetry/connect_logs_and_traces/go/)
- [Ruby](https://docs.datadoghq.com/tracing/other_telemetry/connect_logs_and_traces/ruby/)
- [Node.js](https://docs.datadoghq.com/tracing/other_telemetry/connect_logs_and_traces/nodejs/)
- [.Net](https://docs.datadoghq.com/tracing/other_telemetry/connect_logs_and_traces/dotnet/)
- [PHP](https://docs.datadoghq.com/tracing/other_telemetry/connect_logs_and_traces/php/)
- [OpenTelemetry](https://docs.datadoghq.com/tracing/other_telemetry/connect_logs_and_traces/opentelemetry/)
