Correlating logs with traces in OpenTelemetry

Correlating logs with traces in OpenTelemetry means putting trace and span IDs on each log record, so teams can move from a failing request to its logs. This page covers logging bridges, SDK export versus file collection, and the language checks to make first.

On this page

How correlating logs with traces in OpenTelemetry links errors to requests

During an incident, application logs often cannot be tied to the trace of the request that produced them, so engineers search by timestamp and guess which lines belong together. Correlation here means writing the trace ID and span ID onto each log record, so a log line can be matched to the exact request and operation that emitted it. Teams need this when they already have logs, want to move from tracing to log lines in one step, and cannot rewrite every logging call to add IDs by hand.

OpenTelemetry is a framework for generating, exporting and collecting telemetry, not an observability backend. Correlated logs still need a separate store and viewer, so the decision that matters is which log backend will hold the records and whether it can search on the trace and span fields. The Collector is the common path for this: it can receive logs from applications and host collection, process them, and export them to that backend, as described in the OpenTelemetry Collector documentation. Confirm with your backend team that it accepts the OpenTelemetry log fields you plan to send.

Before choosing a method, check language support for the logs signal in each runtime you run, using the OpenTelemetry status page. Trace APIs and SDKs are stable in most languages, but log SDK maturity varies and several languages are still in development, so the logging bridge you need may not be stable everywhere. Plan the investigation workflow with the people who will use it: which fields must appear on every line, how existing log formats will be preserved, and how the team will test that a sample error opens the matching trace.

Checking log SDK maturity before you choose a correlation path

Trace APIs and SDKs are stable in most languages, but log SDK maturity varies more, and several languages are still in development. Before you pick a correlation path, run the same short checks for every language and runtime in your estate, because the answer for logs can differ from the answer for traces.

Log SDK status for your language

Look up your language on the OpenTelemetry status page and find its log signal entry. A stable log SDK lets you export logs directly from the application over OTLP, while an in-development entry means you should plan for file collection or a bridge with known gaps. Record the status for each runtime version you run, not only the language name, and confirm it against the current page before you commit.

OpenTelemetry status page

Bridge support for your logging library

Applications rarely log through the OpenTelemetry API directly. They use a library such as the standard logging facility, Log4j, Logback, Serilog, Winston or Zap, so you need a bridge or appender that copies the active trace and span IDs into each record. Confirm that a bridge exists for your exact library and version, and test that it attaches IDs inside asynchronous code and background jobs.

Collector receiver stability

If logs leave the application as files and a Collector reads them, check the stability level of the file log receiver and any parser or processor you plan to use. Core Collector components have mixed stability levels, and each component's README states its level. Pin the Collector version you test against, since component stability and options can change between releases.

Whether framework logs are already JSON

Find out whether your framework writes structured JSON or plain text lines. If the output is plain text, correlation depends on a parser that extracts the trace ID from each line, which is fragile when messages change. If the framework already emits JSON with fields you control, a collector can read the IDs reliably. Sample real log lines from production-like traffic, including error paths, before you decide.

Ownership of the logging configuration

Identify which team controls the logging configuration in each service, such as a shared logging library, a base container image or a per-service file. Changes to log format or appender settings often need the owning team's review, so a correlation rollout that touches those files will take longer than one that only adds an instrumentation package. Agree on that owner before you plan the rollout.

How logging bridges inject trace context into existing log lines

A logging bridge is the piece that connects an existing logging library to the OpenTelemetry log pipeline, and its main job for correlation is to read the active span context at the moment a log call is made. When the bridge finds a valid span in the current execution context, it copies the trace ID, span ID and trace flags onto the log record. Your application code does not pass these values in by hand. The bridge also hands the finished record to the OpenTelemetry log SDK, which applies resource attributes and sends it to an exporter or to the Collector. The exact bridge for each library, such as the appender or handler that ships with a given logging framework, varies by language and version, so confirm the bridge name, its supported versions and whether it is marked stable for your language in the OpenTelemetry status page before you commit to a design.

Bridges generally come in two forms, and the choice shapes how much existing code changes. In the first, the bridge is added as an extra destination, so the library keeps writing its usual output to the console or file and the OpenTelemetry record is sent in parallel. This is the lower-risk path for a brownfield service because existing log formats, parsers and alerts continue to work. In the second, the bridge replaces the library's output format, which gives you one structured stream but forces a review of every consumer that reads the old lines. Decide which path applies per service, and test the replacement path against the log parsing rules your security operations and support teams already depend on. Keep the trace fields visible in the text output too if people will read logs directly during an incident.

The most common reason IDs are missing is that the log call runs outside an active span. Context is held per request or per thread, so a log line written in a startup routine, a background job that was never wrapped in a span, or a callback that lost its context will carry empty trace fields, and the bridge will not invent them. Check this before blaming the bridge: reproduce a request, confirm that the relevant handler or job starts a span, and confirm that context propagates across any thread pool, async task or queue consumer your code uses. Ask your instrumentation team which of your frameworks restore context automatically and which need explicit handling, because that list drives how much manual work the rollout needs.

SDK log export or file collection: which fits your estate

With SDK export, the application's logging bridge sends log records directly to a Collector over OTLP, usually through the OpenTelemetry log SDK. The application carries a new dependency and exporter configuration, and the log pipeline becomes part of the process. Trace context is attached at emit time, so when a log record is written inside an active span, the SDK can record the trace ID and span ID on the record without any parsing step. Before you commit, confirm that the log SDK for your language is stable, because log SDK maturity varies across languages and some are still in development.

  • Application change: Add the logging bridge for your framework, the OTLP log exporter, and endpoint settings. Code or deployment configuration changes are needed in every service.
  • Trace IDs: Taken from the active span context at the moment of the log call, which keeps correlation accurate under async work when context propagation is set up correctly.
  • Failure behavior: Test what happens when the Collector is unreachable. Confirm whether the exporter retries, how many records it holds in memory, and whether records are dropped on process exit.
  • Backpressure: Check that a slow Collector cannot stall request threads. Confirm the exporter's queue limits and drop behavior under load.
  • Fit: Suits greenfield or well-maintained services where the application team owns logging and the log SDK is stable in its language.

Before rollout, ask the platform team to run a Collector outage test in staging and record what is lost.

Configuration options and when each one fits

This table compares the main ways to get trace and span IDs onto application logs: exporting logs through the SDK, bridging an existing logging library, collecting log files with the Collector, formatting JSON with trace fields, and reshaping attributes in the Collector. Read each row for the fit, the main trade-off, and what to confirm in the component README before committing to a design.

OptionFitMain trade-offConfirm in the component README
SDK log exporter with OTLPServices where the application can send log records directly to a Collector and the team wants trace context attached by the SDKLog SDK maturity varies by language, so the exporter may not be ready for every runtime in useSignal stability for logs in your language, and whether trace context is attached automatically
Bridge an existing logging libraryApplications already logging through a established library that should keep its call sites and forward records to OpenTelemetryEach library needs its own bridge or appender, and bridge behavior can differ from the library's own output formatWhich logging libraries the bridge supports, and how it maps levels, attributes and exceptions
File collection with the CollectorTeams that cannot change application code or need one collection path for hosts, containers and legacy servicesParsing and correlating depends on log format; trace IDs must already be written into each line before collectionReceiver options for file paths, parsing operators, and how trace fields are extracted from the log body
JSON formatting with trace fieldsApplications that write structured logs to stdout or files and need trace and span IDs in a predictable field layoutTrace IDs appear only when a trace context is active, so logs outside spans lack correlation fieldsWhich field names the logging framework expects and whether the SDK or instrumentation injects them
Collector processors that add or move attributesPipelines that receive logs from several sources and need consistent attribute names or resource fields before exportProcessing adds CPU cost and can drop or overwrite fields if rules are written too broadlyProcessor configuration keys, stability level, and the order in which processors run in your pipeline
Redaction in the pipelineLogs that may carry sensitive values next to trace IDs and must be scrubbed before they leave your networkRedaction rules need upkeep as log content changes, and over-redaction can remove fields needed for correlationWhich attributes the redaction processor can match and whether it preserves trace and span fields

How trace context reaches the log backend

The path starts with a request that creates a span in the application. The logging library, through its OpenTelemetry bridge, stamps each log record with the active trace and span IDs. Logs then leave by one of two routes: the SDK exports them over OTLP, or the application writes them to a file that a Collector file receiver reads. Both routes meet in the Collector, which sits inside the trust boundary, so check that its endpoints are authenticated and that logs and traces reach separate backends with the same IDs.

Trace IDs travel from the active span into log records along two export paths.

Setting up trace-correlated logs step by step

This sequence takes an application from existing unstructured logs to logs that carry trace and span IDs, so each log line can be matched to the request that produced it. Each step ends with a check that tells you whether the next one can start.

  1. Inventory logging libraries and languages

    List every service, the language and runtime it uses, and the logging library it writes with, such as Log4j, Logback, the standard logging module in Python, or Winston in Node.js. Record where each service sends its logs today, whether that is stdout, a file, or an existing agent. Ask the owning teams to confirm the versions in use, because bridge support depends on them. The step is done when every service has one row with language, runtime, logging library, version and log destination.

  2. Confirm log SDK status for each language

    Check the OpenTelemetry status page for the log signal in each language on your inventory, and read the stability notes in the relevant SDK documentation. Trace APIs and SDKs are stable in most languages, but log SDK maturity varies and some languages are still in development. Mark each service as SDK log export supported, bridge only, or file collection required. The step is done when every service has one of those three labels and the team that owns it has seen the label.

  3. Enable tracing first and confirm spans exist

    Instrument the services with the OpenTelemetry SDK or agent for traces before touching logging. Set the service name through resource attributes, send spans to a Collector, and make a test request through each service. Open your tracing backend and confirm that a span appears for that request with the expected service name and duration. The step is done when a request from each service produces a visible trace, because correlation cannot work without a span to attach to.

  4. Add the logging bridge or JSON trace fields

    For services with a supported bridge, install the OpenTelemetry appender or bridge for your logging library so the active trace context is attached to each record. Where no bridge exists, configure the logging library to write trace_id and span_id as fields in structured JSON, reading them from the current span context in your code. Restart the service and trigger a request inside a span. The step is done when a local log line for that request shows a trace ID and span ID that match the span you saw in the previous step.

  5. Choose SDK export or file collection

    Decide, per service, whether logs leave the process through the SDK log exporter or are written to files that the Collector reads. SDK export keeps the trace context attached without parsing, but depends on the log SDK maturity you confirmed earlier. File collection suits services with stable log files, existing retention rules, or languages where the log signal is not yet stable, but it requires parsing so the trace fields are extracted correctly. Document the choice per service with the owner and the reason. The step is done when each service has one recorded export method and the owning team has agreed to it.

  6. Configure the Collector pipeline

    Add log receivers and pipelines to the Collector configuration. For file collection, use a file log receiver with a parser that extracts the trace and span fields from your JSON format. For SDK export, add an OTLP receiver for logs. Both paths should run through the same processors and exporter to your log backend. The Collector configuration file is usually named config.yaml and is passed to the Collector at startup, and its location depends on your deployment, so confirm the path in your Kubernetes manifest, systemd unit, or container command. Validate the file before rollout, and bind receivers only to the interfaces you intend to use, since server components bind to localhost by default in recent Collector versions. The step is done when the Collector starts cleanly and reports the log pipeline as running.

  7. Check that a sample log carries the trace ID

    Generate a request that passes through at least two services, then find the resulting span in your tracing backend and copy its trace ID. Search your log backend for that trace ID and confirm that log records from each service appear, with the same trace ID and the matching span ID. Repeat the check for an error path so you can see exceptions correlated with their spans. Keep the query you used in your runbook so the check can be repeated after upgrades. The step is done when a single trace ID returns logs from every service in the request path.

Keeping sensitive data out of correlated logs

Once trace IDs sit next to log bodies and attributes, the logs inherit whatever sensitive data the application writes and whatever the Collector accepts from the network. The cards below cover the data, the Collector endpoints, the configuration and the build, and the defaults to verify before production.

Regulated personal data in correlated logs

Correlation makes existing log lines easier to find, and it also makes personal data easier to move. A log line that once sat in one file can now reach a back end with trace context, service names and user identifiers attached. Inventory which fields your applications log, classify them against your data protection rules, and decide before rollout which fields may leave the application at all.

Unauthenticated Collector receivers

A Collector receiver that accepts OTLP from the network without authentication lets any reachable client send telemetry that your back ends will store. Decide which services may send data, and place authentication on the receiver. The authenticator extensions can verify incoming connections, for example with OIDC, so confirm they are configured on every receiver exposed beyond the host.

Collector configuration docs

Securing Collector configuration

Collector configuration often holds endpoints, tokens and client secrets for exporters. Store it outside source control in plain text, encrypt it where your platform allows, and restrict who can read or change it. Check that exporter credentials are added through the authenticator extensions rather than pasted into files that many engineers can open.

Redacting sensitive attributes

The redaction processor removes or masks attributes that match your rules before data is exported, which is the last chance to stop a card number or national identifier from reaching storage. Write rules for the fields your logs carry, then test them with sample logs that contain realistic-looking but synthetic values. Redaction covers the fields you named, so review new log statements during change control.

Building only the components you need

The Collector Builder compiles a Collector from the components you list, which keeps unused receivers, processors and exporters out of the binary. Fewer components means a smaller attack surface and fewer components to patch. Releases also ship the contrib distribution, so confirm which distribution you run and which components each configuration actually uses.

Security best practices

Localhost binding default since v0.110.0

Since Collector v0.110.0, server components bind to localhost by default instead of all interfaces. Upgrading past that version therefore changes behavior for pipelines that relied on the old default, and older deployments may still listen on every interface. Verify the bind addresses in each running Collector, and set explicit addresses only where remote services must reach it.

Questions teams ask before correlating logs with traces

How much effort does it take to correlate logs with traces?

The effort depends mostly on how many services write logs, which logging library each one uses, and whether those libraries already have an OpenTelemetry bridge. Teams with a small set of services on one supported language usually need a bounded change: add a logging bridge or enable log export, confirm that trace and span IDs appear on each log record, and then check the backend view. Effort rises when services use several languages, when log formats are inconsistent, or when some runtimes have logs support still in development. The most reliable way to size the work is a written inventory of services, languages, logging libraries and current log destinations, which a provider can use to quote the scope. Ask for the quote to split the work into an inventory phase, a pilot on one service and a rollout phase, so each step has a clear exit check.

Can our own team correlate logs with traces without outside help?

Yes, a team that already runs its own services and has someone comfortable with the Collector can do the work in-house, provided the language support is confirmed first. The work involves three skill areas: application instrumentation, Collector configuration and backend setup. A team that owns all three, and has time to test changes in a non-production environment, can handle a pilot alone. Outside help tends to be useful when many languages are involved, when log SDK maturity differs across runtimes, or when the team needs the setup reviewed for security before production use. Ask a provider to state which parts it would do, which it would leave to your team, and what handover material you would receive.

What do we need to provide before a correlation project starts?

Three inputs make the scope accurate. The first is a logging inventory: the services, their languages and runtimes, the logging libraries they use, log formats, current log destinations and retention rules. The second is access to the hosts where Collectors will run, along with permission to change application deployment settings in a test environment. The third is a backend decision: the team needs to know where logs and traces will be stored and queried, because the export path depends on it. Teams often also need to name the owners of sensitive fields, since logs can contain personal or regulated data that should be removed before export. Ask the provider to list these inputs in the quote so gaps are visible before work begins.

How long does it take to verify that correlation works?

Verification takes a fixed sequence of checks, and its length depends on how many services and environments are in scope. For each service, the team confirms that a request produces a trace, that log records written during the request carry the same trace and span IDs, and that the backend can move between a trace and its matching logs. Teams also check that the IDs are present in production-like load and that no sensitive fields leaked into the export path. Duration depends on test traffic, how quickly a test environment can be deployed, and how many languages need separate checks. Ask a provider to describe its verification steps and the evidence it will hand over, such as test records or screenshots, and to give a schedule tied to the agreed scope.

Do we have to rewrite our existing application logs?

Usually not. Most correlation approaches add trace and span IDs to log records that the application already writes, either through a logging bridge that attaches the active trace context or through a Collector that reads existing log files and enriches them. Rewriting log statements is needed only where a service does not write logs through a supported library, or where log messages are unstructured and the team wants to add fields for search. Check the log SDK status for each language before choosing a path, because some languages still have logs support in development. Changes to log formats should be planned separately from the correlation work so that dashboards and alerts that depend on current fields do not break.

Should logs go straight from the SDK or be collected from files?

The choice depends on language support, host access and how much change the team can accept in application code. Exporting logs from the SDK sends records over OTLP and keeps the application and telemetry path together, but it needs a stable log SDK for the language. Collecting log files with the Collector suits services that cannot change, or hosts where the application already writes structured logs, but it needs file access, parsing rules and a plan for log rotation. Many teams use both paths during a transition. A provider should record the choice per service in the design, along with the reason, so the platform team can review it later.

What makes the cost of this work go up or down?

Cost is driven by labor, mostly, and by the number of variables the work must cover. The main cost drivers are the number of services and languages, the number of environments, whether log formats need changes, the number of Collector deployments, and the amount of security review required for sensitive fields and endpoints. Recurring costs include Collector upgrades, configuration changes as services are added, and backend storage for logs, which depends on the backend you choose. Ask for a quote that separates one-time setup, a pilot, rollout, handover and any retainer for ongoing support, and ask what each line assumes about services, environments and hosts. Because DeployOpen works to a written scope, the quote follows from the inventory rather than from a fixed price list.

Which languages should we check for log support first?

Check the OpenTelemetry status page for each language in your estate before committing to a design. Trace APIs and SDKs are stable in most languages, including C++, .NET, Go, Java, JavaScript, PHP, Python, Ruby and Swift, while log SDK maturity varies more and several languages are still in development. Confirm the status of the logging library your team actually uses, not only the language, because bridge support depends on that library. Record the result in the inventory so that services on languages with immature log support are routed to file collection or planned for later. Your engineers should also verify the current status for the exact versions of the SDK and bridge they plan to deploy.

Running correlated logs in production

After go-live, the first thing to monitor is the Collector itself, because a correlated log pipeline fails quietly when the Collector drops data or stops exporting. Watch the Collector's own telemetry for refused and dropped spans, logs and metrics, and set alerts on the exporter queue so backpressure shows up before log lines go missing from the back end. Check that the log_record fields carrying trace_id and span_id still arrive populated after each deployment, since a changed logging configuration can strip them without any error. Decide who owns these alerts and whether the Collector's health endpoint is reachable only from the monitoring network, because the Collector's server components bind to localhost by default since v0.110.0 and any exposure you added during setup needs to be reviewed.

Trace ID consistency is the second check. Sample a set of requests end to end and confirm that the trace ID written to each service's logs matches the trace ID on the spans in the back end. Mismatches usually come from a service that starts a new trace on an inbound call, a proxy that drops the traceparent header, or a queue consumer that does not restore the context. Log format changes are the third risk: a library upgrade can rename fields, change the JSON structure or alter how the logging bridge writes attributes, and parsing rules or dashboards built on the old shape will break silently. Pin logging library versions, review the diff in sample output after each upgrade, and confirm that log SDK maturity for your language is still what the OpenTelemetry status page reports, because the logs signal is not uniformly stable across languages.

Keep the Collector current on a planned cadence. Release dates for each Collector version are published on the OpenTelemetry Collector releases page, which also lists the signed artifacts, checksums and SBOM files you should verify before deploying. Before moving to a new version, test it in a non-production environment against your real log and trace samples, and read the stability notes in each component's README for every receiver, processor and exporter your pipeline uses, since those components have mixed stability levels. Confirm which of these components your team relies on for log correlation and record the version you tested, so the upgrade decision rests on evidence from your own pipeline rather than the release notes alone.

How DeployOpen scopes and delivers log and trace correlation

DeployOpen plans, builds and hands over log and trace correlation inside your own infrastructure, starting from the logging libraries your applications already use. We agree the scope in writing first, then test the setup against your real log paths and collector pipeline before your teams depend on it.

How we scope

  • Inventory which services already write logs, which logging libraries they use, and where those logs currently go.
  • Confirm the OpenTelemetry language support for each runtime, including whether the logs signal is stable or still in development.
  • Agree in writing whether trace context goes out through SDK log export, file collection, or a mix of both for each service.

How we build

  • Configure logging bridges so trace and span IDs are written into existing log records without rewriting application log statements.
  • Set up the Collector pipeline that receives, processes and exports correlated logs, with redaction rules for sensitive attributes.
  • Test that a sample request produces a trace and matching log lines that share the same trace and span identifiers.

How we hand over

  • Document the logging library configuration, log format, Collector configuration and the trace fields each service emits.
  • Provide a verification runbook that lists the checks to repeat after each deployment or library upgrade.
  • Walk your platform and security teams through the configuration so they can review and operate it themselves.

How we support

  • Ongoing support, upgrades and continuous testing are available as retainers after the initial handover.
  • Retainers can cover Collector and SDK version upgrades, since correlation behavior can change between releases.
  • Ask any proposal to name who owns each recurring task, such as upgrades, log format changes and new services.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.