Enable Logs-in-context with Winston


New Relic offers a Winston extension to connect your log data to New Relic Logs-in-context for Node.js, allowing you link to your log data with related data across the rest of the New Relic platform. This document explains how to enable this feature and get started using it.

New Relic's logs-in-context (linking logs directly to Applications, APM errors, and APM traces and spans) for New Relic Logs is currently available as a beta feature. Your use of the early access service is at your own risk. New Relic disclaims all warranties, express or implied, regarding the beta services.

Compatibility and Requirements

To use New Relic Logs-in-context with Winston, ensure your configuration meets the following requirements:

New Relic Logs must be enabled prior to enabling logs-in-context. For more information, see Introduction to New Relic Logs.

Enable logs-in-context with New Relic Logs

To enable New Relic logs-in-context with Winston:

  1. Install or update the Node.js agent.
  2. Enable and configure the Winston extension.
  3. Check for logging data.

Install or update the Node.js agent

Install or update to the most recent Node.js agent version, and enable Distributed tracing.

Enable and configure the Winston extension

To enable logs-in-context with the Winston extension, complete the following steps:

  1. To install the New Relic Winston log enricher, enter the following command into your terminal or command line interface:

    npm install @newrelic/winston-enricher
  2. In your application code, update your logging configuration to add the newrelicFormatter as shown below:.

    // index.js
    const newrelicFormatter = require('@newrelic/winston-enricher')

    The New Relic formatter can be used individually or combined with other formatters as the final format.

    format: winston.format.combine(
      winston.format.label({label: 'test'}),

Check for logging data

To verify that you have configured the extension correctly, run your application and verify that the logging you have configured contains the following:

  1. Includes trace.id and span.id fields
  2. Is properly-formatted JSON lines

If everything is configured correctly and your data is being reported, you should see data logs in the New Relic Logs UI using the query operator has: span.id/trace.id.

What's next?

Now that you've enabled logs-in-context, here are some potential next steps:

For more help

Recommendations for learning more: