This example should be considered to be deprecated. Instead of following this method of delivering logs, we recommend that customers use the Node agent for logs in context and log forwarding.
This project demonstrates logs in context with New Relic by using a Node.js application and log enrichers.
The sample application has support for the two log enrichers: @newrelic/winston-enricher and @newrelic/pino-enricher. It also contains a container to run fluentd with the fluent-plugin-newrelic to forward logs to New Relic One.
Note: You must have Docker and Docker Compose installed. The steps below are using hey to generate load on the sample app.
-
Clone or fork this repository.
-
Copy
.env.example
to.env
and fill out the following keys:NEW_RELIC_LICENSE_KEY=<New Relic License Key> # By default the app is using pino + @newrelic/pino-enricher # If you want to use winston + @newrelic/winston-enricher add # WINSTON=1
-
Build containers
docker-compose build
-
Start containers
docker-compose up -d
-
Make requests to the app
hey -z 5m http://localhost:3000
-
Navigate to New Relic One > APM > (select an app) > Triage > Logs.
-
View the details of the log entry and you can see
entity.*
,span.id
andtrace.id
metadata added. -
Navigate to APM > (select an app) > Monitor > Distributed Trace. Click a trace group > trace > See logs(top right of pane).
If you are a New Relic employee and wanting to testing on a staging environment, add the following:
NEW_RELIC_HOST=staging-collector.newrelic.com
NEW_RELIC_LOG_HOST=https://staging-log-api.newrelic.com/log/v1