Add grpc status code to metrics attrs
MODIFY
instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java
instrumentation-api-semconv/src/main/java/io/opentelemetry/instrumentation/api/instrumenter/rpc/MetricsView.java
@@ -30,6 +30,7 @@ final class MetricsView {
view.add(SemanticAttributes.RPC_SYSTEM);
view.add(SemanticAttributes.RPC_SERVICE);
view.add(SemanticAttributes.RPC_METHOD);
+ view.add(SemanticAttributes.RPC_GRPC_STATUS_CODE);
return view;
}

MODIFY
instrumentation/grpc-1.6/testing/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/AbstractGrpcStreamingTest.java
instrumentation/grpc-1.6/testing/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/AbstractGrpcStreamingTest.java
@@ -227,7 +227,10 @@ public abstract class AbstractGrpcStreamingTest {
equalTo(
SemanticAttributes.RPC_SERVICE,
"example.Greeter"),
- equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"))))));
+ equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"),
+ equalTo(
+ SemanticAttributes.RPC_GRPC_STATUS_CODE,
+ (long) Status.Code.OK.value()))))));
testing()
.waitAndAssertMetrics(
"io.opentelemetry.grpc-1.6",
@@ -253,7 +256,10 @@ public abstract class AbstractGrpcStreamingTest {
equalTo(
SemanticAttributes.RPC_SERVICE,
"example.Greeter"),
- equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"))))));
+ equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"),
+ equalTo(
+ SemanticAttributes.RPC_GRPC_STATUS_CODE,
+ (long) Status.Code.OK.value()))))));
}
private ManagedChannel createChannel(Server server) throws Exception {

MODIFY
instrumentation/grpc-1.6/testing/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/AbstractGrpcTest.java
instrumentation/grpc-1.6/testing/src/main/java/io/opentelemetry/instrumentation/grpc/v1_6/AbstractGrpcTest.java
@@ -217,7 +217,10 @@ public abstract class AbstractGrpcTest {
equalTo(
SemanticAttributes.RPC_SERVICE,
"example.Greeter"),
- equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"))))));
+ equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"),
+ equalTo(
+ SemanticAttributes.RPC_GRPC_STATUS_CODE,
+ (long) Status.Code.OK.value()))))));
testing()
.waitAndAssertMetrics(
"io.opentelemetry.grpc-1.6",
@@ -242,7 +245,10 @@ public abstract class AbstractGrpcTest {
equalTo(
SemanticAttributes.RPC_SERVICE,
"example.Greeter"),
- equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"))))));
+ equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"),
+ equalTo(
+ SemanticAttributes.RPC_GRPC_STATUS_CODE,
+ (long) Status.Code.OK.value()))))));
}
@Test
@@ -398,7 +404,10 @@ public abstract class AbstractGrpcTest {
equalTo(
SemanticAttributes.RPC_SERVICE,
"example.Greeter"),
- equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"))))));
+ equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"),
+ equalTo(
+ SemanticAttributes.RPC_GRPC_STATUS_CODE,
+ (long) Status.Code.OK.value()))))));
testing()
.waitAndAssertMetrics(
"io.opentelemetry.grpc-1.6",
@@ -423,7 +432,10 @@ public abstract class AbstractGrpcTest {
equalTo(
SemanticAttributes.RPC_SERVICE,
"example.Greeter"),
- equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"))))));
+ equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"),
+ equalTo(
+ SemanticAttributes.RPC_GRPC_STATUS_CODE,
+ (long) Status.Code.OK.value()))))));
}
@Test
@@ -587,7 +599,10 @@ public abstract class AbstractGrpcTest {
equalTo(
SemanticAttributes.RPC_SERVICE,
"example.Greeter"),
- equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"))))));
+ equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"),
+ equalTo(
+ SemanticAttributes.RPC_GRPC_STATUS_CODE,
+ (long) Status.Code.OK.value()))))));
testing()
.waitAndAssertMetrics(
"io.opentelemetry.grpc-1.6",
@@ -612,7 +627,10 @@ public abstract class AbstractGrpcTest {
equalTo(
SemanticAttributes.RPC_SERVICE,
"example.Greeter"),
- equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"))))));
+ equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"),
+ equalTo(
+ SemanticAttributes.RPC_GRPC_STATUS_CODE,
+ (long) Status.Code.OK.value()))))));
}
@ParameterizedTest
@@ -733,7 +751,10 @@ public abstract class AbstractGrpcTest {
equalTo(
SemanticAttributes.RPC_SERVICE,
"example.Greeter"),
- equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"))))));
+ equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"),
+ equalTo(
+ SemanticAttributes.RPC_GRPC_STATUS_CODE,
+ (long) status.getCode().value()))))));
testing()
.waitAndAssertMetrics(
"io.opentelemetry.grpc-1.6",
@@ -758,7 +779,10 @@ public abstract class AbstractGrpcTest {
equalTo(
SemanticAttributes.RPC_SERVICE,
"example.Greeter"),
- equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"))))));
+ equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"),
+ equalTo(
+ SemanticAttributes.RPC_GRPC_STATUS_CODE,
+ (long) status.getCode().value()))))));
}
@ParameterizedTest
@@ -880,7 +904,10 @@ public abstract class AbstractGrpcTest {
equalTo(
SemanticAttributes.RPC_SERVICE,
"example.Greeter"),
- equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"))))));
+ equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"),
+ equalTo(
+ SemanticAttributes.RPC_GRPC_STATUS_CODE,
+ (long) Status.Code.UNKNOWN.value()))))));
testing()
.waitAndAssertMetrics(
"io.opentelemetry.grpc-1.6",
@@ -905,7 +932,10 @@ public abstract class AbstractGrpcTest {
equalTo(
SemanticAttributes.RPC_SERVICE,
"example.Greeter"),
- equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"))))));
+ equalTo(SemanticAttributes.RPC_SYSTEM, "grpc"),
+ equalTo(
+ SemanticAttributes.RPC_GRPC_STATUS_CODE,
+ (long) Status.Code.UNKNOWN.value()))))));
}
static class ErrorProvider implements ArgumentsProvider {

Add grpc status code to metrics attrs (#6556)