diff --git a/pkg/webserver/webserver.interceptors.grpc.go b/pkg/webserver/webserver.interceptors.grpc.go index 273c7c44..2df9e028 100644 --- a/pkg/webserver/webserver.interceptors.grpc.go +++ b/pkg/webserver/webserver.interceptors.grpc.go @@ -68,3 +68,27 @@ func (f *Factory) StreamServerInterceptors(interceptors ...grpc.StreamServerInte } return interceptors } + +func (f *Factory) UnaryClientInterceptors(interceptors ...grpc.UnaryClientInterceptor) []grpc.UnaryClientInterceptor { + // handle request timeout + interceptors = append(interceptors, timeoutlimit.UnaryClientInterceptor(f.fc.HandledTimeoutUnary)) + // burst limit + interceptors = append(interceptors, burstlimit.UnaryClientInterceptor(f.fc.MaxConcurrencyUnary, f.fc.BurstLimitTimeoutUnary)) + // request id + if f.fc.FillRequestId { + interceptors = append(interceptors, requestid.UnaryClientInterceptor()) + } + return interceptors +} + +func (f *Factory) StreamClientInterceptors(interceptors ...grpc.StreamClientInterceptor) []grpc.StreamClientInterceptor { + // handle request timeout + interceptors = append(interceptors, timeoutlimit.StreamClientInterceptor(f.fc.HandledTimeoutUnary)) + // burst limit + interceptors = append(interceptors, burstlimit.StreamClientInterceptor(f.fc.MaxConcurrencyUnary, f.fc.BurstLimitTimeoutUnary)) + // request id + if f.fc.FillRequestId { + interceptors = append(interceptors, requestid.StreamClientInterceptor()) + } + return interceptors +} diff --git a/pkg/webserver/webserver.options.grpc.go b/pkg/webserver/webserver.options.grpc.go index aa2b56ad..f5b54b8b 100644 --- a/pkg/webserver/webserver.options.grpc.go +++ b/pkg/webserver/webserver.options.grpc.go @@ -47,5 +47,7 @@ func (f *Factory) DialOptions(opts ...grpc.DialOption) []grpc.DialOption { if f.fc.EnableOpenTelemetry { opts = append(opts, otel.DialOptions()...) } + opts = append(opts, grpc.WithChainUnaryInterceptor(f.UnaryClientInterceptors()...)) + opts = append(opts, grpc.WithChainStreamInterceptor(f.StreamClientInterceptors()...)) return opts }