| 29 | * @returns Object containing data from the header, or undefined if traceparent string is malformed |
| 30 | */ |
| 31 | export function extractTraceparentData(traceparent?: string): TraceparentData | undefined { |
| 32 | if (!traceparent) { |
| 33 | return undefined; |
| 34 | } |
| 35 | |
| 36 | const matches = traceparent.match(TRACEPARENT_REGEXP); |
| 37 | if (!matches) { |
| 38 | return undefined; |
| 39 | } |
| 40 | |
| 41 | let parentSampled: boolean | undefined; |
| 42 | if (matches[3] === '1') { |
| 43 | parentSampled = true; |
| 44 | } else if (matches[3] === '0') { |
| 45 | parentSampled = false; |
| 46 | } |
| 47 | |
| 48 | return { |
| 49 | traceId: matches[1], |
| 50 | parentSampled, |
| 51 | parentSpanId: matches[2], |
| 52 | }; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Create a propagation context from incoming headers or |