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

Implement tower::Service for OtelGrpcService #201

Merged
merged 1 commit into from
Jan 7, 2025

Conversation

timvermeulen
Copy link
Contributor

Implementing Service gives you the GrpcService implementation for free, and it also comes with the benefits of the Service trait, such as being able to use interceptors:

struct MyInterceptor;

impl tonic::service::Interceptor for MyInterceptor {
    fn call(&mut self, request: tonic::Request<()>) -> Result<tonic::Request<()>, tonic::Status> {
        Ok(request)
    }
}
# examples/grpc/src/client.rs

  let channel = ServiceBuilder::new().layer(OtelGrpcLayer).service(channel);

- let mut client = GreeterClient::new(channel);
+ let mut client = GreeterClient::with_interceptor(channel, MyInterceptor);

The above change currently fails to compile because MyInterceptor doesn't implement Service (which InterceptedService requires), only GrpcService.

@davidB
Copy link
Owner

davidB commented Jan 7, 2025

Thank you

@davidB davidB merged commit ec74474 into davidB:main Jan 7, 2025
2 checks passed
@github-actions github-actions bot mentioned this pull request Feb 16, 2025
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