diff --git a/packages/node/package.json b/packages/node/package.json index 4cdeee400d1c..2b1ec548e8d7 100644 --- a/packages/node/package.json +++ b/packages/node/package.json @@ -18,7 +18,6 @@ "dependencies": { "@sentry/core": "6.18.1", "@sentry/hub": "6.18.1", - "@sentry/tracing": "6.18.1", "@sentry/types": "6.18.1", "@sentry/utils": "6.18.1", "cookie": "^0.4.1", diff --git a/packages/node/src/handlers.ts b/packages/node/src/handlers.ts index 6604dfff284c..1d08dab177ae 100644 --- a/packages/node/src/handlers.ts +++ b/packages/node/src/handlers.ts @@ -1,9 +1,15 @@ /* eslint-disable max-lines */ /* eslint-disable @typescript-eslint/no-explicit-any */ import { captureException, getCurrentHub, startTransaction, withScope } from '@sentry/core'; -import { extractTraceparentData, Span } from '@sentry/tracing'; -import { Event, ExtractedNodeRequestData, Transaction } from '@sentry/types'; -import { isPlainObject, isString, logger, normalize, stripUrlQueryAndFragment } from '@sentry/utils'; +import { Event, ExtractedNodeRequestData, Span, Transaction } from '@sentry/types'; +import { + extractTraceparentData, + isPlainObject, + isString, + logger, + normalize, + stripUrlQueryAndFragment, +} from '@sentry/utils'; import * as cookie from 'cookie'; import * as domain from 'domain'; import * as http from 'http'; diff --git a/packages/tracing/src/utils.ts b/packages/tracing/src/utils.ts index 9b78ad4074c9..63598c00ac58 100644 --- a/packages/tracing/src/utils.ts +++ b/packages/tracing/src/utils.ts @@ -1,13 +1,19 @@ import { getCurrentHub, Hub } from '@sentry/hub'; -import { Options, TraceparentData, Transaction } from '@sentry/types'; +import { Options, Transaction } from '@sentry/types'; -export const TRACEPARENT_REGEXP = new RegExp( - '^[ \\t]*' + // whitespace - '([0-9a-f]{32})?' + // trace_id - '-?([0-9a-f]{16})?' + // span_id - '-?([01])?' + // sampled - '[ \\t]*$', // whitespace -); +/** + * The `extractTraceparentData` function and `TRACEPARENT_REGEXP` constant used + * to be declared in this file. It was later moved into `@sentry/utils` as part of a + * move to remove `@sentry/tracing` dependencies from `@sentry/node` (`extractTraceparentData` + * is the only tracing function used by `@sentry/node`). + * + * These exports are kept here for backwards compatability's sake. + * + * TODO(v7): Reorganize these exports + * + * See https://github.com/getsentry/sentry-javascript/issues/4642 for more details. + */ +export { TRACEPARENT_REGEXP, extractTraceparentData } from '@sentry/utils'; /** * Determines if tracing is currently enabled. @@ -20,31 +26,6 @@ export function hasTracingEnabled(maybeOptions?: Options | undefined): boolean { return !!options && ('tracesSampleRate' in options || 'tracesSampler' in options); } -/** - * Extract transaction context data from a `sentry-trace` header. - * - * @param traceparent Traceparent string - * - * @returns Object containing data from the header, or undefined if traceparent string is malformed - */ -export function extractTraceparentData(traceparent: string): TraceparentData | undefined { - const matches = traceparent.match(TRACEPARENT_REGEXP); - if (matches) { - let parentSampled: boolean | undefined; - if (matches[3] === '1') { - parentSampled = true; - } else if (matches[3] === '0') { - parentSampled = false; - } - return { - traceId: matches[1], - parentSampled, - parentSpanId: matches[2], - }; - } - return undefined; -} - /** Grabs active transaction off scope, if any */ export function getActiveTransaction(maybeHub?: Hub): T | undefined { const hub = maybeHub || getCurrentHub(); diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 6a8e84e2fd93..6ffe7222569e 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -20,6 +20,7 @@ export * from './string'; export * from './supports'; export * from './syncpromise'; export * from './time'; +export * from './tracing'; export * from './env'; export * from './envelope'; export * from './clientreport'; diff --git a/packages/utils/src/tracing.ts b/packages/utils/src/tracing.ts new file mode 100644 index 000000000000..aef92cf5f0ca --- /dev/null +++ b/packages/utils/src/tracing.ts @@ -0,0 +1,34 @@ +import { TraceparentData } from '@sentry/types'; + +export const TRACEPARENT_REGEXP = new RegExp( + '^[ \\t]*' + // whitespace + '([0-9a-f]{32})?' + // trace_id + '-?([0-9a-f]{16})?' + // span_id + '-?([01])?' + // sampled + '[ \\t]*$', // whitespace +); + +/** + * Extract transaction context data from a `sentry-trace` header. + * + * @param traceparent Traceparent string + * + * @returns Object containing data from the header, or undefined if traceparent string is malformed + */ +export function extractTraceparentData(traceparent: string): TraceparentData | undefined { + const matches = traceparent.match(TRACEPARENT_REGEXP); + if (matches) { + let parentSampled: boolean | undefined; + if (matches[3] === '1') { + parentSampled = true; + } else if (matches[3] === '0') { + parentSampled = false; + } + return { + traceId: matches[1], + parentSampled, + parentSpanId: matches[2], + }; + } + return undefined; +}