extractTraceFromString will extract the trace information from the provided propagated trace string context.
(ctx context.Context, trace string)
| 230 | // extractTraceFromString will extract the trace information from the provided |
| 231 | // propagated trace string context. |
| 232 | func 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. |