Ruby Agent Troubleshooting Framework Logs in Context

Ruby Logger

General

  • Review the Compatibility and Requirements for setting up Logs in Context for the Ruby agent:
  • Ensure you have distributed tracing enabled for the Ruby agent.
  • For Rails Users:
    • Require ‘newrelic_rpm’ in your application.rb file.
    • Rails logging is controlled by two components: a logger (customizable by setting config.logger) and a log formatter (customizable by setting config.log_formatter).
    • Check that you have adjusted the Rails config.log_formatter to be the DecoratingFormatter in your application.rb file. You can see an example here:
    • If using rails, but not the default log_formatter, check that you are creating an instance of New Relic’s log. You can see an example here:
    • If you are using your own logger or a different log implementation make sure the Ruby agent’s DecoratingFormatter is referenced as the formatter. Example here:
  • If not using Rails:
  • Once you have configured the enricher you should examine your logs to check that they are formatted as JSON and contain the following fields:
    • “entity.name”
      • Should be the application name set in APM for the service you’ve configured Logs in Context for.
    • “entity.type”
      • Should be the string “SERVICE”
    • “entity.guid”
      • The ID of the entity.
    • “trace.id"
      • Will only be present if distributed tracing is enabled and a corresponding transaction generates a log.
    • "span.id”
      • Will only be present if distributed tracing is enabled and a corresponding span generates a log.
    • “hostname”
      • This should be the hostname gathered by the APM agent.

Troubleshooting

  • 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 span.id and trace.id in 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
  • Ensure that you’ve applied the logging configuration to all environments that you want logging data for.

  • Check that there aren’t other loggers configured later in the configuration of the application.

  • Check that you aren’t using any incompatible gems: