From 29808e14ebf814954b4fcf5806d46d8e32c6fce8 Mon Sep 17 00:00:00 2001 From: s1gr1d Date: Fri, 3 Jan 2025 15:36:01 +0100 Subject: [PATCH 1/3] feat(core): Remove `transactionContext` from `samplingContext` --- docs/migration/v8-to-v9.md | 1 + packages/core/src/tracing/trace.ts | 4 ---- packages/core/src/types-hoist/samplingcontext.ts | 9 --------- packages/core/test/lib/tracing/trace.test.ts | 1 - packages/opentelemetry/src/sampler.ts | 4 ---- packages/opentelemetry/test/trace.test.ts | 9 --------- packages/profiling-node/src/spanProfileUtils.ts | 4 ---- 7 files changed, 1 insertion(+), 31 deletions(-) diff --git a/docs/migration/v8-to-v9.md b/docs/migration/v8-to-v9.md index 9c5e242a2a62..717f52da3e21 100644 --- a/docs/migration/v8-to-v9.md +++ b/docs/migration/v8-to-v9.md @@ -221,6 +221,7 @@ Since v9, the types have been merged into `@sentry/core`, which removed some of - The `Request` type has been removed. Use `RequestEventData` type instead. - The `IntegrationClass` type is no longer exported - it was not used anymore. Instead, use `Integration` or `IntegrationFn`. - The `samplingContext.request` attribute in the `tracesSampler` has been removed. Use `samplingContext.normalizedRequest` instead. Note that the type of `normalizedRequest` differs from `request`. +- The `samplingContext.transactionContext` object in the `tracesSampler` has been removed. All object attributes are available in the top-level of `samplingContext`. # No Version Support Timeline diff --git a/packages/core/src/tracing/trace.ts b/packages/core/src/tracing/trace.ts index f17867a4e32d..dbe1691cfbaf 100644 --- a/packages/core/src/tracing/trace.ts +++ b/packages/core/src/tracing/trace.ts @@ -381,10 +381,6 @@ function _startRootSpan(spanArguments: SentrySpanArguments, scope: Scope, parent name, parentSampled, attributes, - transactionContext: { - name, - parentSampled, - }, }); const rootSpan = new SentrySpan({ diff --git a/packages/core/src/types-hoist/samplingcontext.ts b/packages/core/src/types-hoist/samplingcontext.ts index 0c73ba0968c2..d406b851be88 100644 --- a/packages/core/src/types-hoist/samplingcontext.ts +++ b/packages/core/src/types-hoist/samplingcontext.ts @@ -15,15 +15,6 @@ export interface CustomSamplingContext { * Adds default data to data provided by the user. See {@link Hub.startTransaction} */ export interface SamplingContext extends CustomSamplingContext { - /** - * Context data with which transaction being sampled was created. - * @deprecated This is duplicate data and will be removed eventually. - */ - transactionContext: { - name: string; - parentSampled?: boolean | undefined; - }; - /** * Sampling decision from the parent transaction, if any. */ diff --git a/packages/core/test/lib/tracing/trace.test.ts b/packages/core/test/lib/tracing/trace.test.ts index fe304acc2beb..4cb82060a2f7 100644 --- a/packages/core/test/lib/tracing/trace.test.ts +++ b/packages/core/test/lib/tracing/trace.test.ts @@ -496,7 +496,6 @@ describe('startSpan', () => { test2: 'aa', test3: 'bb', }, - transactionContext: expect.objectContaining({ name: 'outer', parentSampled: undefined }), }); }); diff --git a/packages/opentelemetry/src/sampler.ts b/packages/opentelemetry/src/sampler.ts index a561bb863561..fc4431ea9720 100644 --- a/packages/opentelemetry/src/sampler.ts +++ b/packages/opentelemetry/src/sampler.ts @@ -99,10 +99,6 @@ export class SentrySampler implements Sampler { const [sampled, sampleRate] = sampleSpan(options, { name: inferredSpanName, attributes: mergedAttributes, - transactionContext: { - name: inferredSpanName, - parentSampled, - }, parentSampled, }); diff --git a/packages/opentelemetry/test/trace.test.ts b/packages/opentelemetry/test/trace.test.ts index 6852b8b40988..78b5ff4eff61 100644 --- a/packages/opentelemetry/test/trace.test.ts +++ b/packages/opentelemetry/test/trace.test.ts @@ -1322,7 +1322,6 @@ describe('trace (sampling)', () => { parentSampled: undefined, name: 'outer', attributes: {}, - transactionContext: { name: 'outer', parentSampled: undefined }, }); // Now return `false`, it should not sample @@ -1341,7 +1340,6 @@ describe('trace (sampling)', () => { parentSampled: false, name: 'inner2', attributes: {}, - transactionContext: { name: 'inner2', parentSampled: false }, }); }); @@ -1376,7 +1374,6 @@ describe('trace (sampling)', () => { attr2: 1, 'sentry.op': 'test.op', }, - transactionContext: { name: 'outer', parentSampled: undefined }, }); // Now return `0`, it should not sample @@ -1395,7 +1392,6 @@ describe('trace (sampling)', () => { parentSampled: false, name: 'inner2', attributes: {}, - transactionContext: { name: 'inner2', parentSampled: false }, }); // Now return `0.4`, it should not sample @@ -1410,7 +1406,6 @@ describe('trace (sampling)', () => { parentSampled: undefined, name: 'outer3', attributes: {}, - transactionContext: { name: 'outer3', parentSampled: undefined }, }); }); @@ -1444,10 +1439,6 @@ describe('trace (sampling)', () => { parentSampled: true, name: 'outer', attributes: {}, - transactionContext: { - name: 'outer', - parentSampled: true, - }, }); }); diff --git a/packages/profiling-node/src/spanProfileUtils.ts b/packages/profiling-node/src/spanProfileUtils.ts index 39196578a9bc..1ee050ce22e5 100644 --- a/packages/profiling-node/src/spanProfileUtils.ts +++ b/packages/profiling-node/src/spanProfileUtils.ts @@ -48,10 +48,6 @@ export function maybeProfileSpan( profilesSampleRate = profilesSampler({ name: spanName, attributes: data, - transactionContext: { - name: spanName, - parentSampled, - }, parentSampled, ...customSamplingContext, }); From 32322550166295fdac8786e829ebf10f243a1ad2 Mon Sep 17 00:00:00 2001 From: s1gr1d Date: Fri, 10 Jan 2025 16:09:19 +0100 Subject: [PATCH 2/3] fix formatting --- packages/opentelemetry/src/sampler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/opentelemetry/src/sampler.ts b/packages/opentelemetry/src/sampler.ts index b0924e90beea..ecaf8340e3f5 100644 --- a/packages/opentelemetry/src/sampler.ts +++ b/packages/opentelemetry/src/sampler.ts @@ -104,7 +104,7 @@ export class SentrySampler implements Sampler { name: inferredSpanName, attributes: mergedAttributes, parentSampled, - }); + }); const attributes: Attributes = { [SEMANTIC_ATTRIBUTE_SENTRY_SAMPLE_RATE]: sampleRate, From 2b668912498e4077c3132d659a42968ef0ff0172 Mon Sep 17 00:00:00 2001 From: s1gr1d Date: Mon, 13 Jan 2025 09:33:28 +0100 Subject: [PATCH 3/3] add optional chaining --- .../wrapServerEntryWithDynamicImport.ts | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/packages/solidstart/src/config/wrapServerEntryWithDynamicImport.ts b/packages/solidstart/src/config/wrapServerEntryWithDynamicImport.ts index 6d069220e1ae..8f8c7a59f1f4 100644 --- a/packages/solidstart/src/config/wrapServerEntryWithDynamicImport.ts +++ b/packages/solidstart/src/config/wrapServerEntryWithDynamicImport.ts @@ -53,7 +53,7 @@ export function wrapServerEntryWithDynamicImport(config: WrapServerEntryPluginOp return { id: source, moduleSideEffects: true }; } - if (additionalImports && additionalImports.includes(source)) { + if (additionalImports?.includes(source)) { // When importing additional imports like "import-in-the-middle/hook.mjs" in the returned code of the `load()` function below: // By setting `moduleSideEffects` to `true`, the import is added to the bundle, although nothing is imported from it // By importing "import-in-the-middle/hook.mjs", we can make sure this file is included, as not all node builders are including files imported with `module.register()`. @@ -70,7 +70,7 @@ export function wrapServerEntryWithDynamicImport(config: WrapServerEntryPluginOp const resolution = await this.resolve(source, importer, options); // If it cannot be resolved or is external, just return it so that Rollup can display an error - if (!resolution || (resolution && resolution.external)) return resolution; + if (!resolution || resolution?.external) return resolution; const moduleInfo = await this.load(resolution); @@ -146,23 +146,21 @@ export function extractFunctionReexportQueryParameters(query: string): { wrap: s const wrapMatch = query.match(wrapRegex); const reexportMatch = query.match(reexportRegex); - const wrap = - wrapMatch && wrapMatch[1] - ? wrapMatch[1] - .split(',') - .filter(param => param !== '') - // Sanitize, as code could be injected with another rollup plugin - .map((str: string) => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')) - : []; - - const reexport = - reexportMatch && reexportMatch[1] - ? reexportMatch[1] - .split(',') - .filter(param => param !== '' && param !== 'default') - // Sanitize, as code could be injected with another rollup plugin - .map((str: string) => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')) - : []; + const wrap = wrapMatch?.[1] + ? wrapMatch[1] + .split(',') + .filter(param => param !== '') + // Sanitize, as code could be injected with another rollup plugin + .map((str: string) => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')) + : []; + + const reexport = reexportMatch?.[1] + ? reexportMatch[1] + .split(',') + .filter(param => param !== '' && param !== 'default') + // Sanitize, as code could be injected with another rollup plugin + .map((str: string) => str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')) + : []; return { wrap, reexport }; }