Skip to content

Latest commit

 

History

History
156 lines (117 loc) · 6.61 KB

File metadata and controls

156 lines (117 loc) · 6.61 KB
title metaDescription redirects freshnessValidatedDate
Forward Micrometer data to New Relic with OpenTelemetry
New Relic offers an integration that sends your Micrometer telemetry data to your New Relic account.
/docs/integrations/open-source-telemetry-integrations/micrometer/micrometer-metrics-registry
/docs/integrations/open-source-telemetry-integrations/open-source-telemetry-integration-list/new-relics-micrometer-integration
never

import opentelemetryMicrometerWithOtel from 'images/opentelemetry_screenshot-full_micrometer-with-otel.webp'

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](https://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 [#requirements]

Before working through these procedures, you should:

Forward Micrometer data to New Relic [#forward-data-OpenTelemetry]

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:

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

</Step>
<Step>

Add OpenTelemetry dependencies

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

```java
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.

</Step>
<Step>

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")
                                .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();
    }
</Step>

    <Step>

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.

</Step>

What's next? [#whats-next]

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