(ctx context.Context, req any, httpRequest *http.Request, router *mux.Router, handler grpc.UnaryHandler)
| 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 |
| 257 | method := httpRequest.Method |
| 258 | routeName := getRouteName(router, httpRequest) |
| 259 | urlPath := httpRequest.URL.Path |
| 260 | userAgent := httpRequest.Header.Get("User-Agent") |
| 261 | |
| 262 | parentSpan := trace.SpanFromContext(ctx) |
| 263 | if parentSpan.SpanContext().IsValid() { |
| 264 | parentSpan.SetAttributes( |
| 265 | semconv.HTTPRequestMethodKey.String(method), |
| 266 | semconv.HTTPRouteKey.String(routeName), |
| 267 | attribute.String("url.path", urlPath), |
| 268 | semconv.UserAgentOriginal(userAgent), |
| 269 | ) |
| 270 | } |
| 271 | // create and start child HTTP span and set span name and attributes |
| 272 | childSpanName := getOperationName(routeName, httpRequest) |
| 273 | |
| 274 | startSpanOpts := []trace.SpanStartOption{ |
| 275 | trace.WithSpanKind(trace.SpanKindServer), |
| 276 | trace.WithAttributes( |
| 277 | semconv.HTTPRequestMethodKey.String(method), |
| 278 | semconv.HTTPRouteKey.String(routeName), |
| 279 | semconv.UserAgentOriginal(userAgent), |
| 280 | attribute.String("url.path", urlPath), |
| 281 | ), |
| 282 | } |
| 283 | |
| 284 | var childSpan trace.Span |
| 285 | ctx, childSpan = tracer.Start(ctx, childSpanName, startSpanOpts...) |
| 286 | defer childSpan.End() |
| 287 | |
| 288 | return handler(ctx, req) |
| 289 | } |
| 290 | |
| 291 | func httpOperationName(r *http.Request) string { |
| 292 | routeName := ExtractRouteName(r.Context()) |
no test coverage detected