• EnglishEspañol日本語한국어Português
  • Log inStart now

OpenTelemetry logs: Best practices

Logs may represent application logs, machine generated events, or system logs. OpenTelemetry has defined a log data model for representing log data.

You can send logs using OpenTelemetry tooling, correlate them with applications, and view them in New Relic.

Send logs to New Relic

The OpenTelemetry Collector and OpenTelemetry Collector Contrib repositories contain a number of components for consuming log data. The general pattern is to configure the collector to:

  1. Receive logs from any of the log receivers. Some of the receiver options include Filelog Receiver, Fluent Forward Receiver, and Syslog Receiver.
  2. Process logs, potentially annotating them with resource information. Some of the processor options include Resource Detection Processor and Resource Processor.
  3. Export logs to New Relic via the OTLP exporter.

Correlate your application logs

Application logs are more useful if they're correlated with other telemetry data produced by the application. The OpenTelemetry semantic convention for services specifies service.name as a required field. All application metric, trace, and log data sent to New Relic with the same service.name are associated with the same entity.

The specifics of how logs get annotated with the service.name resource attribute depends on the application's environment:

  • Applications may produce structured JSON logs, which you can configure to include service.name as another field.
  • You can deploy applications alongside a dedicated Collector agent instance, which you can configure with a Resource processor to annotate logs with the service.name attribute.

Optionally, additional application trace context (sometimes called execution context) can be propagated to log messages. The setup and availability of this depends on the language and logging framework used by the application. The general strategy is to set up the application to write structured JSON logs and to configure it to extract trace context into specified trace context fields on available log messages. For more details, see OpenTelemetry in the UI: Logs page.

The Logs in Context with Log4j2 example in GitHub demonstrates an end-to-end working example for a simple Java application using Log4j2.

View OpenTelemetry logs

Here are two ways you can view logs:

The time field

The timeUnixNano field is optional according to the OpenTelemetry specification for log data. When timeUnixNano is not present New Relic will use the time that the data was received for the New Relic log timestamp.

Copyright © 2024 New Relic Inc.

This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.