11import { getCurrentHub , Hub } from '@sentry/hub' ;
2- import { Options , TraceparentData , Transaction } from '@sentry/types' ;
2+ import { Options , Transaction } from '@sentry/types' ;
33
4- export const TRACEPARENT_REGEXP = new RegExp (
5- '^[ \\t]*' + // whitespace
6- '([0-9a-f]{32})?' + // trace_id
7- '-?([0-9a-f]{16})?' + // span_id
8- '-?([01])?' + // sampled
9- '[ \\t]*$' , // whitespace
10- ) ;
4+ /**
5+ * The `extractTraceparentData` function and `TRACEPARENT_REGEXP` constant used
6+ * to be declared in this file. It was later moved into `@sentry/utils` as part of a
7+ * move to remove `@sentry/tracing` dependencies from `@sentry/node` (`extractTraceparentData`
8+ * is the only tracing function used by `@sentry/node`).
9+ *
10+ * These exports are kept here for backwards compatability's sack.
11+ *
12+ * TODO(v7): Reorganize these exports
13+ *
14+ * See https://github.com/getsentry/sentry-javascript/issues/4642 for more details.
15+ */
16+ export { TRACEPARENT_REGEXP , extractTraceparentData } from '@sentry/utils' ;
1117
1218/**
1319 * Determines if tracing is currently enabled.
@@ -20,31 +26,6 @@ export function hasTracingEnabled(maybeOptions?: Options | undefined): boolean {
2026 return ! ! options && ( 'tracesSampleRate' in options || 'tracesSampler' in options ) ;
2127}
2228
23- /**
24- * Extract transaction context data from a `sentry-trace` header.
25- *
26- * @param traceparent Traceparent string
27- *
28- * @returns Object containing data from the header, or undefined if traceparent string is malformed
29- */
30- export function extractTraceparentData ( traceparent : string ) : TraceparentData | undefined {
31- const matches = traceparent . match ( TRACEPARENT_REGEXP ) ;
32- if ( matches ) {
33- let parentSampled : boolean | undefined ;
34- if ( matches [ 3 ] === '1' ) {
35- parentSampled = true ;
36- } else if ( matches [ 3 ] === '0' ) {
37- parentSampled = false ;
38- }
39- return {
40- traceId : matches [ 1 ] ,
41- parentSampled,
42- parentSpanId : matches [ 2 ] ,
43- } ;
44- }
45- return undefined ;
46- }
47-
4829/** Grabs active transaction off scope, if any */
4930export function getActiveTransaction < T extends Transaction > ( maybeHub ?: Hub ) : T | undefined {
5031 const hub = maybeHub || getCurrentHub ( ) ;
0 commit comments