Link Traces with Logs
Linking traces with logs allows you to correlate error incidents and traces with log messages, making it easier to debug issues by viewing relevant logs directly alongside your traces. By adding an identifier to both your traces and logs, you can navigate between them in the AppSignal interface.
How It Works
To link traces with logs, you need to add the same identifier to both, such as request_id or trace_id.
This will be set up automatically in most cases, but when it's not make sure the following identifiers are set.
- Add a request or trace identifier to your trace as an AppSignal tag or OpenTelemetry attribute.
- Add the same identifier to your logs as a log attribute.
When AppSignal receives traces and logs with matching identifiers, it can correlate them, allowing you to view related logs when inspecting a trace sample.
Choosing an Identifier
You can use any of the following identifiers to link traces and logs:
request_id- A unique identifier for each HTTP request (common in web frameworks).trace_id- The AppSignal or OpenTelemetry trace ID.
Many web frameworks automatically generate a request_id for each request, making it a convenient choice.
For OpenTelemetry-based integrations, you can use the trace ID directly.
Linking Application Logs
Report logs from your application by setting up logging using the AppSignal packages or OpenTelemetry SDK.
Most framework configuration will already have request_id or trace_id tags set up.
If no relevant logs are detected, follow the logging set up instructions for the framework your application uses or report the identifier manually as a trace tag and log attribute.
Viewing Linked Logs
Once you've configured your application to link traces with logs, you can view related logs directly in the AppSignal interface:
- Navigate to a performance trace sample or error incident.
- Look for the related logs block, which will link to the relevant log messages.
- Use the logs to gain additional context about what happened during the request.
This correlation makes debugging faster, as you can quickly find the relevant trace and logs.
Next Steps
- Set up log reporting to send your application logs to AppSignal.
- Learn more about adding tags to your traces.