Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OTel span support #1886

Draft
wants to merge 22 commits into
base: main
Choose a base branch
from
Draft

OTel span support #1886

wants to merge 22 commits into from

Conversation

sdaubin
Copy link
Contributor

@sdaubin sdaubin commented May 7, 2024

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

  • Your contributions are backwards compatible with relevant frameworks and APIs.
  • Your code does not contain any breaking changes. Otherwise please describe.
  • Your code does not introduce any new dependencies. Otherwise please describe.

@@ -59,6 +58,10 @@ ExitTracer createTracer(Object invocationTarget, int signatureId, boolean dispat

ExitTracer createScalaTxnTracer();

default ExitTracer createTracer(String metricName, int flags) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The createSegment API still generates an asynchronous tracer, which is not what we want. And from the bridge there's no easy way to register a signature to get a signatureId. This was the easiest way to get a normal, synchronous tracer.

@codecov-commenter
Copy link

codecov-commenter commented May 8, 2024

Codecov Report

Attention: Patch coverage is 35.00000% with 26 lines in your changes missing coverage. Please review.

Project coverage is 70.67%. Comparing base (c4536f9) to head (c308a60).
Report is 14 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 ⚠️
...ain/java/com/newrelic/agent/bridge/ExitTracer.java 0.00% 3 Missing ⚠️
...elic/agent/bridge/datastore/SqlQueryConverter.java 0.00% 3 Missing ⚠️
...ava/com/newrelic/agent/database/SqlObfuscator.java 25.00% 3 Missing ⚠️
...elic/agent/service/analytics/SpanEventFactory.java 40.00% 2 Missing and 1 partial ⚠️
...ava/com/newrelic/agent/tracers/AbstractTracer.java 0.00% 3 Missing ⚠️
...n/java/com/newrelic/agent/bridge/TracedMethod.java 0.00% 2 Missing ⚠️
...gent/instrumentation/pointcuts/XmlRpcPointCut.java 0.00% 2 Missing ⚠️
...ava/com/newrelic/agent/bridge/Instrumentation.java 0.00% 1 Missing ⚠️
...wrelic/agent/introspec/internal/SpanEventImpl.java 0.00% 1 Missing ⚠️
... and 1 more
Additional details and impacted files
@@             Coverage Diff              @@
##               main    #1886      +/-   ##
============================================
- Coverage     70.69%   70.67%   -0.03%     
- Complexity     9991    10006      +15     
============================================
  Files           841      846       +5     
  Lines         40314    40385      +71     
  Branches       6110     6119       +9     
============================================
+ Hits          28501    28543      +42     
- Misses         9069     9087      +18     
- Partials       2744     2755      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@sdaubin sdaubin requested a review from jasonjkeller May 8, 2024 22:27
jasonjkeller
jasonjkeller previously approved these changes Jul 2, 2024
@jasonjkeller jasonjkeller marked this pull request as draft July 11, 2024 20:35
@jasonjkeller
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
oct-dec qtr Represents proposed work item for the Oct-Dec quarter
Projects
Development

Successfully merging this pull request may close these issues.

3 participants