newrelic / node-newrelic

New Relic Node.js agent code base. Developers are welcome to create pull requests here, please see our contributing guidelines. For New Relic technical support, please go to http://support.newrelic.com.
Apache License 2.0
971 stars 399 forks source link

Attach labels (tags) to logs #2716

Open svetlanabrennan opened 5 days ago

svetlanabrennan commented 5 days ago

Description

We need to support adding labels (tags) to logs.

TLDR:

Dependent on this issue that adds configurations to the agents to enable this feature: https://github.com/newrelic/node-newrelic/issues/2713

Implementation details:

Example newrelic.config bit from .NET showing labels with no exclude configuration:

<labels>label1:value1;LABEL2:value2;LABEL2-ALSO:value3</labels>

Example log_event_data payload based on above newrelic.config:

[{
   "common": {
     "attributes": {
       "entity.guid": <ENTITY_GUID>,
       "entity.name": "My Application",
       "hostname": "my-host-name",
       "tags.label1": "value1",
       "tags.LABEL2": "value2",
       "tags.LABEL2-ALSO":"value3"
     }
   },
   "logs": [{
       "timestamp": <TIMESTAMP_IN_UNIX_EPOCH_MILLSECONDS>,
       "level": "INFO"
       "message": "User 'xyz' logged in",
       "span.id": "123456789ADF",
       "trace.id": "ADF09876565"
     }]
}]

Same example above, but with the following exclude configuration (.NET agent XML):

<applicationLogging>
  <forwarding>
    <labels enabled="true" exclude="label2" />
  </forwarding>
</applicationLogging>

Example log_event_data payload based on above newrelic.config - no longer has LABEL2, but still has LABEL2-ALSO:

[{
   "common": {
     "attributes": {
       "entity.guid": <ENTITY_GUID>,
       "entity.name": "My Application",
       "hostname": "my-host-name",
       "tags.label1": "value1",
       "tags.LABEL2-ALSO":"value3"
     }
   },
   "logs": [{
       "timestamp": <TIMESTAMP_IN_UNIX_EPOCH_MILLSECONDS>,
       "level": "INFO"
       "message": "User 'xyz' logged in",
       "span.id": "123456789ADF",
       "trace.id": "ADF09876565"
     }]
}]

Link to labels spec.

Discovery doc about labels.

workato-integration[bot] commented 5 days ago

https://new-relic.atlassian.net/browse/NR-338335