Enable Logs-in-context with Dropwizard

BETA

New Relic offers a Dropwizard extension to connect your log data to New Relic Logs-in-context for Java, allowing you link to your log data with related data across the rest of the New Relic platform.​ This document explains how to enable this feature and get started using it.

New Relic's logs-in-context (linking logs directly to Applications, APM errors, and APM traces and spans) for New Relic Logs is currently available as a beta feature. Your use of the early access service is at your own risk. New Relic disclaims all warranties, express or implied, regarding the beta services.

Compatibility and requirements

To use New Relic Logs-in-context with Dropwizard 1.3, ensure your configuration meets the following requirements:

New Relic Logs must be enabled and a compatible log forwarder must be installed prior to enabling logs-in-context. For more information, see Introduction to New Relic Logs.

Enable logs-in-context with New Relic Logs

To enable New Relic logs-in-context with Dropwizard:

  1. Install or update the Java agent.
  2. Enable and configure the Dropwizard extension.
  3. Check for logging data.

Install or update the Java agent

Install or update to the most recent Java agent version, and enable Distributed tracing.

Enable and configure the Dropwizard extension

To enable logs-in-context with the Dropwizard 1.3 extension, complete the following steps:

  1. Update your project's dependencies to include the Dropwizard 1.3 extension as applicable:

    Update with Gradle

    To update with Gradle, add the following to your build.gradle file:

    dependencies {
        compile("com.newrelic.logging:dropwizard:1.0-rc2")
    }
    Update with Maven

    To update with Maven, add the following to your pom.xml file:

    <dependencies>
        <dependency>
            <groupId>com.newrelic.logging</groupId>
            <artifactId>dropwizard</artifactId>
            <version>1.0-rc2</version>
        </dependency>
    </dependencies>
  2. Update your Dropwizard .yaml configuration file with a newrelic-json layout, replacing the currently used type: console or type: file with either type: newrelic-console or type: newrelic-file as appropriate. For example:
    logging:
      appenders:
        - type: newrelic-console
          # Add the two lines below if you don't have a layout specified on the appender.
          # If you have a layout, remove all parameters to the layout and set the type.
          layout: 
            type: newrelic-json

    Alternatively, the New Relic Dropwizard extension also supports a log-format layout type that uses the standard Dropwizard logging. For testing purposes, you can change the type of the layout with a one-line change

    logging:
      appenders:
        - type: newrelic-file
          # This format will be ignored by the newrelic-json layout, but used by the log-format layout.
          logFormat: "%date{ISO8601} %c %-5p: %m trace.id=%mdc{trace.id} span.id=%mdc{span.id}%n"
          layout: 
            # type: newrelic-json
            type: log-format

Check for logging data

To verify that you have configured the extension correctly, run your application and verify that the logging you have configured contains the following:

  1. Includes trace.id and span.id fields
  2. Is properly-formatted JSON lines

If everything is configured correctly and your data is being reported, you should see data logs in the New Relic Logs UI using the query operator has: span.id/trace.id.

What's next?

Now that you've enabled logs-in-context, here are some potential next steps:

For more help

Recommendations for learning more: