Skip to content

Commit 6a18b7e

Browse files
committed
Incorporate ErrorApi
1 parent 87c5739 commit 6a18b7e

File tree

5 files changed

+30
-14
lines changed

5 files changed

+30
-14
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ public Map<String, String> getLinkingMetadata() {
7878
return Collections.emptyMap();
7979
}
8080

81+
@Override
8182
public OpenTelemetryErrorApi getErrorApi() {
8283
return OpenTelemetryErrorApi.getInstance();
8384
}

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,22 @@
11
package com.newrelic.opentelemetry;
22

3+
import com.newrelic.api.agent.ErrorApi;
4+
import com.newrelic.api.agent.ErrorGroupCallback;
35
import io.opentelemetry.api.common.AttributeKey;
46
import io.opentelemetry.api.common.Attributes;
57
import io.opentelemetry.api.trace.Span;
68
import io.opentelemetry.api.trace.StatusCode;
79

810
import java.util.Map;
911

12+
import static com.newrelic.opentelemetry.OpenTelemetryNewRelic.logUnsupportedMethod;
13+
1014
/**
1115
* Note class is public because it is accessed from package
1216
* {@code com.newrelic.api.agent} after {@link com.newrelic.api.agent.NewRelic}
1317
* is rewritten.
1418
*/
15-
public final class OpenTelemetryErrorApi {
19+
public final class OpenTelemetryErrorApi implements ErrorApi {
1620

1721
private static final OpenTelemetryErrorApi INSTANCE = new OpenTelemetryErrorApi();
1822

@@ -27,41 +31,54 @@ static OpenTelemetryErrorApi getInstance() {
2731
return INSTANCE;
2832
}
2933

34+
@Override
3035
public void noticeError(Throwable throwable, Map<String, ?> params) {
3136
noticeError(throwable, params, false);
3237
}
3338

39+
@Override
3440
public void noticeError(Throwable throwable) {
3541
noticeError(throwable, false);
3642
}
3743

44+
@Override
3845
public void noticeError(String message, Map<String, ?> params) {
3946
noticeError(new ReportedError(message), params);
4047
}
4148

49+
@Override
4250
public void noticeError(String message) {
4351
noticeError(new ReportedError(message));
4452
}
4553

54+
@Override
4655
public void noticeError(Throwable throwable, Map<String, ?> params, boolean expected) {
4756
Attributes attributes = OpenTelemetryNewRelic.toAttributes(params).putAll(expected ? EXPECTED_ERROR_ATTRIBUTES : UNEXPECTED_ERROR_ATTRIBUTES).build();
4857
Span.current().recordException(throwable, attributes);
4958
Span.current().setStatus(StatusCode.ERROR);
5059
}
5160

61+
@Override
5262
public void noticeError(Throwable throwable, boolean expected) {
5363
Span.current().recordException(throwable, expected ? EXPECTED_ERROR_ATTRIBUTES : UNEXPECTED_ERROR_ATTRIBUTES);
5464
Span.current().setStatus(StatusCode.ERROR);
5565
}
5666

67+
@Override
5768
public void noticeError(String message, Map<String, ?> params, boolean expected) {
5869
noticeError(new ReportedError(message), params, expected);
5970
}
6071

72+
@Override
6173
public void noticeError(String message, boolean expected) {
6274
noticeError(new ReportedError(message), expected);
6375
}
6476

77+
@Override
78+
public void setErrorGroupCallback(ErrorGroupCallback errorGroupCallback) {
79+
logUnsupportedMethod("ErrorApi", "setErrorGroupCallback");
80+
}
81+
6582
private static class ReportedError extends Exception {
6683
private ReportedError(String message) {
6784
super(message);

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

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ public static Agent getAgent() {
2525
return AGENT_REF.get();
2626
}
2727

28-
static OpenTelemetryAgent getOpenTelemetryAgent() {
29-
return AGENT_REF.get();
30-
}
31-
3228
// Visible for testing
3329
public static void resetForTest() {
3430
AGENT_REF.set(NOOP_AGENT);
@@ -59,35 +55,35 @@ public static void incrementCounter(String name, int count) {
5955
// ************************** Error API ***********************************//
6056

6157
public static void noticeError(Throwable throwable, Map<String, ?> params) {
62-
getOpenTelemetryAgent().getErrorApi().noticeError(throwable, params);
58+
getAgent().getErrorApi().noticeError(throwable, params);
6359
}
6460

6561
public static void noticeError(Throwable throwable) {
66-
getOpenTelemetryAgent().getErrorApi().noticeError(throwable);
62+
getAgent().getErrorApi().noticeError(throwable);
6763
}
6864

6965
public static void noticeError(String message, Map<String, ?> params) {
70-
getOpenTelemetryAgent().getErrorApi().noticeError(message, params);
66+
getAgent().getErrorApi().noticeError(message, params);
7167
}
7268

7369
public static void noticeError(String message) {
74-
getOpenTelemetryAgent().getErrorApi().noticeError(message);
70+
getAgent().getErrorApi().noticeError(message);
7571
}
7672

7773
public static void noticeError(Throwable throwable, Map<String, ?> params, boolean expected) {
78-
getOpenTelemetryAgent().getErrorApi().noticeError(throwable, params, expected);
74+
getAgent().getErrorApi().noticeError(throwable, params, expected);
7975
}
8076

8177
public static void noticeError(Throwable throwable, boolean expected) {
82-
getOpenTelemetryAgent().getErrorApi().noticeError(throwable, expected);
78+
getAgent().getErrorApi().noticeError(throwable, expected);
8379
}
8480

8581
public static void noticeError(String message, Map<String, ?> params, boolean expected) {
86-
getOpenTelemetryAgent().getErrorApi().noticeError(message, params, expected);
82+
getAgent().getErrorApi().noticeError(message, params, expected);
8783
}
8884

8985
public static void noticeError(String message, boolean expected) {
90-
getOpenTelemetryAgent().getErrorApi().noticeError(message, expected);
86+
getAgent().getErrorApi().noticeError(message, expected);
9187
}
9288

9389
// **************************** Transaction APIs ********************************//
@@ -179,7 +175,7 @@ public static void setInstanceName(String instanceName) {
179175
}
180176

181177
public static void setErrorGroupCallback(ErrorGroupCallback errorGroupCallback) {
182-
logUnsupportedMethod("NewRelic", "setErrorGroupCallback");
178+
getAgent().getErrorApi().setErrorGroupCallback(errorGroupCallback);
183179
}
184180

185181
static void logUnsupportedMethod(String className, String methodName) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import static org.assertj.core.api.Assertions.assertThat;
3939
import static org.assertj.core.api.Assertions.assertThatCode;
4040

41+
@SuppressWarnings("deprecation")
4142
class NewRelicApiCompatibilityTest {
4243

4344
private static final ExtendedRequest DUMMY_REQUEST = new ExtendedRequestImpl();

newrelic-opentelemetry-agent-extension/src/testAgentExtension/java/com/newrelic/api/agent/opentelemetry/OpenTelemetryAgentExtensionSmokeTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
import static org.assertj.core.api.Assertions.assertThat;
3434

35+
@SuppressWarnings("deprecation")
3536
class OpenTelemetryAgentExtensionSmokeTest {
3637

3738
private static final ExtendedRequest DUMMY_REQUEST = new ExtendedRequestImpl();

0 commit comments

Comments
 (0)