Node.js Agent Troubleshooting Framework Logs in Context

Winston

General

  • Review the Compatibility and Requirements for setting up Logs in Context for the Node.js agent:
  • Ensure you have distributed tracing enabled for the Node.js agent.
  • Ensure you have installed the @newrelic/winston-enricher library.
  • Double check that you have installed and implemented Winston as the logger for your application.
    • If you aren’t using Winston in your application you will need to manually add our context metadata to your logs by using the Agent API.
  • Make sure you have required the winston enricher library correctly in the main javascript file for your application. Here’s an example of what that could look like:
 // app.js

require('newrelic');

require(‘winston’);

const newrelicFormatter = require('@newrelic/winston-enricher');
  • Ensure that you use the newrelicFormatter reference correctly when you create your logger with Winston.
  • Once you have configured the enricher you should examine your logs to check that they are formatted as JSON and contain the following fields:
    • “entity.name”
      • Should be the application name set in APM for the service you’ve configured Logs in Context for.
    • “entity.type”
      • Should be the string “SERVICE”
    • “entity.guid”
      • The ID of the entity.
    • “trace.id"
      • Will only be present if distributed tracing is enabled and a corresponding transaction generates a log.
    • "span.id”
      • Will only be present if distributed tracing is enabled and a corresponding span generates a log.
    • “hostname”
      • This should be the hostname gathered by the APM agent.

Troubleshooting

  • Make sure your APM language agent is installed and set up correctly.

  • Make sure that you have Distributed Tracing configured correctly for your application. If you do not you will not see a span.id and trace.id in your log metadata.

  • If you aren’t seeing logs in the Logs UI. Ensure that you have installed and configured a New Relic plugin for a compatible log forwarder:

  • Check your Logs UI in New Relic and query using the the following:

    • has: span.id has:trace.id
  • Double check that you are using your logger within a Node.js agent transaction. If you are not then your logs will not have linkage with APM.

Make sure that you have Distributed Tracing configured correctly for your application. If you do not you will not see a span.id and trace.id in your log metadata.