Skip to content

Commit 7972e68

Browse files
committed
move client instrumentation from library to javaagent
1 parent c5f1862 commit 7972e68

File tree

14 files changed

+149
-99
lines changed

14 files changed

+149
-99
lines changed
+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
package io.opentelemetry.instrumentation.jsonrpc4j.v1_3;
6+
package io.opentelemetry.javaagent.instrumentation.jsonrpc4j.v1_3;
77

88
import io.opentelemetry.api.common.AttributeKey;
99
import io.opentelemetry.api.common.AttributesBuilder;
+2-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
package io.opentelemetry.instrumentation.jsonrpc4j.v1_3;
6+
package io.opentelemetry.javaagent.instrumentation.jsonrpc4j.v1_3;
77

88
import io.opentelemetry.instrumentation.api.incubator.semconv.rpc.RpcAttributesGetter;
99

@@ -23,7 +23,7 @@ public String getService(JsonRpcClientRequest request) {
2323
if (request.getMethod() != null) {
2424
return request.getMethod().getDeclaringClass().getName();
2525
}
26-
return "NOT_AVAILABLE";
26+
return null;
2727
}
2828

2929
@Override

instrumentation/jsonrpc4j-1.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsonrpc4j/v1_3/JsonRpcClientInstrumentation.java

-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616

1717
import io.opentelemetry.context.Context;
1818
import io.opentelemetry.context.Scope;
19-
import io.opentelemetry.instrumentation.jsonrpc4j.v1_3.JsonRpcClientRequest;
20-
import io.opentelemetry.instrumentation.jsonrpc4j.v1_3.JsonRpcClientResponse;
2119
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
2220
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
2321
import java.lang.reflect.Type;

instrumentation/jsonrpc4j-1.3/library/src/main/java/io/opentelemetry/instrumentation/jsonrpc4j/v1_3/JsonRpcClientRequest.java instrumentation/jsonrpc4j-1.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsonrpc4j/v1_3/JsonRpcClientRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
package io.opentelemetry.instrumentation.jsonrpc4j.v1_3;
6+
package io.opentelemetry.javaagent.instrumentation.jsonrpc4j.v1_3;
77

88
import java.lang.reflect.Method;
99

instrumentation/jsonrpc4j-1.3/library/src/main/java/io/opentelemetry/instrumentation/jsonrpc4j/v1_3/JsonRpcClientResponse.java instrumentation/jsonrpc4j-1.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsonrpc4j/v1_3/JsonRpcClientResponse.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
package io.opentelemetry.instrumentation.jsonrpc4j.v1_3;
6+
package io.opentelemetry.javaagent.instrumentation.jsonrpc4j.v1_3;
77

88
public final class JsonRpcClientResponse {
99

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6-
package io.opentelemetry.instrumentation.jsonrpc4j.v1_3;
6+
package io.opentelemetry.javaagent.instrumentation.jsonrpc4j.v1_3;
77

88
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
99
import java.lang.reflect.Method;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.javaagent.instrumentation.jsonrpc4j.v1_3;
7+
8+
import io.opentelemetry.api.OpenTelemetry;
9+
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
10+
11+
public final class JsonRpcClientTelemetry {
12+
public static JsonRpcClientTelemetry create(OpenTelemetry openTelemetry) {
13+
return builder(openTelemetry).build();
14+
}
15+
16+
public static JsonRpcClientTelemetryBuilder builder(OpenTelemetry openTelemetry) {
17+
return new JsonRpcClientTelemetryBuilder(openTelemetry);
18+
}
19+
20+
private final Instrumenter<JsonRpcClientRequest, JsonRpcClientResponse> clientInstrumenter;
21+
22+
JsonRpcClientTelemetry(
23+
Instrumenter<JsonRpcClientRequest, JsonRpcClientResponse> clientInstrumenter) {
24+
this.clientInstrumenter = clientInstrumenter;
25+
}
26+
27+
public Instrumenter<JsonRpcClientRequest, JsonRpcClientResponse> getClientInstrumenter() {
28+
return clientInstrumenter;
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.javaagent.instrumentation.jsonrpc4j.v1_3;
7+
8+
import com.google.errorprone.annotations.CanIgnoreReturnValue;
9+
import io.opentelemetry.api.OpenTelemetry;
10+
import io.opentelemetry.instrumentation.api.incubator.semconv.rpc.RpcClientAttributesExtractor;
11+
import io.opentelemetry.instrumentation.api.incubator.semconv.rpc.RpcClientMetrics;
12+
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
13+
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
14+
import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder;
15+
import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor;
16+
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
17+
import java.util.ArrayList;
18+
import java.util.List;
19+
20+
public class JsonRpcClientTelemetryBuilder {
21+
22+
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.jsonrpc4j-1.3";
23+
24+
private final OpenTelemetry openTelemetry;
25+
26+
private final List<
27+
AttributesExtractor<? super JsonRpcClientRequest, ? super JsonRpcClientResponse>>
28+
additionalClientExtractors = new ArrayList<>();
29+
30+
JsonRpcClientTelemetryBuilder(OpenTelemetry openTelemetry) {
31+
this.openTelemetry = openTelemetry;
32+
}
33+
34+
/**
35+
* Adds an extra client-only {@link AttributesExtractor} to invoke to set attributes to
36+
* instrumented items. The {@link AttributesExtractor} will be executed after all default
37+
* extractors.
38+
*/
39+
@CanIgnoreReturnValue
40+
public JsonRpcClientTelemetryBuilder addClientAttributeExtractor(
41+
AttributesExtractor<? super JsonRpcClientRequest, ? super JsonRpcClientResponse>
42+
attributesExtractor) {
43+
additionalClientExtractors.add(attributesExtractor);
44+
return this;
45+
}
46+
47+
public JsonRpcClientTelemetry build() {
48+
SpanNameExtractor<JsonRpcClientRequest> clientSpanNameExtractor =
49+
new JsonRpcClientSpanNameExtractor();
50+
51+
InstrumenterBuilder<JsonRpcClientRequest, JsonRpcClientResponse> clientInstrumenterBuilder =
52+
Instrumenter.builder(openTelemetry, INSTRUMENTATION_NAME, clientSpanNameExtractor);
53+
54+
JsonRpcClientAttributesGetter clientRpcAttributesGetter =
55+
JsonRpcClientAttributesGetter.INSTANCE;
56+
57+
clientInstrumenterBuilder
58+
.addAttributesExtractor(RpcClientAttributesExtractor.create(clientRpcAttributesGetter))
59+
.addAttributesExtractors(additionalClientExtractors)
60+
.addAttributesExtractor(new JsonRpcClientAttributesExtractor())
61+
.addOperationMetrics(RpcClientMetrics.get());
62+
63+
return new JsonRpcClientTelemetry(
64+
clientInstrumenterBuilder.buildInstrumenter(SpanKindExtractor.alwaysClient()));
65+
}
66+
}

instrumentation/jsonrpc4j-1.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsonrpc4j/v1_3/JsonRpcProxyInstrumentation.java

-2
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
import com.googlecode.jsonrpc4j.IJsonRpcClient;
1616
import io.opentelemetry.context.Context;
1717
import io.opentelemetry.context.Scope;
18-
import io.opentelemetry.instrumentation.jsonrpc4j.v1_3.JsonRpcClientRequest;
19-
import io.opentelemetry.instrumentation.jsonrpc4j.v1_3.JsonRpcClientResponse;
2018
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
2119
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
2220
import java.lang.reflect.InvocationHandler;

instrumentation/jsonrpc4j-1.3/javaagent/src/main/java/io/opentelemetry/javaagent/instrumentation/jsonrpc4j/v1_3/JsonRpcSingletons.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
import com.googlecode.jsonrpc4j.InvocationListener;
99
import io.opentelemetry.api.GlobalOpenTelemetry;
1010
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
11-
import io.opentelemetry.instrumentation.jsonrpc4j.v1_3.JsonRpcClientRequest;
12-
import io.opentelemetry.instrumentation.jsonrpc4j.v1_3.JsonRpcClientResponse;
13-
import io.opentelemetry.instrumentation.jsonrpc4j.v1_3.JsonRpcTelemetry;
11+
import io.opentelemetry.instrumentation.jsonrpc4j.v1_3.JsonRpcServerTelemetry;
1412

1513
public final class JsonRpcSingletons {
1614

@@ -19,10 +17,13 @@ public final class JsonRpcSingletons {
1917
public static final Instrumenter<JsonRpcClientRequest, JsonRpcClientResponse> CLIENT_INSTRUMENTER;
2018

2119
static {
22-
JsonRpcTelemetry telemetry = JsonRpcTelemetry.builder(GlobalOpenTelemetry.get()).build();
20+
JsonRpcServerTelemetry serverTelemetry =
21+
JsonRpcServerTelemetry.builder(GlobalOpenTelemetry.get()).build();
22+
JsonRpcClientTelemetry clientTelemetry =
23+
JsonRpcClientTelemetry.builder(GlobalOpenTelemetry.get()).build();
2324

24-
SERVER_INVOCATION_LISTENER = telemetry.newServerInvocationListener();
25-
CLIENT_INSTRUMENTER = telemetry.getClientInstrumenter();
25+
SERVER_INVOCATION_LISTENER = serverTelemetry.newServerInvocationListener();
26+
CLIENT_INSTRUMENTER = clientTelemetry.getClientInstrumenter();
2627
}
2728

2829
private JsonRpcSingletons() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
package io.opentelemetry.instrumentation.jsonrpc4j.v1_3;
7+
8+
import com.googlecode.jsonrpc4j.InvocationListener;
9+
import io.opentelemetry.api.OpenTelemetry;
10+
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
11+
12+
public final class JsonRpcServerTelemetry {
13+
public static JsonRpcServerTelemetry create(OpenTelemetry openTelemetry) {
14+
return builder(openTelemetry).build();
15+
}
16+
17+
public static JsonRpcServerTelemetryBuilder builder(OpenTelemetry openTelemetry) {
18+
return new JsonRpcServerTelemetryBuilder(openTelemetry);
19+
}
20+
21+
private final Instrumenter<JsonRpcServerRequest, JsonRpcServerResponse> serverInstrumenter;
22+
23+
JsonRpcServerTelemetry(
24+
Instrumenter<JsonRpcServerRequest, JsonRpcServerResponse> serverInstrumenter) {
25+
this.serverInstrumenter = serverInstrumenter;
26+
}
27+
28+
public InvocationListener newServerInvocationListener() {
29+
return new OpenTelemetryJsonRpcInvocationListener(serverInstrumenter);
30+
}
31+
}
+6-40
Original file line numberDiff line numberDiff line change
@@ -7,83 +7,51 @@
77

88
import com.google.errorprone.annotations.CanIgnoreReturnValue;
99
import io.opentelemetry.api.OpenTelemetry;
10-
import io.opentelemetry.instrumentation.api.incubator.semconv.rpc.RpcClientAttributesExtractor;
11-
import io.opentelemetry.instrumentation.api.incubator.semconv.rpc.RpcClientMetrics;
1210
import io.opentelemetry.instrumentation.api.incubator.semconv.rpc.RpcServerAttributesExtractor;
1311
import io.opentelemetry.instrumentation.api.incubator.semconv.rpc.RpcServerMetrics;
1412
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
1513
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
1614
import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder;
17-
import io.opentelemetry.instrumentation.api.instrumenter.SpanKindExtractor;
1815
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
1916
import java.util.ArrayList;
2017
import java.util.List;
2118

22-
public class JsonRpcTelemetryBuilder {
19+
public class JsonRpcServerTelemetryBuilder {
2320

2421
private static final String INSTRUMENTATION_NAME = "io.opentelemetry.jsonrpc4j-1.3";
2522

2623
private final OpenTelemetry openTelemetry;
2724

28-
private final List<
29-
AttributesExtractor<? super JsonRpcClientRequest, ? super JsonRpcClientResponse>>
30-
additionalClientExtractors = new ArrayList<>();
3125
private final List<
3226
AttributesExtractor<? super JsonRpcServerRequest, ? super JsonRpcServerResponse>>
3327
additionalServerExtractors = new ArrayList<>();
3428

35-
JsonRpcTelemetryBuilder(OpenTelemetry openTelemetry) {
29+
JsonRpcServerTelemetryBuilder(OpenTelemetry openTelemetry) {
3630
this.openTelemetry = openTelemetry;
3731
}
3832

39-
/**
40-
* Adds an extra client-only {@link AttributesExtractor} to invoke to set attributes to
41-
* instrumented items. The {@link AttributesExtractor} will be executed after all default
42-
* extractors.
43-
*/
44-
@CanIgnoreReturnValue
45-
public JsonRpcTelemetryBuilder addClientAttributeExtractor(
46-
AttributesExtractor<? super JsonRpcClientRequest, ? super JsonRpcClientResponse>
47-
attributesExtractor) {
48-
additionalClientExtractors.add(attributesExtractor);
49-
return this;
50-
}
51-
5233
/**
5334
* Adds an extra server-only {@link AttributesExtractor} to invoke to set attributes to
5435
* instrumented items. The {@link AttributesExtractor} will be executed after all default
5536
* extractors.
5637
*/
5738
@CanIgnoreReturnValue
58-
public JsonRpcTelemetryBuilder addServerAttributeExtractor(
39+
public JsonRpcServerTelemetryBuilder addServerAttributeExtractor(
5940
AttributesExtractor<? super JsonRpcServerRequest, ? super JsonRpcServerResponse>
6041
attributesExtractor) {
6142
additionalServerExtractors.add(attributesExtractor);
6243
return this;
6344
}
6445

65-
public JsonRpcTelemetry build() {
66-
SpanNameExtractor<JsonRpcClientRequest> clientSpanNameExtractor =
67-
new JsonRpcClientSpanNameExtractor();
46+
public JsonRpcServerTelemetry build() {
6847
SpanNameExtractor<JsonRpcServerRequest> serverSpanNameExtractor =
6948
new JsonRpcServerSpanNameExtractor();
7049

71-
InstrumenterBuilder<JsonRpcClientRequest, JsonRpcClientResponse> clientInstrumenterBuilder =
72-
Instrumenter.builder(openTelemetry, INSTRUMENTATION_NAME, clientSpanNameExtractor);
73-
7450
InstrumenterBuilder<JsonRpcServerRequest, JsonRpcServerResponse> serverInstrumenterBuilder =
7551
Instrumenter.builder(openTelemetry, INSTRUMENTATION_NAME, serverSpanNameExtractor);
7652

7753
JsonRpcServerAttributesGetter serverRpcAttributesGetter =
7854
JsonRpcServerAttributesGetter.INSTANCE;
79-
JsonRpcClientAttributesGetter clientRpcAttributesGetter =
80-
JsonRpcClientAttributesGetter.INSTANCE;
81-
82-
clientInstrumenterBuilder
83-
.addAttributesExtractor(RpcClientAttributesExtractor.create(clientRpcAttributesGetter))
84-
.addAttributesExtractors(additionalClientExtractors)
85-
.addAttributesExtractor(new JsonRpcClientAttributesExtractor())
86-
.addOperationMetrics(RpcClientMetrics.get());
8755

8856
serverInstrumenterBuilder
8957
.setSpanStatusExtractor(JsonRpcServerSpanStatusExtractor.INSTANCE)
@@ -92,9 +60,7 @@ public JsonRpcTelemetry build() {
9260
.addAttributesExtractors(additionalServerExtractors)
9361
.addOperationMetrics(RpcServerMetrics.get());
9462

95-
return new JsonRpcTelemetry(
96-
serverInstrumenterBuilder.buildServerInstrumenter(JsonRpcServerRequestGetter.INSTANCE),
97-
clientInstrumenterBuilder.buildInstrumenter(SpanKindExtractor.alwaysClient()),
98-
openTelemetry.getPropagators());
63+
return new JsonRpcServerTelemetry(
64+
serverInstrumenterBuilder.buildServerInstrumenter(JsonRpcServerRequestGetter.INSTANCE));
9965
}
10066
}

instrumentation/jsonrpc4j-1.3/library/src/main/java/io/opentelemetry/instrumentation/jsonrpc4j/v1_3/JsonRpcTelemetry.java

-42
This file was deleted.

instrumentation/jsonrpc4j-1.3/library/src/test/java/io/opentelemetry/instrumentation/jsonrpc4j/v1_3/LibraryJsonRpcTest.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ protected InstrumentationExtension testing() {
2323
@Override
2424
protected JsonRpcBasicServer configureServer(JsonRpcBasicServer server) {
2525
server.setInvocationListener(
26-
JsonRpcTelemetry.builder(testing.getOpenTelemetry()).build().newServerInvocationListener());
26+
JsonRpcServerTelemetry.builder(testing.getOpenTelemetry())
27+
.build()
28+
.newServerInvocationListener());
2729
return server;
2830
}
2931
}

0 commit comments

Comments
 (0)