newrelic / newrelic-python-agent

New Relic Python Agent
https://docs.newrelic.com/docs/agents/python-agent
Apache License 2.0
178 stars 102 forks source link

Add tags to forwarded logs #1184

Closed spearki closed 2 months ago

spearki commented 3 months ago

Overview

This adds any tags defined in NEW_RELIC_LABELS as tags.* attributes in the forwarded logs captured by the agent. This brings some parity to the attributes included in transactions, so logs can be tagged without setting up a separate log forwarder.

This is implemented by adding the tag attributes to the get_linking_metadata() API so they are available in a few different places that forward logs, as well as included in the output of the NewRelicContextFormatter if manual instrumentation is used.

I haven't put this behind a new setting, but would be happy to do that if you think it's necessary (a suggestion for a suitable name would be appreciated in that case).

Testing

There's 1 test added, feedback definitely welcome there on the approach I took.

CLAassistant commented 3 months ago

CLA assistant check
All committers have signed the CLA.