(ctx context.Context, req any, httpRequest *http.Request, router *mux.Router, handler grpc.UnaryHandler)
| 209 | } |
| 210 | |
| 211 | func handleHTTPGRPCRequestWithOpenTracing(ctx context.Context, req any, httpRequest *http.Request, router *mux.Router, handler grpc.UnaryHandler) (any, error) { |
| 212 | tracer := opentracing.GlobalTracer() |
| 213 | parentSpan := opentracing.SpanFromContext(ctx) |
| 214 | |
| 215 | // extract relevant span & tag data from request |
| 216 | method := httpRequest.Method |
| 217 | routeName := getRouteName(router, httpRequest) |
| 218 | urlPath := httpRequest.URL.Path |
| 219 | userAgent := httpRequest.Header.Get("User-Agent") |
| 220 | |
| 221 | // tag parent httpgrpc.HTTP/Handle server span, if it exists |
| 222 | if parentSpan != nil { |
| 223 | parentSpan.SetTag(string(ext.HTTPUrl), urlPath) |
| 224 | parentSpan.SetTag(string(ext.HTTPMethod), method) |
| 225 | parentSpan.SetTag("http.route", routeName) |
| 226 | parentSpan.SetTag("http.user_agent", userAgent) |
| 227 | } |
| 228 | |
| 229 | // create and start child HTTP span |
| 230 | // mirroring opentracing-contrib/go-stdlib/nethttp.Middleware span name and tags |
| 231 | childSpanName := getOperationName(routeName, httpRequest) |
| 232 | startSpanOpts := []opentracing.StartSpanOption{ |
| 233 | ext.SpanKindRPCServer, |
| 234 | opentracing.Tag{Key: string(ext.Component), Value: "net/http"}, |
| 235 | opentracing.Tag{Key: string(ext.HTTPUrl), Value: urlPath}, |
| 236 | opentracing.Tag{Key: string(ext.HTTPMethod), Value: method}, |
| 237 | opentracing.Tag{Key: "http.route", Value: routeName}, |
| 238 | opentracing.Tag{Key: "http.user_agent", Value: userAgent}, |
| 239 | } |
| 240 | if parentSpan != nil { |
| 241 | startSpanOpts = append( |
| 242 | startSpanOpts, |
| 243 | opentracing.SpanReference{ |
| 244 | Type: opentracing.ChildOfRef, |
| 245 | ReferencedContext: parentSpan.Context(), |
| 246 | }) |
| 247 | } |
| 248 | |
| 249 | childSpan := tracer.StartSpan(childSpanName, startSpanOpts...) |
| 250 | defer childSpan.Finish() |
| 251 | ctx = opentracing.ContextWithSpan(ctx, childSpan) |
| 252 | return handler(ctx, req) |
| 253 | } |
| 254 | |
| 255 | func handleHTTPGRPCRequestWithOTel(ctx context.Context, req any, httpRequest *http.Request, router *mux.Router, handler grpc.UnaryHandler) (any, error) { |
| 256 | // extract relevant span & tag data from request |
no test coverage detected