Skip to content

Commit

Permalink
Add grpc status code to metrics attrs (open-telemetry#6556)
Browse files Browse the repository at this point in the history
  • Loading branch information
trask authored and LironKS committed Oct 23, 2022
1 parent 5cf6d85 commit e591ae3
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ private static Set<AttributeKey> buildAlwaysInclude() {
view.add(SemanticAttributes.RPC_SYSTEM);
view.add(SemanticAttributes.RPC_SERVICE);
view.add(SemanticAttributes.RPC_METHOD);
view.add(SemanticAttributes.RPC_GRPC_STATUS_CODE);
return view;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,10 @@ public void onCompleted() {
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",
Expand All @@ -253,7 +256,10 @@ public void onCompleted() {
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,10 @@ public void sayHello(
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",
Expand All @@ -242,7 +245,10 @@ public void sayHello(
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
Expand Down Expand Up @@ -398,7 +404,10 @@ public void sayHello(
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",
Expand All @@ -423,7 +432,10 @@ public void sayHello(
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
Expand Down Expand Up @@ -587,7 +599,10 @@ public void onCompleted() {
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",
Expand All @@ -612,7 +627,10 @@ public void onCompleted() {
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
Expand Down Expand Up @@ -733,7 +751,10 @@ public void sayHello(
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",
Expand All @@ -758,7 +779,10 @@ public void sayHello(
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
Expand Down Expand Up @@ -880,7 +904,10 @@ public void sayHello(
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",
Expand All @@ -905,7 +932,10 @@ public void sayHello(
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 {
Expand Down

0 comments on commit e591ae3

Please sign in to comment.