Logs in context for the PHP agent connects your logs and APM data in New Relic. Bringing all of this data together in a single tool helps you quickly get to the root cause of an issue and find the log lines that you need to identify and resolve a problem.
To enable logs in context for APM apps monitored by PHP, you can use our manual installation option.
- Make sure you have already set up logging in New Relic. This includes configuring a supported log forwarder that collects your application logs and extends the metadata that is forwarded to New Relic.
- Install or update to the latest PHP agent version, and enable distributed tracing. Use PHP agent version 18.104.22.1680 or higher for logs in context.
- Install Monolog version 1 or 2, or use a compatible log forwarding plugin if you are not using the built-in Monolog Handler for New Relic.
- Configure logs in context for PHP using the Monolog extension, if used.
- To verify that you have configured the log appender correctly, run your application, then check your logs data in New Relic using the query operator
If everything is configured correctly and your data is being forwarded to New Relic with the enriched metadata, your logs should now be emitted as JSON and contain
span.id fields. If you don't see log data in the UI, follow the troubleshooting procedures.
If the logs from your application do not include fields like
span.id, there may be a problem with the configuration of the Monolog log enricher. In this situation:
- Check that the PHP agent for your app has been installed and is configured to enable distributed tracing.
- Check that your application is using the Monolog logger object when sending log records, not
- Check that another Monolog handler is not preventing the log record from bubbling.
After you set up APM logs in context, make the most of your logging data:
- Explore the logging data across your platform with our Logs UI.
- View your logs in context data in distributed tracing. Note that for PHP, logs in context data doesn't appear in the Logs tab of the APM UI.
- Get deeper visibility into both your application and your platform performance data by forwarding your logs with our infrastructure monitoring agent. Review your infrastructure logs in the UI.
- Set up alerts.
- Query your data and create dashboards.