(rootCtx context.Context)
| 482 | func telemetryAttributesMiddleware(additionalAttributes []attribute.KeyValue) mux.MiddlewareFunc { |
| 483 | return func(next http.Handler) http.Handler { |
| 484 | return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { |
| 485 | trace.SpanFromContext(r.Context()).SetAttributes(additionalAttributes...) |
| 486 | next.ServeHTTP(rw, r) |
| 487 | }) |
| 488 | } |
| 489 | } |
| 490 | |
| 491 | func loggingMiddleware(rootCtx context.Context) mux.MiddlewareFunc { |
| 492 | return func(next http.Handler) http.Handler { |
| 493 | return http.HandlerFunc(func(rw http.ResponseWriter, r *http.Request) { |
| 494 | reqID := nextRequestID(rootCtx, &httpReqSequenceID) |
| 495 | logFields := map[string]interface{}{ |
| 496 | "path": r.URL.Path, |
| 497 | "method": r.Method, |
| 498 | "ip": r.RemoteAddr, |
| 499 | "http_req_id": reqID, |
| 500 | } |
| 501 | // Retrieve the span and trace IDs if they exist and log them |
| 502 | spanCtx := trace.SpanContextFromContext(r.Context()) |
| 503 | if spanCtx.HasSpanID() { |
| 504 | logFields["span_id"] = spanCtx.SpanID().String() |
| 505 | } |
| 506 | if spanCtx.HasTraceID() { |
| 507 | logFields["trace_id"] = spanCtx.TraceID().String() |
| 508 | } |
| 509 | |
| 510 | // Create new logger with fields and pass along |
| 511 | requestLogger := GetLogger(rootCtx).WithFields(logFields) |
no test coverage detected