googleads / google-ads-dotnet

This project hosts the .NET client library for the Google Ads API.
https://developers.google.com/google-ads/api
Apache License 2.0
73 stars 97 forks source link

How do I add my own GRPC interceptors? #546

Closed wub closed 7 months ago

wub commented 9 months ago

We want to use something like Lunar to help with rate limiting, specifically the Agentless mode.

Is it possible (or recommended) to attach my own GRPC client interceptor to modify all outgoing requests to be compatible with Lunar?

We want to change the hostname for all requests to the IP of the Lunar proxy, and add a custom Host header that points to the original hostname.

I am able to create a basic interceptor, but I'm not sure how to attach it to the correct channel. Do I have to fetch the channel on a per-service basis? (If so, how would I do that?)

Or, is there a better approach?

Thanks!

AnashOommen commented 9 months ago

@wub This would definitely require a code change. The grpc interceptors are wired here: https://github.com/googleads/google-ads-dotnet/blob/59e2dc8d96e046f64f6b8ec99b5d783bdeae71cd/Google.Ads.GoogleAds.Core/src/Lib/GoogleAdsServiceClientFactory.cs#L65

The class is internal, so any change would require enhancement.

Could you download the library, manually modify and make sure the Lunar functionality works as expected? If so, let us know, we can add a callback hook so you can add the necessary interceptor at the runtime.