MCPcopy
hub / github.com/grafana/dskit / HTTPGRPCTracingInterceptor

Function HTTPGRPCTracingInterceptor

middleware/http_tracing.go:187–209  ·  view source on GitHub ↗

HTTPGRPCTracingInterceptor adds additional information about the encapsulated HTTP request to httpgrpc trace spans. The httpgrpc client wraps HTTP requests up into a generic httpgrpc.HTTP/Handle gRPC method. The httpgrpc server unwraps httpgrpc.HTTP/Handle gRPC requests into HTTP requests and forwa

(router *mux.Router)

Source from the content-addressed store, hash-verified

185// span tags to whatever parent span is active in the caller, rather than the /httpgrpc.HTTP/Handle
186// span created by the tracing middleware for requests that arrive over the network.
187func HTTPGRPCTracingInterceptor(router *mux.Router) grpc.UnaryServerInterceptor {
188 return func(ctx context.Context, req any, info *grpc.UnaryServerInfo, handler grpc.UnaryHandler) (resp any, err error) {
189 if info.FullMethod != "/httpgrpc.HTTP/Handle" {
190 return handler(ctx, req)
191 }
192
193 httpgrpcRequest, ok := req.(*httpgrpc.HTTPRequest)
194 if !ok {
195 return handler(ctx, req)
196 }
197
198 httpRequest, err := httpgrpc.ToHTTPRequest(ctx, httpgrpcRequest)
199 if err != nil {
200 return handler(ctx, req)
201 }
202
203 if opentracing.IsGlobalTracerRegistered() {
204 return handleHTTPGRPCRequestWithOpenTracing(ctx, req, httpRequest, router, handler)
205 }
206
207 return handleHTTPGRPCRequestWithOTel(ctx, req, httpRequest, router, handler)
208 }
209}
210
211func handleHTTPGRPCRequestWithOpenTracing(ctx context.Context, req any, httpRequest *http.Request, router *mux.Router, handler grpc.UnaryHandler) (any, error) {
212 tracer := opentracing.GlobalTracer()

Callers 1

newServerFunction · 0.92

Calls 3

ToHTTPRequestFunction · 0.92

Tested by

no test coverage detected