• /
  • Log in
  • Free account

Java: Configure logs in context

Logs in context for the Java 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.

Set up your Java app

To enable logs in context for APM apps monitored by Java:

  1. 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.
  2. Install or update to the latest Java agent version. Use Java agent version 5.6.0 or higher for logs in context.
  3. Enable the JVM argument -javaagent, and enable distributed tracing.
  4. Configure logs in context for Java to enrich your log data, using any of the following extensions as applicable. If you use Spring or Spring Boot and aren't sure which extension you need, see our Spring documentation.

View logs in UI

To verify that you have configured the log appender correctly, run your application, then check your logs data in New Relic One using the query operator has:span.id has:trace.id.

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 trace.id and span.id fields. If you don't see log data in the UI, follow the troubleshooting procedures.

What's next?

After you set up APM logs in context, make the most of your logging data:

Create issueEdit page
Copyright © 2021 New Relic Inc.