Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ObservationGrpcServerCallListener does not capture an uncontrolled error during the execution of the service logic #4490

Closed
ceremo opened this issue Dec 11, 2023 · 13 comments

Comments

@ceremo
Copy link

ceremo commented Dec 11, 2023

The ObservationGrpcServerCallListener currently does not inform to the Observation object when an uncontrolled error occurs during the execution of the gRPC service logic. The current behavior does not allow to determine if an exception ocurred, so the generated metric cannot report accurately if the gRPC service failed.

In our gRPC services, errors can be generated as signals (next, completed, error...), but they can also occur as uncontrolled errors during service execution. What are your thoughts about this?

@ceremo
Copy link
Author

ceremo commented Dec 15, 2023

@ttddyy

@marcingrzejszczak
Copy link
Contributor

Do you have an example that replicates this problem so that we can look into it?

@marcingrzejszczak marcingrzejszczak added the waiting for feedback We need additional information before we can continue label Dec 28, 2023
Copy link

github-actions bot commented Jan 5, 2024

If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed.

@ceremo
Copy link
Author

ceremo commented Jan 10, 2024

No, but you only have to check the behaviour of the method onHalfClose defined in ObservationGrpcServerCallListener, when the grpc server fails with an unexpected error, the exception is captured but it does not pass the error to the observation:

  public void onHalfClose() {
        try (Scope scope = observation.openScope()) {
            super.onHalfClose();
        }
    }

Thxs for your time.

@marcingrzejszczak
Copy link
Contributor

@ttddyy so we would have to do this change and it will capture the exception?

From

public void onHalfClose() {
        try (Scope scope = observation.openScope()) {
            super.onHalfClose();
        }
    }

To

public void onHalfClose() {
        observation.scoped( () -> super.onHalfClose() );
    }

@marcingrzejszczak marcingrzejszczak removed waiting for feedback We need additional information before we can continue feedback-reminder labels Jan 10, 2024
@ttddyy
Copy link
Contributor

ttddyy commented Jan 14, 2024

Sorry for the late reply.
Yes, wrapping with scoped sounds good to me.

@marcingrzejszczak
Copy link
Contributor

@ceremo are you willing to this change? It's pretty straight-forward :)

@ceremo
Copy link
Author

ceremo commented Jan 23, 2024

Thanks @marcingrzejszczak. I would like your opinion in two improvements about the behaviour of the grpc observation:

  • ObservationGrpcServerInterceptor does not allow to customize the Supplier<GrpcServerObservationContext>, this could be useful in order to add extra information to the context.
  • DefaultGrpcServerObservationConvention only receives the metadata of the request, it would be useful to get the metadata of the response on the close execution, to do that the ObservationGrpcServerCall should set in the context the response metadata, like the status:
  @Override
  public void close(final Status status, final Metadata trailers) {
    if (status.getCause() != null) {
      this.observation.error(status.getCause());
    }

    final GrpcServerObservationContext context = (GrpcServerObservationContext) this.observation.getContext();
    context.setStatusCode(status.getCode());
    context.setCarrier(trailers); // HERE THE IMPROVEMENT
    super.close(status, trailers);
  }

Thanks for your time.

@marcingrzejszczak
Copy link
Contributor

ObservationGrpcServerInterceptor does not allow to customize the Supplier, this could be useful in order to add extra information to the context.

The ObservationConvention mechanism should be used to add extra information.

DefaultGrpcServerObservationConvention only receives the metadata of the request, it would be useful to get the metadata of the response on the close execution, to do that the ObservationGrpcServerCall should set in the context the response metadata, like the status:

We already are doing this.

@ceremo
Copy link
Author

ceremo commented Jan 23, 2024

The ObservationConvention mechanism should be used to add extra information.

Sorry, I don't get it, the ObservationConvention already receives the context fulfilled, and it is the grpc interceptor that is fullfilling it.

@marcingrzejszczak
Copy link
Contributor

You said that you want to add extra information to the context. What information exactly? Are you saying that you're missing some objects that the convention could later reuse ? Cause I understood that assuming that all the information got already provided you wanted to add more tags on the context in which case the ObservationConvention would be the way to go.

@ceremo
Copy link
Author

ceremo commented Jan 23, 2024

We need to include additional information to the GrpcServerObservationContext in order to convert it into additional tags in the generated metric. That extra information is included in the Metadata, so to include that in the context I have to define my own ObservationGrpcServerInterceptor because this does not allow customizing the contextSupplier. Finally the ObservationConvention load that additional information to include it as new tags.

What I'm trying to say it that allowing to customize the supplier context defined in the interceptor will facilitate our case, and could be useful to have it.

@marcingrzejszczak
Copy link
Contributor

It would be better IMO to prepare the context accordingly. If you think we're missing things in the context please file a PR that adds this data to the existing context.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants