Skip to content

Commit 2cf58ea

Browse files
committed
PR feedback
1 parent 6a18b7e commit 2cf58ea

File tree

4 files changed

+51
-11
lines changed

4 files changed

+51
-11
lines changed

newrelic-opentelemetry-agent-extension/README.md

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,48 @@ will need to download the New Relic OpenTelemetry Agent extension, which is publ
3131
**IMPORTANT**: This package is marked "-alpha". All APIs and behaviors are subject to change. Please use with caution and be sure to check the release notes for
3232
changes before upgrading.
3333

34-
Calls to the [Java agent API](https://docs.newrelic.com/docs/apm/agents/java-agent/api-guides/guide-using-java-agent-api/) API will be routed through the
34+
See [OpenTelemetry Java Getting started guide](https://docs.newrelic.com/docs/more-integrations/open-source-telemetry-integrations/opentelemetry/get-started/opentelemetry-tutorial-java/)
35+
for information on configuring the OpenTelemetry Java agent to export to New Relic.
36+
37+
## Supported Operations
38+
39+
Calls to the [Java agent API](https://docs.newrelic.com/docs/apm/agents/java-agent/api-guides/guide-using-java-agent-api/) will be routed through the
3540
OpenTelemetry API. Note that many concepts of the New Relic API do not map to an equivalent in the OpenTelemetry API. When an API is called which is not bridged
3641
to OpenTelemetry, the extension will log details from logger named `com.newrelic.opentelemetry.OpenTelemetryNewRelic` at `FINER` level (if `FINEST` level is
3742
enabled, a stacktrace to the calling code is included).
3843

39-
TODO: add table defining which NewRelic APIs are supported and describe the behavior of each
44+
The following operations are supported:
4045

41-
See [OpenTelemetry Java Getting started guide](https://docs.newrelic.com/docs/more-integrations/open-source-telemetry-integrations/opentelemetry/get-started/opentelemetry-tutorial-java/)
42-
for information on configuring the OpenTelemetry Java agent to export to New Relic.
46+
* NewRelic Metric APIs for recording custom timeslice metrics. Record to OpenTelemetry dimensional metrics, where the name of the metric is `newrelic.timeslice.value` for `recordMetric`, `recordResponseTimeMetric`, and `newrelic.timeslice.counter.value` for `incrementCounter`. The name of timeslice metric is set to the value of a dimension on metric with key `metricTimesliceName`.
47+
* `NewRelic.recordMetric(String, float)`
48+
* `NewRelic.recordResponseTimeMetric(String, long)`
49+
* `NewRelic.incrementCounter(String)`
50+
* `NewRelic.incrementCounter(String, int)`
51+
* `MetricAggregator.recordMetric(String, float)`
52+
* `MetricAggregator.recordResponseTimeMetric(String, long)`
53+
* `MetricAggregator.incrementCounter(String)`
54+
* `MetricAggregator.incrementCounter(String, int)`
55+
* NewRelic Error APIs for recording errors. Record the error on whatever OpenTelemetry span is currently active (i.e. `Span.current()`) using `recordException`. Sets the active span status to `ERROR`.
56+
* `NewRelic.noticeError(Throwable, Map<String, ?>)`
57+
* `NewRelic.noticeError(Throwable)`
58+
* `NewRelic.noticeError(String, Map<String, ?>)`
59+
* `NewRelic.noticeError(String)`
60+
* `NewRelic.noticeError(Throwable, Map<String, ?>, boolean)`
61+
* `NewRelic.noticeError(Throwable, boolean)`
62+
* `NewRelic.noticeError(String, Map<String, ?>, boolean)`
63+
* `NewRelic.noticeError(String, boolean)`
64+
* `ErrorApi.noticeError(Throwable, Map<String, ?>)`
65+
* `ErrorApi.noticeError(Throwable)`
66+
* `ErrorApi.noticeError(String, Map<String, ?>)`
67+
* `ErrorApi.noticeError(String)`
68+
* `ErrorApi.noticeError(Throwable, Map<String, ?>, boolean)`
69+
* `ErrorApi.noticeError(Throwable, boolean)`
70+
* `ErrorApi.noticeError(String, Map<String, ?>, boolean)`
71+
* `ErrorApi.noticeError(String, boolean)`
72+
* NewRelic TracedMethod APIs for adding custom attributes. Record the custom attributes to whatever OpenTelemetry span is currently active (i.e. `Span.current()`).
73+
* `TracedMethod.addCustomAttribute(String, Number)`
74+
* `TracedMethod.addCustomAttribute(String, Strg)`
75+
* `TracedMethod.addCustomAttribute(String, boolean)`
76+
* `TracedMethod.addCustomAttributes(Map<String, Object>)`
77+
* NewRelic Insights API for recording custom events. Record the event as an OpenTelemetry LogRecord following the [semantic conventions for events](https://github.com/open-telemetry/semantic-conventions/blob/main/docs/general/events.md). The `event.domain` is set to `newrelic.agent_api`, the `event.name` is set to the name of the custom event.
78+
* `Insights.recordCustomEvent(String, Map<String, ?>)`

newrelic-opentelemetry-agent-extension/src/main/java/com/newrelic/opentelemetry/OpenTelemetryInsights.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
final class OpenTelemetryInsights implements Insights {
1212

13+
private static final String NEW_RELIC_AGENT_API_DOMAIN = "newrelic.agent_api";
1314
private final io.opentelemetry.api.logs.Logger logger;
1415

1516
private OpenTelemetryInsights(OpenTelemetry openTelemetry) {
@@ -24,7 +25,7 @@ static OpenTelemetryInsights create(OpenTelemetry openTelemetry) {
2425
public void recordCustomEvent(String eventType, Map<String, ?> attributesMap) {
2526
Attributes attributes = OpenTelemetryNewRelic.toAttributes(attributesMap)
2627
// TODO: is this the right domain?
27-
.put(SemanticAttributes.EVENT_DOMAIN, "newrelic.api")
28+
.put(SemanticAttributes.EVENT_DOMAIN, NEW_RELIC_AGENT_API_DOMAIN)
2829
.put(SemanticAttributes.EVENT_NAME, eventType)
2930
.build();
3031
// TODO: use event API when stable. For now, its not possible to without taking

newrelic-opentelemetry-agent-extension/src/main/java/com/newrelic/opentelemetry/OpenTelemetryNewRelic.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.newrelic.api.agent.ErrorGroupCallback;
55
import com.newrelic.api.agent.Request;
66
import com.newrelic.api.agent.Response;
7+
import com.newrelic.api.agent.TransactionNamePriority;
78
import io.opentelemetry.api.OpenTelemetry;
89
import io.opentelemetry.api.common.AttributesBuilder;
910

@@ -86,6 +87,10 @@ public static void noticeError(String message, boolean expected) {
8687
getAgent().getErrorApi().noticeError(message, expected);
8788
}
8889

90+
public static void setErrorGroupCallback(ErrorGroupCallback errorGroupCallback) {
91+
getAgent().getErrorApi().setErrorGroupCallback(errorGroupCallback);
92+
}
93+
8994
// **************************** Transaction APIs ********************************//
9095

9196
public static void addCustomParameter(String key, Number value) {
@@ -109,11 +114,11 @@ public static void setUserId(String userId) {
109114
}
110115

111116
public static void setTransactionName(String category, String name) {
112-
logUnsupportedMethod("NewRelic", "setTransactionName");
117+
getAgent().getTransaction().setTransactionName(TransactionNamePriority.CUSTOM_LOW, true, category, name);
113118
}
114119

115120
public static void ignoreTransaction() {
116-
logUnsupportedMethod("NewRelic", "ignoreTransaction");
121+
getAgent().getTransaction().ignore();
117122
}
118123

119124
public static void ignoreApdex() {
@@ -174,9 +179,7 @@ public static void setInstanceName(String instanceName) {
174179
logUnsupportedMethod("NewRelic", "setInstanceName");
175180
}
176181

177-
public static void setErrorGroupCallback(ErrorGroupCallback errorGroupCallback) {
178-
getAgent().getErrorApi().setErrorGroupCallback(errorGroupCallback);
179-
}
182+
// Internal helpers
180183

181184
static void logUnsupportedMethod(String className, String methodName) {
182185
// If FINER or FINEST is enabled, indicate that an unsupported method was called.

newrelic-opentelemetry-agent-extension/src/test/java/com/newrelic/api/agent/opentelemetry/OpenTelemetryInsightsTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void recordCustomEvent() {
5252
assertThat(exporter.getFinishedLogRecordItems())
5353
.satisfiesExactly(logRecordData -> assertThat(logRecordData)
5454
.hasAttributesSatisfying(
55-
equalTo(AttributeKey.stringKey("event.domain"), "newrelic.api"),
55+
equalTo(AttributeKey.stringKey("event.domain"), "newrelic.agent_api"),
5656
equalTo(AttributeKey.stringKey("event.name"), "eventType"),
5757
satisfies(AttributeKey.doubleKey("double_key"), value -> value.isCloseTo(1.1, Offset.offset(0.01))),
5858
equalTo(AttributeKey.longKey("long_key"), 1),

0 commit comments

Comments
 (0)