- Configure logs in context for Python | New Relic Documentation
- newrelic-python-agent/log.py at main · newrelic/newrelic-python-agent · GitHub
- Review the Compatibility and Requirements for setting up Logs in Context for the Python agent:
- Python agent 5.4.0 or higher
- Ensure you have distributed tracing enabled for the Python agent.
- Check your logging configuration:
- Import Python’s Logging module.
- Import New Relic’s
- Check that you’ve created a log handler in your code. There is a list of usable logging handlers in Python’s docs:
- Check that NewRelicContextFormatter is the formatter for your log handler.
- Check that you’ve added your new logging handler to your root logger.
- You can see an example of the above in our docs here:
- Once you have configured the enricher you should examine your logs to check that they are formatted as JSON and contain the following fields:
- Should be the application name set in APM for the service you’ve configured Logs in Context for.
- Should be the string “SERVICE”
- The ID of the entity.
- Will only be present if distributed tracing is enabled and a corresponding transaction generates a log.
- Will only be present if distributed tracing is enabled and a corresponding span generates a log.
- This should be the hostname gathered by the APM agent.
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
trace.idin 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