• /
  • EnglishEspañol日本語한국어Português
  • ログイン今すぐ開始

Forward Micrometer data to New Relic with OpenTelemetry

New Relic supports Micrometer data so you can view all of your observability metrics in one platform. You'll configure the OpenTelemetry Micrometer bridge with the OpenTelemetry SDK, then use OpenTelemetry Protocol (OTLP) to forward your Micrometer data to New Relic.

A screenshot of the Micrometer summary page when instrumented with OpenTelemetry

Go to one.newrelic.com > All Capabilities > APM & Services, then find the Services - OpenTelemetry section: View your Micrometer data in New Relic when bridged through OpenTelemetry

Compatibility and requirements

Before working through these procedures, you should:

Forward Micrometer data to New Relic

These are generalized steps to set up Micrometer metrics forwarding. You may want to update code snippets as needed to fit your specific environment.

Add OpenTelemetry Micrometer instrumentation

Add OpenTelemetry Micrometer instrumentation to the alpha modules section of your build.gradle file:

//Alpha modules
implementation 'io.opentelemetry.instrumentation:opentelemetry-micrometer-1.5'

Add OpenTelemetry dependencies

In the dependencies section, add the OpenTelemetry SDK and OTLP exporter:

dependencies {
implementation 'io.opentelemetry:opentelemetry-sdk'
implementation 'io.opentelemetry:opentelemetry-exporters-otlp'
}

An example file with alpha modules and dependencies added might look something like this:

plugins {
id 'java-library'
id 'org.springframework.boot'
}
bootRun {
mainClass.set 'io.opentelemetry.example.micrometer.Application'
}
dependencies {
implementation platform("io.opentelemetry:opentelemetry-bom-alpha:JAVA_OTEL_VERSION")
implementation 'io.opentelemetry:opentelemetry-sdk'
implementation 'io.opentelemetry:opentelemetry-exporters-otlp'
implementation platform("io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom-alpha:OTEL_JAVA_INSTRUMENTATION_VERSION")
implementation 'io.opentelemetry.instrumentation:opentelemetry-micrometer-1.5'
}

Keep in mind you will need to update the snippet with correct versioning.

Configure Micrometer to forward data to New Relic

Below is an example code snippet that directs Micrometer to use the OpenTelemetry Micrometer bridge.

This snippet updates your code so OpenTelemetry can detect Micrometer data, then forward that data to New Relic:

public OpenTelemetry openTelemetry() {
return OpenTelemetrySdk.builder()
.setMeterProvider(
SdkMeterProvider.builder()
.setResource(
Resource.getDefault()
.toBuilder()
.put("service.name", "micrometer-shim")
// Include instrumentation.provider=micrometer to enable
// micrometer metrics experience in New Relic
.put("instrumentation.provider", "micrometer")
.build())
.registerMetricReader(
PeriodicMetricReader.builder(
OtlpHttpMetricExporter.builder()
.setEndpoint("https://otlp.nr-data.net/v1/metrics")
.addHeader("api-key",
Optional
.ofNullable(System.getenv("NEW_RELIC_LICENSE_KEY"))
.filter(str -> !str.isEmpty() && !str.isBlank())
.orElseThrow())
// IMPORTANT: New Relic exports data using delta
// temporality rather than cumulative temporality
.setAggregationTemporalitySelector(
AggregationTemporalitySelector
.deltaPreferred())
// Use exponential histogram aggregation for
// histogram instruments to produce better data
// and compression
.setDefaultAggregationSelector(
DefaultAggregationSelector.getDefault().with(
InstrumentType.HISTOGRAM,
Aggregation.base2ExponentialBucketHistogram()))
.build())
// Match default micrometer collection interval of 60
// seconds
.setInterval(Duration.ofSeconds(60))
.build())
.build())
.build();
}

Find your data in New Relic

Wait a few minutes, trigger some test data, then go to one.newrelic.com > All Capabilities > APM & Services, then find Services - OpenTelemetry to choose the service instrumented with Micrometer.

What's next?

To learn more about using New Relic with Micrometer data, we recommend these docs:

Copyright © 2024 New Relic株式会社。

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