Skip to content

Commit c308a60

Browse files
committed
Add readme for OTel functionality
1 parent 0750c0b commit c308a60

File tree

1 file changed

+93
-0
lines changed
  • instrumentation/opentelemetry-sdk-extension-autoconfigure-1.28.0

1 file changed

+93
-0
lines changed
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
# OpenTelemetry Instrumentation
2+
3+
This instrumentation module weaves parts of the OpenTelemetry SDK to incorporate bits of OpenTelemetry functionality into the New Relic Java agent.
4+
5+
Specifically it can:
6+
* Detect OpenTelemetry Spans and include them in New Relic Java agent traces.
7+
* Detect OpenTelemetry dimensional metrics and report them to the APM entity being monitored by the Java agent.
8+
* Autoconfigure the OpenTelemetry SDK so that OpenTelemetry data is sent to New Relic and properly associated with an APM entity guid.
9+
10+
## New Relic Java Agent Configuration
11+
12+
To use the OpenTelemetry Span and dimensional metric functionality incorporated into the New Relic Java agent you must enable the following config options:
13+
14+
Configuration via yaml:
15+
```
16+
opentelemetry:
17+
sdk:
18+
autoconfigure:
19+
enabled: true
20+
spans:
21+
enabled: true
22+
```
23+
24+
Configuration via system property:
25+
```
26+
-Dopentelemetry.sdk.autoconfigure.enabled=true
27+
-Dopentelemetry.sdk.spans.enabled=true
28+
```
29+
30+
Configuration via environment variable:
31+
```
32+
NEW_RELIC_OPENTELEMETRY_SDK_AUTOCONFIGURE_ENABLED=true
33+
NEW_RELIC_OPENTELEMETRY_SDK_SPANS_ENABLED=true
34+
```
35+
36+
## OpenTelemetry Dimensional Metrics
37+
38+
OpenTelemetry APIs can be used to create dimensional metrics which will be detected by the New Relic Java agent and reported to the APM entity being monitored by the New Relic Java agent.
39+
40+
To use this functionality, enable the feature as documented above, add the required `opentelemetry` dependencies to your application:
41+
```groovy
42+
implementation(platform("io.opentelemetry:opentelemetry-bom:1.44.1"))
43+
implementation("io.opentelemetry:opentelemetry-sdk-extension-autoconfigure")
44+
implementation("io.opentelemetry:opentelemetry-exporter-otlp")
45+
```
46+
47+
Then utilize the OpenTelemetry APIs to record dimensional metrics:
48+
```java
49+
LongCounter longCounter = GlobalOpenTelemetry.get().getMeterProvider().get("my-application").counterBuilder("my.application.counter").build();
50+
longCounter.add(1, Attributes.of(AttributeKey.stringKey("foo"), "bar"));
51+
```
52+
53+
Any recorded dimensional metrics can be found in the Metrics Explorer for the associated APM entity and can be used to build custom dashboards.
54+
55+
## OpenTelemetry Spans
56+
57+
Documented below are several approaches for incorporating OpenTelemetry Spans into New Relic Java agent traces.
58+
59+
### `@WithSpan` Annotation
60+
61+
The New Relic Java agent will detect usage of the OpenTelemetry [@WithSpan](https://opentelemetry.io/docs/zero-code/java/agent/annotations/) annotation. The `@WithSpan` annotation can be used as an alternative to the `@Trace` annotation.
62+
63+
This does not currently support the following config options:
64+
* [Suppressing @WithSpan instrumentation](https://opentelemetry.io/docs/zero-code/java/agent/annotations/#suppressing-withspan-instrumentation)
65+
* [Creating spans around methods with otel.instrumentation.methods.include](https://opentelemetry.io/docs/zero-code/java/agent/annotations/#creating-spans-around-methods-with-otelinstrumentationmethodsinclude)
66+
67+
Note that OpenTelemetry config properties can be set through environment or system properties, like our agent, and eventually through a config file. We can use our existing OpenTelemetry instrumentation model to get access to the normalized version of the instrumentation settings to include and exclude methods and pass those to the core agent through the bridge.
68+
69+
See `ClassTransformerConfigImpl.java` for implementation details of the `@WithSpan` annotation.
70+
71+
### Spans Emitted From OpenTelemetry Instrumentation
72+
73+
The New Relic Java agent will detect Spans emitted by [OpenTelemetry instrumentation](https://opentelemetry.io/docs/languages/java/instrumentation/). It does this by weaving the `io.opentelemetry.sdk.trace.SdkTracerProvider` so that it will create a New Relic Tracer each time an OpenTelemetry Span is started and weaving the `io.opentelemetry.context.Context` to propagate context between New Relic and OpenTelemetry Spans.
74+
75+
Currently, the New Relic Java agent does not load any OpenTelemetry instrumentation it simply detects Spans emitted by OpenTelemetry manual instrumentation, native instrumentation, library instrumentation, or zero code instrumentation (i.e. bytecode instrumentation that would also require running the OpenTelemetry Java agent).
76+
77+
Depending on the OpenTelemetry Span `SpanKind`, it may result in the New Relic Java agent starting a transaction (when one doesn't already exist).
78+
79+
* `SpanKind.INTERNAL`
80+
* Creating a span with no `SpanKind`, which defaults to `SpanKind.INTERNAL`, will not start a transaction
81+
* If `SpanKind.INTERNAL` spans occur within an already existing New Relic transaction they will be included in the trace
82+
* `SpanKind.CLIENT`
83+
* Creating a span with `SpanKind.CLIENT` will not start a transaction. If a `CLIENT` span has certain db attributes it will be treated as a DB span, and other specific attributes will cause it to be treated as an external span
84+
* If `SpanKind.CLIENT` spans occur within an already existing New Relic transaction they will be included in the trace
85+
* `SpanKind.SERVER`
86+
* Creating a span with `SpanKind.SERVER` will start a `WebTransaction/Uri/*` transaction.
87+
* If `SpanKind.SERVER` spans occur within an already existing New Relic transaction they will be included in the trace
88+
* `SpanKind.CONSUMER`
89+
* Creating a span with `SpanKind.CONSUMER` will start a `OtherTransaction/*` transaction.
90+
* If `SpanKind.CONSUMER` spans occur within an already existing New Relic transaction they will be included in the trace
91+
* `SpanKind.PRODUCER`
92+
* Creating a span with `SpanKind.PRODUCER` will not start a transaction. There is no explicit processing for `PRODUCER` spans currently.
93+
* If `SpanKind.PRODUCER` spans occur within an already existing New Relic transaction they will be included in the trace (though it's effectively no different from a `SpanKind.INTERNAL` span)

0 commit comments

Comments
 (0)