newrelic / newrelic-java-agent

The New Relic Java agent
Apache License 2.0
202 stars 143 forks source link

Auto-configure the opentelemetry SDK #1798

Closed sdaubin closed 7 months ago

sdaubin commented 7 months ago

Overview

This PR allows users to use the OpenTelemetry SDK and auto-configuration to send dimensional metrics to New Relic.

In the service code, include the OpenTelemetry SDK:

    implementation 'io.opentelemetry:opentelemetry-sdk-extension-autoconfigure:1.33.0'
    implementation 'io.opentelemetry:opentelemetry-sdk:1.33.0'
    implementation 'io.opentelemetry:opentelemetry-exporter-otlp:1.33.0'

Access OpenTelemetry using GlobalOpenTelemetry:

GlobalOpenTelemetry.get().getMeterProvider().get("test").histogramBuilder("test.metric").build();

When running the instrumented service, set otel.java.global-autoconfigure.enabled:

-Dotel.java.global-autoconfigure.enabled=true

The java agent will configure the proper endpoint for sending data to the New Relic service.

Test app: https://github.com/sdaubin/kafka-examples

Value add

This makes it easy for customers to report dimensional metrics into their APM service with no special configuration. This is difficult today, especially trying to get data reported with the correct entity.guid stamp.

This also makes it easy to use the OTel metrics SDK today and later switch to an OTel agent without changing any code.

Related Github Issue

Include a link to the related GitHub issue, if applicable

Testing

The agent includes a suite of tests which should be used to verify your changes don't break existing functionality. These tests will run with Github Actions when a pull request is made. More details on running the tests locally can be found here,

Checks

codecov-commenter commented 7 months ago

Codecov Report

Attention: Patch coverage is 0% with 19 lines in your changes are missing coverage. Please review.

Project coverage is 70.83%. Comparing base (267afe2) to head (7714c06). Report is 6 commits behind head on main.

Files Patch % Lines
...a/com/newrelic/agent/rpm/RPMConnectionService.java 0.00% 13 Missing :warning:
...nt/src/main/java/com/newrelic/agent/AgentImpl.java 0.00% 6 Missing :warning:
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1798 +/- ## ============================================ - Coverage 70.84% 70.83% -0.02% Complexity 9951 9951 ============================================ Files 827 828 +1 Lines 39880 39899 +19 Branches 6043 6045 +2 ============================================ + Hits 28254 28263 +9 - Misses 8900 8910 +10 Partials 2726 2726 ```

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.