Correlation ID vs trace ID: which one to use in your logs

Correlation ID vs trace ID: which one to use to link logs and traces? Criteria, OpenTelemetry baggage propagation and DQL queries to check both.
Correlation ID ou trace ID : lequel utiliser dans vos logs

A customer reports a failed order. Support gives you an order number, not a trace ID. Do you need a business correlation ID, or is the OpenTelemetry trace_id enough? The answer depends on what you want to link: a single technical request, or an action that lasts several days.

This article compares the two identifiers, explains what each one guarantees, and proposes a selection rule for an SRE team. It applies to Dynatrace SaaS and to OpenTelemetry in general. For Dynatrace Managed, field names and screens depend on the version, so check your cluster documentation.

For setting up the trace_id in logs, see OpenTelemetry logs and the trace_id in Dynatrace. Here, the focus is on choosing the identifier.

Correlation ID vs trace ID: the difference

The trace_id is a standard. According to the W3C Trace Context specification, it identifies “the whole trace forest”: an entire distributed trace. It is 16 bytes long, written as 32 lowercase hexadecimal characters, and the all-zero value is invalid. The specification asks for it to be globally unique and prefers a randomly generated value.

The correlation ID has no equivalent normative definition. It is a team convention: an identifier you choose (often the X-Request-ID header or an order number) and copy into logs, messages and tickets. Its format, lifetime and propagation depend on your code. That lack of a standard is its weakness, but also its strength: it can survive where a trace stops.

Example traceparent header from the W3C Trace Context specification, split into version, trace-id, parent-id and trace-flags
Criterion trace_id Correlation ID
Origin Generated by the SDK or agent at the start of the request Chosen by the application or read from a header
Format 32 hexadecimal characters (W3C) Free
Scope One distributed request A business action, sometimes several requests
Propagation traceparent header, handled by instrumentation Your responsibility (header, message, baggage)
Readable by support Rarely Yes, if it is a number the customer knows
Sampling May vanish if the trace is not kept Stays in the logs

Duration is the deciding factor. A trace covers one request. A payment confirmed after an asynchronous call, a confirmation e-mail and a nightly retry covers several. The trace_id changes at every step that starts a new trace (batch job, queue consumer). The correlation ID stays the same if you carry it along.

How Dynatrace uses the trace ID

On the OpenTelemetry side, the logs data model defines the optional fields TraceId, SpanId and TraceFlags. A log emitted inside an active span receives them from the SDK. The specification adds that if SpanId is present, TraceId should be present too.

The Dynatrace documentation on OTLP log ingestion states that TraceID and SpanID are mapped to the trace_id and span_id fields, converted to hexadecimal. For logs enriched by OneAgent, the documentation names dt.trace_id and dt.span_id instead. Two names therefore exist depending on the source: inspect a real record before writing queries. See also Distributed traces and PurePath for reading a trace.

Example JSON log carrying both an OpenTelemetry trace_id and a business correlation_id attribute

Propagating a correlation ID with baggage

If you keep a correlation ID, do not copy it by hand into each service. OpenTelemetry provides baggage, defined as contextual information passed between signals, which travels with the context in HTTP headers.

  1. Create the identifier at the entry point. Read the incoming header or generate it at the system boundary.
  2. Put it in baggage.
    from opentelemetry import baggage, context
    
    ctx = baggage.set_baggage("correlation.id", "cmd-A-1042")
    token = context.attach(ctx)
  3. Copy it explicitly into an attribute. The documentation states that baggage is “a separate key-value store” unassociated with attributes: you must add it to spans and logs yourself, or use a baggage processor when your language offers one.
    span.set_attribute("correlation.id", baggage.get_baggage("correlation.id"))
  4. Write it in the logs under a stable key, next to the trace_id.

Warning: the OpenTelemetry documentation notes that baggage can be exposed to third parties, is visible in network traffic, and has no integrity check. Never put personal data or secrets in it, and do not trust a value received from an external client.

How to check that it works

In a Dynatrace SaaS Notebook, first look up the logs of a business action, then go back to their traces. Field names may vary: check with fetch logs | limit 1.

fetch logs, from: now() - 2h
| filter correlation.id == "cmd-A-1042"
| summarize traces = countDistinct(trace_id), logs = count()

If traces is greater than 1, the action crosses several traces: this is the case where the correlation ID gives what the trace_id cannot. For a specific trace:

fetch logs, from: now() - 2h
| filter trace_id == "<trace_id>"
| fields timestamp, loglevel, content
Two DQL queries: counting distinct trace_id values for a correlation ID, then filtering logs on a trace_id

A selection rule for an SRE team

  • Technical diagnosis of a slow or failing request: the trace_id. It is standard, automatic and links logs, spans and metrics.
  • Customer support and business journeys: the correlation ID, because a human can supply it and find it again.
  • Asynchronous processing: both. The correlation ID links the traces, the trace_id links each trace to its logs.
  • Uninstrumented sources (third-party system, flat file): the correlation ID, since no trace_id exists.

For reliability goals, combining them reduces MTTR: support starts from a readable number, the on-call engineer switches to the trace. The choice also affects volume. Tail sampling can drop traces, but not the logs that carry the correlation ID.

Best practices

  • One field name for the correlation ID across the organisation, documented.
  • No personal data as an identifier (no e-mail address or card number).
  • Do not replace the trace_id: do not invent a second trace format, use traceparent.
  • Cardinality: avoid using the correlation ID as a metric dimension. It suits logs and span attributes.
  • Retention: make sure logs live as long as your customers’ claim period.

Frequently asked questions

Can the trace ID be used as a correlation ID?

For a synchronous request, yes. As soon as asynchronous processing opens a new trace, the trace_id is no longer the same, and the customer rarely knows it.

Does a correlation ID replace the trace_id in Dynatrace?

No. Dynatrace links logs and traces through the trace fields (trace_id, span_id). The correlation ID remains an attribute you filter on in DQL.

Is baggage safe for carrying an identifier?

Only for an identifier with no sensitive value. According to the OpenTelemetry documentation, it is visible in traffic and has no integrity check.

Conclusion

The trace ID serves the engineer, the correlation ID serves the business: keep both, each in its own role. Start by checking that your logs already carry the trace_id, then add a correlation ID where an action outlasts a single request. To place these signals in context, read the difference between observability and monitoring.

span.observer is an independent community blog, not affiliated with Dynatrace LLC. Dynatrace is a trademark of Dynatrace LLC. Fields and screens change: check them in the official documentation.

Total
0
Shares
Leave a Reply

Your email address will not be published. Required fields are marked *

Previous Post
ActiveGate Kubernetes not ready : readiness 503 et diagnostic kubectl

ActiveGate pod not ready: readiness 503 and kubectl diagnosis

Next Post
Métriques outils MCP : compteurs, histogrammes et taux d'échec

MCP tool metrics: counters, histograms and failure rate

Related Posts