Skip to content

Commit

Permalink
server span name follow convention
Browse files Browse the repository at this point in the history
  • Loading branch information
chenlujjj committed Jan 8, 2025
1 parent a5e1a43 commit 6f50140
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,13 @@
package io.opentelemetry.instrumentation.jsonrpc4j.v1_6;

import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;
import java.lang.reflect.Method;

public class JsonRpcServerSpanNameExtractor implements SpanNameExtractor<JsonRpcRequest> {
// Follow https://opentelemetry.io/docs/specs/semconv/rpc/rpc-spans/#span-name
@Override
public String extract(JsonRpcRequest request) {
return request.getMethod().getName();
Method method = request.getMethod();
return String.format("%s/%s", method.getDeclaringClass().getName(), method.getName());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,16 @@ void testServer() throws IOException {
trace.hasSpansSatisfyingExactly(
span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(),
span ->
span.hasName("add")
span.hasName(
"io.opentelemetry.instrumentation.jsonrpc4j.v1_6.CalculatorService/add")
.hasKind(SpanKind.SERVER)
.hasParent(trace.getSpan(0))
.hasAttributesSatisfyingExactly(
equalTo(RPC_SYSTEM, "jsonrpc"),
equalTo(RPC_JSONRPC_VERSION, "2.0"),
equalTo(RPC_SERVICE, "/calculator"),
equalTo(
RPC_SERVICE,
"io.opentelemetry.instrumentation.jsonrpc4j.v1_6.CalculatorService"),
equalTo(RPC_METHOD, "add"),
equalTo(RPC_JSONRPC_ERROR_CODE, 0L))));
testing()
Expand All @@ -90,7 +93,9 @@ void testServer() throws IOException {
point ->
point.hasAttributesSatisfying(
equalTo(RPC_METHOD, "add"),
equalTo(RPC_SERVICE, "/calculator"),
equalTo(
RPC_SERVICE,
"io.opentelemetry.instrumentation.jsonrpc4j.v1_6.CalculatorService"),
equalTo(RPC_SYSTEM, "jsonrpc"))))));
}
}

0 comments on commit 6f50140

Please sign in to comment.