Documentation forAppOptics

Trace Context in Logs

Adding trace context to application logs provides the ability to correlate the log messages from a traced transaction, and if sampled, the log messages to the transaction trace detail. The different ways to enable and use this feature in the Node.js agent are described below, and please check the Supported Components page for the full list of supported logging packages and versions.

Automatic Insertion

Automatic insertion adds the Trace ID directly to the log message, whether by inserting it as an attribute in structured JSON output or appending it to unstructured output. There are two configuration options, see Automatic Insertion of Trace ID into Logs for details.

Automatic Log Attribute / Token

This option creates a token that can be used in the logger's format string, giving you more control over when and where to insert the Trace ID. See Automatic Creation of Trace ID Log Attribute for details.

Using the SDK

If your logger is not supported for automatic insertion, or for finer control, you can use the SDK to add Trace ID to application logs. See the reference guide on ao.getFormattedTraceId and ao.insertLogObject for details and examples.