MCPcopy Index your code
hub / github.com/cloudflare/cloudflared / extractTraceFromString

Function extractTraceFromString

tracing/tracing.go:232–254  ·  view source on GitHub ↗

extractTraceFromString will extract the trace information from the provided propagated trace string context.

(ctx context.Context, trace string)

Source from the content-addressed store, hash-verified

230// extractTraceFromString will extract the trace information from the provided
231// propagated trace string context.
232func extractTraceFromString(ctx context.Context, trace string) (context.Context, bool) {
233 if trace == "" {
234 return ctx, false
235 }
236 // Jaeger specific separator
237 parts := strings.Split(trace, separator)
238 if len(parts) != 4 {
239 return ctx, false
240 }
241 if parts[0] == "" {
242 return ctx, false
243 }
244 // Correctly left pad the trace to a length of 32
245 if len(parts[0]) < traceID128bitsWidth {
246 left := traceID128bitsWidth - len(parts[0])
247 parts[0] = strings.Repeat("0", left) + parts[0]
248 trace = strings.Join(parts, separator)
249 }
250 // Override the 'cf-trace-id' as 'uber-trace-id' so the jaeger propagator can extract it.
251 traceHeader := map[string]string{TracerContextNameOverride: trace}
252 remoteCtx := otel.GetTextMapPropagator().Extract(ctx, propagation.MapCarrier(traceHeader))
253 return remoteCtx, true
254}
255
256// extractTrace attempts to check for a cf-trace-id from a request and return the
257// trace context with the provided http.Request.

Callers 1

NewTracedContextFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected