- Configure logs in context for PHP | New Relic Documentation
- GitHub - newrelic/newrelic-monolog-logenricher-php: Monolog components to enable New Relic Logs
- Review the Compatibility and Requirements for setting up Logs in Context for the PHP agent:
- Ensure you have distributed tracing enabled for the PHP agent.
- Check that you’ve installed the newrelic/monolog-enricher package using Composer.
- Review our getting started guide on github:
- Our monolog enricher provides three components:
- A Handler, which delivers log records directly from Monolog to New Relic Logs.
- A Processor. This can be used in conjunction with the New Relic PHP agent to decorate log records with linking metadata, which allows you to use logs-in-context to correlate log records with related data across the New Relic platform.
- A Formatter, which extends the JsonFormatter provided by Monolog to take the decorated log records from the Processor and output them with the simplified JSON body structure expected by New Relic Logs and its supported plugins.
- If using our Monolog Handler:
- Make sure you have PHP’s curl extension installed.
- Review your logging code and check that you’ve used the Processor and Handler classes provided by the log enricher in conjunction with Monolog’s built-in BufferHandler
- You can find an example of how to use these in our documentation here:
- If you ARE NOT using our Monolog Handler:
- 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.
If you are not using Monolog to forward logs AND you do not see logs in the 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
If the logs from your application do not include fields like trace.id and span.id, there may be a problem with the configuration of the Monolog log enricher:
- Make sure that you have Distributed Tracing configured correctly for your application.
- Make sure your application is using the Monolog logger object when sending log records and not
Check that another Monolog handler is not preventing the log record from bubbling.