- Dropwizard must be configured and working in the application with the Dropwizard appenders and logging factory.
- The New Relic Java agent must be enabled using the
-javaagent
command-line parameter. - You must be using at least version 5.6.0 of the Java Agent.
There are some changes to your application to use the New Relic Dropwizard Logging Extension. All steps are required.
Optional: Configuration Options for setting max stack size or collecting MDC.
Refer to Maven Central for the appropriate snippets.
Update your DW configuration yaml like the example below. Modify the appender you have chosen to receive decorated logs.
If you were using type: console
, then replace that with type: newrelic-console
. This is a frequent use case for container-based applications. All
configuration elements for type: console
will still apply.
If you were using type: file
then replace that with type: newrelic-file
. All
configuration elements for type: file
will still apply.
logging:
appenders:
- type: newrelic-file
# Add the two lines below if you don't have a layout specified on the appender.
# If you do have a layout, remove all parameters to the layout and set the type to newrelic-json.
layout:
type: newrelic-json
Why? The appenders are different because they must capture New Relic-specific data on the thread the log message
is coming from. The newrelic-file
and newrelic-console
appenders inherit from the existing file
and console
appenders with a different asynchronous wrapper. Unfortunately, DW service loading does not provide for injecting
that automatically.
The layout is different because the New Relic log format is a tailored JSON format with specific fields in specific places that our log forwarder plugins and back end rely on.
The New Relic Dropwizard plugin 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.
# The `replace` parameter in the PatternLayout retrieves all MDC values and strips off the
# `NewRelic:` prefix from all linking metadata keys.
logFormat: "%date{ISO8601} %c %-5p: %m %replace(%mdc{}){'NewRelic:', ''}%n"
layout:
# type: newrelic-json
type: log-format
There are two important steps for adding linking metadata to the request log.
@Override
public void run(AppConfiguration configuration, Environment environment) {
environment.servlets().addFilter("trace-into-request", new LinkingMetadataAsRequestAttributesFilter())
.addMappingForUrlPatterns(null, true, "/*");
}
This layout type is a JSON format stylized after OpenTelemetry attributes. Do not use a newrelic-
appender, only use the newrelic-access-json
layout.
server:
requestLog:
appenders:
- type: console
layout:
type: newrelic-access-json
Dropwizard is © Copyright 2010-2013, Coda Hale, Yammer Inc., 2014-2017 Dropwizard Team.