Skip to content

Conversation

@idelpivnitskiy
Copy link
Member

@idelpivnitskiy idelpivnitskiy commented Apr 15, 2025

Motivation:

Server-side GrpcRouter works as a translation layer from HTTP to gRPC and back. It logs all exceptions at DEBUG level, which makes it hard for users to notice when their endpoints throw exceptions.

Modifications:

  • Enhance GrpcRouter to log unexpected exceptions at ERROR level. Expected exceptions (GrpcStatusException, TimeoutException, and CancellationException) will still be logged at DEBUG level.

Result:

Easier to spot unexpected server-side exceptions from gRPC endpoints.

Motivation:

Server-side `GrpcRouter` works as a translation layer from HTTP to gRPC
and back. It logs all exceptions at `DEBUG` level, which makes it hard
for users to notice when their endpoints throw exceptions.

Modifications:

- Enhance `GrpcRouter` to log unexpected exceptions at `ERROR` level.
Expected exceptions (`GrpcStatusException`, TimeoutException`, and
`CancellationException`) will still be logged at `DEBUG` level.

Result:

Easier to spot unexpected server-side exceptions from gRPC endpoints.
Comment on lines 920 to 922
private static boolean shouldLogAsError(final Throwable error) {
return !(error instanceof GrpcStatusException) && GrpcStatusException.serverCatchAllShouldLog(error);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could reduce a lot of duplication if we do something like this:

Suggested change
private static boolean shouldLogAsError(final Throwable error) {
return !(error instanceof GrpcStatusException) && GrpcStatusException.serverCatchAllShouldLog(error);
}
private static boolean logException(String msg, MethodDescriptor<?, ?> methodDescriptor, Throwable error) {
boolean logAsError = !(error instanceof GrpcStatusException) && GrpcStatusException.serverCatchAllShouldLog(error);
if (logAsError) {
LOGGER.error(msg, methodDescriptor.httpPath(), t);
} else {
LOGGER.debug(msg, methodDescriptor.httpPath(), t);
}
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea, I also made all exception messages and logging conditions consistent. GrpcStatusException is something that users can intentionally return/throw as a way to return grpc-status they need. That's why we log it only at debug level

@idelpivnitskiy idelpivnitskiy merged commit 62d7db7 into apple:main Apr 15, 2025
11 checks passed
@idelpivnitskiy idelpivnitskiy deleted the grpc-logs branch April 15, 2025 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants