Glossary
Glossary

What Is a Correlation ID?

By Sazabi Team

Last verified on Nov 8, 2026.

A correlation ID is a unique value attached to a request, or to a longer workflow, and written into every log line produced along the way. Given one ID, a log search returns the lines from every service that handled the request, in order. It is one of the simplest ways to follow work across a distributed system.

Common Examples

Several platforms already generate one for you:

HeaderSourceNotes
X-Request-IDHeroku routerGenerated for every request, passed to your app, and shown as request_id in router logs
X-Amzn-Trace-IdAWS Application Load BalancerAdded or updated on each request, and written to access logs when those are enabled
Cf-RayCloudflareA Ray ID that you can add to origin server logs to match a proxied request
traceparentAny W3C Trace Context tracerCarries the trace ID

None of the first three is part of the W3C standard. Each has its own format, and your stack may carry several at once.

Correlation ID vs Trace ID

A correlation ID is a convention you choose. A trace ID is a standard identifier with a defined format: 32 lowercase hex characters, passed in traceparent. The practical difference is what comes with it. A trace ID also identifies spans with timing and parent-child structure, and OpenTelemetry SDKs can inject it into log records for you.

OpenTelemetry's logs specification lists three ways logs can be correlated: by time, by execution context (trace and span IDs), and by the origin of the telemetry. A correlation ID is a hand-built version of the second. If you already run tracing, log the trace ID and treat it as your correlation ID. If you do not, a request ID is a good first step, and it works with any structured logging setup.

How to Implement One

  1. Accept or create at the edge. Take the ID from an incoming header if it is well formed, or generate one. Heroku's rule is a useful model: an inbound value must be 20 to 200 characters from a safe set, and invalid values are replaced.
  2. Store it per request. Use request-scoped storage so every log call sees the ID without passing it around.
  3. Log it on every line, as a field named consistently, such as request_id.
  4. Return it in the response header, so a user or support engineer can quote it.
  5. Forward it on every outgoing call, including queue messages and background jobs.

This Node.js example uses AsyncLocalStorage and was run against three requests: no header, a malformed one, and a valid one. The first two got new UUIDs, and the third kept its ID:

const http = require('node:http')
const { AsyncLocalStorage } = require('node:async_hooks')
const { randomUUID } = require('node:crypto')

const store = new AsyncLocalStorage()
const VALID = /^[A-Za-z0-9+\/=-]{20,200}$/

function log(msg, fields = {}) {
  console.log(JSON.stringify({ msg, request_id: store.getStore(), ...fields }))
}

http
  .createServer((req, res) => {
    const inbound = req.headers['x-request-id']
    const id = inbound && VALID.test(inbound) ? inbound : randomUUID()
    res.setHeader('x-request-id', id)
    store.run(id, () => {
      log('request received', { path: req.url })
      res.end('ok\n')
    })
  })
  .listen(8080)

To follow one request in JSON logs from a file, filter on the field:

jq -c 'select(.request_id == "req-1234567890-abcdefghij")' app.log

Pitfalls

  • Trusting outside values. An ID from the public internet can be forged or stuffed with junk. Validate length and characters before logging it. OpenTelemetry gives similar advice for trace context from external sources.
  • IDs that stop at a boundary. Queues, cron jobs, and webhooks are where the chain usually breaks. Put the ID in the message or job payload.
  • Different names per service. requestId, req_id, and x-correlation-id in different services mean a search misses lines. Pick one field name and use it everywhere. The logging best practices guide covers shared fields.
  • Personal data in the ID. Use a random value, not an email or user ID. OpenTelemetry also warns that baggage values can end up in logs.

See the microservices logging guide for patterns across services.

Correlation IDs in Sazabi

Sazabi, an AI-native observability and security platform, lets you ask about your logs in plain language, and its traces docs describe searching by trace ID to pull spans and correlated log lines together. A request ID or trace ID in your records gives that search something to hold on to. The log search docs cover sazabi logs ask. If you use Cloudflare, see the Cloudflare integration and Cloudflare's documentation on adding Cf-Ray to origin logs. For trace IDs, see the OpenTelemetry traces setup.

Frequently Asked Questions

What is a correlation ID?

A unique value attached to a request or workflow and written into every log line it produces, so you can find all the lines from all services that handled it.

What is the difference between a correlation ID and a trace ID?

A trace ID is standardized by W3C Trace Context and links spans as well as logs. A correlation ID is an application-level convention, often a request ID header, with no required format. If you run tracing, the trace ID can serve as your correlation ID.

Is X-Request-ID a standard?

It is a widely used convention rather than a W3C standard. Platforms such as Heroku generate and forward it, and each defines its own rules for the value.

Where should a correlation ID be generated?

At the first component that sees the request, usually the edge or gateway. Downstream services should reuse an incoming valid ID and generate one only when it is missing.

Sources

  1. The Heroku router generates an X-Request-ID for every request, passes it to the app, and logs it as request_id; callers may supply one of 20 to 200 ASCII characters (letters, digits, + / = -) and invalid values are replaced; it lets you correlate router logs with dyno logs (accessed Nov 8, 2026)
  2. An Application Load Balancer adds or updates the X-Amzn-Trace-Id header, which is logged in access logs, to track requests from clients to targets (accessed Nov 8, 2026)
  3. The Cf-Ray header is a Ray ID sent to upstream origins that can be added to origin logs to match proxied requests to server logs (accessed Nov 8, 2026)
  4. Logs can be correlated by time of execution, by execution context (trace and span IDs), and by origin of the telemetry (Resource) (accessed Nov 8, 2026)
  5. OpenTelemetry SDKs can inject trace ID and span ID into log records; be cautious accepting context from external sources; baggage can end up in logs (accessed Nov 8, 2026)
  6. The traceparent header standardizes the trace ID and parent ID passed between services (accessed Nov 8, 2026)
  7. Sazabi log search answers plain-language questions about stored logs, from the CLI with sazabi logs ask or from a thread (accessed Nov 8, 2026)