newrelic / newrelic-java-agent

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

OTel span support #1886

Open sdaubin opened 5 months ago

sdaubin commented 5 months ago

Overview

The java agent supports auto configuring the OTel SDK to report data to New Relic. Spans that are created with the span api are orphaned from New Relic data structures though. This returns spans backed by NR traces to generate metric and DT data.

This change hooks the SdkTracerProvider.tracerBuilder method and returns our tracer builder. When spans are started, we attempt to create a tracer. If successful, we return a Span implementation backed by the tracer, otherwise we return a no op span.

There is some special logic based on the span kind:

consumer

We start an OtherTransaction for consumer span kind.

server

We start a transaction for server spans and turn it into a web transaction.

client

For client spans, we either turn it into a database span or an external based on the span attributes.

Configuration

opentelemetry.sdk.spans.enabled can be use to disable the span behavior. opentelemetry.instrumentation.{instrumentation-scope}.enabled can be used to disable spans for a specific Opentelemetry library

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 5 months ago

Codecov Report

Attention: Patch coverage is 35.71429% with 27 lines in your changes missing coverage. Please review.

Project coverage is 70.63%. Comparing base (7a8faab) to head (35c91f8). Report is 37 commits behind head on main.

Files with missing lines Patch % Lines
...java/com/newrelic/agent/tracers/DefaultTracer.java 69.23% 1 Missing and 3 partials :warning:
...ain/java/com/newrelic/agent/bridge/ExitTracer.java 0.00% 3 Missing :warning:
...elic/agent/bridge/datastore/SqlQueryConverter.java 0.00% 3 Missing :warning:
...ava/com/newrelic/agent/database/SqlObfuscator.java 25.00% 3 Missing :warning:
...elic/agent/service/analytics/SpanEventFactory.java 50.00% 2 Missing and 1 partial :warning:
...ava/com/newrelic/agent/tracers/AbstractTracer.java 0.00% 3 Missing :warning:
...n/java/com/newrelic/agent/bridge/TracedMethod.java 0.00% 2 Missing :warning:
...lic/agent/instrumentation/InstrumentationImpl.java 0.00% 2 Missing :warning:
...gent/instrumentation/pointcuts/XmlRpcPointCut.java 0.00% 2 Missing :warning:
...ava/com/newrelic/agent/bridge/Instrumentation.java 0.00% 1 Missing :warning:
... and 1 more
Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #1886 +/- ## ============================================ + Coverage 70.58% 70.63% +0.05% - Complexity 9880 9969 +89 ============================================ Files 829 844 +15 Lines 39961 40288 +327 Branches 6081 6110 +29 ============================================ + Hits 28207 28458 +251 - Misses 9022 9084 +62 - Partials 2732 2746 +14 ```

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

jasonjkeller commented 3 months ago

While this PR has been reviewed and approved, I'm changing it to a draft to prevent merging as there are ongoing discussions about the broader OTel strategy across APM and we want to make sure that all teams are in alignment on an approach.