/ shared / logger / node_modules / @sentry / utils / esm / tracing.js
tracing.js
 1  const TRACEPARENT_REGEXP = new RegExp(
 2    '^[ \\t]*' + // whitespace
 3      '([0-9a-f]{32})?' + // trace_id
 4      '-?([0-9a-f]{16})?' + // span_id
 5      '-?([01])?' + // sampled
 6      '[ \\t]*$', // whitespace
 7  );
 8  
 9  /**
10   * Extract transaction context data from a `sentry-trace` header.
11   *
12   * @param traceparent Traceparent string
13   *
14   * @returns Object containing data from the header, or undefined if traceparent string is malformed
15   */
16  function extractTraceparentData(traceparent) {
17    const matches = traceparent.match(TRACEPARENT_REGEXP);
18  
19    if (!traceparent || !matches) {
20      // empty string or no matches is invalid traceparent data
21      return undefined;
22    }
23  
24    let parentSampled;
25    if (matches[3] === '1') {
26      parentSampled = true;
27    } else if (matches[3] === '0') {
28      parentSampled = false;
29    }
30  
31    return {
32      traceId: matches[1],
33      parentSampled,
34      parentSpanId: matches[2],
35    };
36  }
37  
38  export { TRACEPARENT_REGEXP, extractTraceparentData };
39  //# sourceMappingURL=tracing.js.map