Documentation forSolarWinds Observability

Node.js 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 Library 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.

Use the SDK

If your logger is not supported for automatic insertion, or for finer control, you can use the SDK to add trace context to application logs. See the reference guide on ao.getTraceObjectForLog and ao.getTraceStringForLog for details and examples.