Skip to content

Cancelled status code not reported in the gRPC server metrics #5109

@ceremo

Description

@ceremo

Hi,

cancelled status codes are not reported in the gRPC server metrics, metrics in these cases are reported without the tag status code because GrpcServerObservationContext is not updated with the cancelled. For us it's important the gRPC server metric give us info of the status codes, and this could be improved for example modifying the onCancel method of the ObservationGrpcServerCallListener before running the stop operation, something like this:

  @Override
  public void onCancel() {
    try (final Scope scope = this.observation.openScope()) {
      super.onCancel();
    } finally {
      if (this.observation.getContext() instanceof final GrpcServerObservationContext obsCtx) {
        obsCtx.setStatusCode(Status.Code.CANCELLED);
      }
      this.observation.stop();
    }
  }

I have created a demo to reproduce easily cancelleds, the service has a delay of 5 seconds to give time to the client to cancel the request, you could make the call using postman or a simple grpc client with a deadline lower than 5 seconds.

Thanks for your time.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions