extractTrace attempts to check for a cf-trace-id from a request and return the trace context with the provided http.Request.
(req *http.Request)
| 256 | // extractTrace attempts to check for a cf-trace-id from a request and return the |
| 257 | // trace context with the provided http.Request. |
| 258 | func extractTrace(req *http.Request) (context.Context, bool) { |
| 259 | // Only add tracing for requests with appropriately tagged headers |
| 260 | remoteTraces := req.Header.Values(TracerContextName) |
| 261 | if len(remoteTraces) <= 0 { |
| 262 | // Strip the cf-trace-id header |
| 263 | req.Header.Del(TracerContextName) |
| 264 | return nil, false |
| 265 | } |
| 266 | |
| 267 | traceHeader := map[string]string{} |
| 268 | for _, t := range remoteTraces { |
| 269 | // Override the 'cf-trace-id' as 'uber-trace-id' so the jaeger propagator can extract it. |
| 270 | // Last entry wins if multiple provided |
| 271 | traceHeader[TracerContextNameOverride] = t |
| 272 | } |
| 273 | |
| 274 | // Strip the cf-trace-id header |
| 275 | req.Header.Del(TracerContextName) |
| 276 | |
| 277 | if traceHeader[TracerContextNameOverride] == "" { |
| 278 | return nil, false |
| 279 | } |
| 280 | |
| 281 | remoteCtx := otel.GetTextMapPropagator().Extract(req.Context(), propagation.MapCarrier(traceHeader)) |
| 282 | return remoteCtx, true |
| 283 | } |
| 284 | |
| 285 | func NewNoopSpan() trace.Span { |
| 286 | return trace.SpanFromContext(nil) |
no test coverage detected