From 28a00c60388b0e9dfd874acac2e01e09a8a92f69 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Fri, 9 Feb 2024 17:35:22 -0500 Subject: [PATCH 1/2] feat(v8): Remove deprecated trace and startActiveSpan methods --- .../pages/api/async-context-edge-endpoint.ts | 6 +-- .../scripts/consistentExports.ts | 5 -- packages/astro/src/index.server.ts | 4 -- packages/browser/src/index.ts | 2 - packages/bun/src/index.ts | 2 - packages/core/src/tracing/index.ts | 4 -- packages/core/src/tracing/trace.ts | 54 ------------------- packages/deno/src/index.ts | 2 - packages/node-experimental/README.md | 8 +-- packages/node-experimental/src/index.ts | 2 - packages/node/src/index.ts | 4 -- packages/remix/src/index.server.ts | 2 - packages/sveltekit/src/server/index.ts | 4 -- packages/vercel-edge/src/index.ts | 2 - 14 files changed, 7 insertions(+), 94 deletions(-) diff --git a/dev-packages/e2e-tests/test-applications/nextjs-app-dir/pages/api/async-context-edge-endpoint.ts b/dev-packages/e2e-tests/test-applications/nextjs-app-dir/pages/api/async-context-edge-endpoint.ts index 646a0c22d089..2ee051870a29 100644 --- a/dev-packages/e2e-tests/test-applications/nextjs-app-dir/pages/api/async-context-edge-endpoint.ts +++ b/dev-packages/e2e-tests/test-applications/nextjs-app-dir/pages/api/async-context-edge-endpoint.ts @@ -5,17 +5,17 @@ export const config = { }; export default async function handler() { - // Without `runWithAsyncContext` and a working async context strategy the two spans created by `Sentry.trace()` would be nested. + // Without `runWithAsyncContext` and a working async context strategy the two spans created by `Sentry.startSpan()` would be nested. const outerSpanPromise = Sentry.runWithAsyncContext(() => { - return Sentry.trace({ name: 'outer-span' }, () => { + return Sentry.startSpan({ name: 'outer-span' }, () => { return new Promise(resolve => setTimeout(resolve, 300)); }); }); setTimeout(() => { Sentry.runWithAsyncContext(() => { - return Sentry.trace({ name: 'inner-span' }, () => { + return Sentry.startSpan({ name: 'inner-span' }, () => { return new Promise(resolve => setTimeout(resolve, 100)); }); }); diff --git a/dev-packages/e2e-tests/test-applications/node-exports-test-app/scripts/consistentExports.ts b/dev-packages/e2e-tests/test-applications/node-exports-test-app/scripts/consistentExports.ts index 23bb11e9d237..20ee664b8053 100644 --- a/dev-packages/e2e-tests/test-applications/node-exports-test-app/scripts/consistentExports.ts +++ b/dev-packages/e2e-tests/test-applications/node-exports-test-app/scripts/consistentExports.ts @@ -11,11 +11,6 @@ const NODE_EXPORTS_IGNORE = [ 'default', // Probably generated by transpilation, no need to require it '__esModule', - // this function was deprecated almost immediately after it was introduced - // due to a name change (startSpan). No need to re-export it IMHO. - 'startActiveSpan', - // this was never meant for external use (and documented as such) - 'trace', // These Node exports were only made for type definition fixes (see #10339) 'Undici', 'Http', diff --git a/packages/astro/src/index.server.ts b/packages/astro/src/index.server.ts index ad22273818f7..51f7c4e0395a 100644 --- a/packages/astro/src/index.server.ts +++ b/packages/astro/src/index.server.ts @@ -48,8 +48,6 @@ export { setUser, getSpanStatusFromHttpCode, setHttpStatus, - // eslint-disable-next-line deprecation/deprecation - trace, withScope, withIsolationScope, autoDiscoverNodePerformanceMonitoringIntegrations, @@ -80,8 +78,6 @@ export { setMeasurement, getActiveSpan, startSpan, - // eslint-disable-next-line deprecation/deprecation - startActiveSpan, startInactiveSpan, startSpanManual, continueTrace, diff --git a/packages/browser/src/index.ts b/packages/browser/src/index.ts index 9fa4d83e3984..6034075e22a8 100644 --- a/packages/browser/src/index.ts +++ b/packages/browser/src/index.ts @@ -74,8 +74,6 @@ export { getActiveTransaction, getSpanStatusFromHttpCode, setHttpStatus, - // eslint-disable-next-line deprecation/deprecation - trace, makeMultiplexedTransport, // eslint-disable-next-line deprecation/deprecation ModuleMetadata, diff --git a/packages/bun/src/index.ts b/packages/bun/src/index.ts index 295bad3271ea..c60063a9984b 100644 --- a/packages/bun/src/index.ts +++ b/packages/bun/src/index.ts @@ -64,8 +64,6 @@ export { setUser, getSpanStatusFromHttpCode, setHttpStatus, - // eslint-disable-next-line deprecation/deprecation - trace, withScope, withIsolationScope, captureCheckIn, diff --git a/packages/core/src/tracing/index.ts b/packages/core/src/tracing/index.ts index c45389da53c6..9a219c62ff94 100644 --- a/packages/core/src/tracing/index.ts +++ b/packages/core/src/tracing/index.ts @@ -13,13 +13,9 @@ export { } from './spanstatus'; export type { SpanStatusType } from './spanstatus'; export { - // eslint-disable-next-line deprecation/deprecation - trace, getActiveSpan, startSpan, startInactiveSpan, - // eslint-disable-next-line deprecation/deprecation - startActiveSpan, startSpanManual, continueTrace, } from './trace'; diff --git a/packages/core/src/tracing/trace.ts b/packages/core/src/tracing/trace.ts index a1327d0f737c..75567c13d99f 100644 --- a/packages/core/src/tracing/trace.ts +++ b/packages/core/src/tracing/trace.ts @@ -12,55 +12,6 @@ import { handleCallbackErrors } from '../utils/handleCallbackErrors'; import { hasTracingEnabled } from '../utils/hasTracingEnabled'; import { spanTimeInputToSeconds, spanToJSON } from '../utils/spanUtils'; -/** - * Wraps a function with a transaction/span and finishes the span after the function is done. - * - * Note that if you have not enabled tracing extensions via `addTracingExtensions` - * or you didn't set `tracesSampleRate`, this function will not generate spans - * and the `span` returned from the callback will be undefined. - * - * This function is meant to be used internally and may break at any time. Use at your own risk. - * - * @internal - * @private - * - * @deprecated Use `startSpan` instead. - */ -export function trace( - context: TransactionContext, - callback: (span?: Span) => T, - // eslint-disable-next-line @typescript-eslint/no-empty-function - onError: (error: unknown, span?: Span) => void = () => {}, - // eslint-disable-next-line @typescript-eslint/no-empty-function - afterFinish: () => void = () => {}, -): T { - // eslint-disable-next-line deprecation/deprecation - const hub = getCurrentHub(); - const scope = getCurrentScope(); - // eslint-disable-next-line deprecation/deprecation - const parentSpan = scope.getSpan(); - - const ctx = normalizeContext(context); - const activeSpan = createChildSpanOrTransaction(hub, parentSpan, ctx); - - // eslint-disable-next-line deprecation/deprecation - scope.setSpan(activeSpan); - - return handleCallbackErrors( - () => callback(activeSpan), - error => { - activeSpan && activeSpan.setStatus('internal_error'); - onError(error, activeSpan); - }, - () => { - activeSpan && activeSpan.end(); - // eslint-disable-next-line deprecation/deprecation - scope.setSpan(parentSpan); - afterFinish(); - }, - ); -} - /** * Wraps a function with a transaction/span and finishes the span after the function is done. * The created span is the active span and will be used as parent by other spans created inside the function @@ -105,11 +56,6 @@ export function startSpan(context: StartSpanOptions, callback: (span: Span | }); } -/** - * @deprecated Use {@link startSpan} instead. - */ -export const startActiveSpan = startSpan; - /** * Similar to `Sentry.startSpan`. Wraps a function with a transaction/span, but does not finish the span * after the function is done automatically. You'll have to call `span.end()` manually. diff --git a/packages/deno/src/index.ts b/packages/deno/src/index.ts index 579bad78c869..13f31298e3da 100644 --- a/packages/deno/src/index.ts +++ b/packages/deno/src/index.ts @@ -63,8 +63,6 @@ export { setUser, getSpanStatusFromHttpCode, setHttpStatus, - // eslint-disable-next-line deprecation/deprecation - trace, withScope, withIsolationScope, captureCheckIn, diff --git a/packages/node-experimental/README.md b/packages/node-experimental/README.md index e23ee4f1817c..36a522d78248 100644 --- a/packages/node-experimental/README.md +++ b/packages/node-experimental/README.md @@ -59,10 +59,10 @@ You can manual instrument using the following APIs: ```js const Sentry = require('@sentry/node-experimental'); -Sentry.startActiveSpan({ description: 'outer' }, function (span) { +Sentry.startSpan({ description: 'outer' }, function (span) { span.setData(customData); doSomethingSlow(); - Sentry.startActiveSpan({ description: 'inner' }, function() { + Sentry.startSpan({ description: 'inner' }, function() { // inner span is a child of outer span doSomethingVerySlow(); // inner span is auto-ended when this callback ends @@ -72,13 +72,13 @@ Sentry.startActiveSpan({ description: 'outer' }, function (span) { ``` You can also create spans without marking them as the active span. -Note that for most scenarios, we recommend the `startActiveSpan` syntax. +Note that for most scenarios, we recommend the `startSpan` syntax. ```js const Sentry = require('@sentry/node-experimental'); // This will _not_ be put on the scope/set as active, so no other spans will be attached to it -const span = Sentry.startSpan({ description: 'non-active span' }); +const span = Sentry.startInactiveSpan({ description: 'non-active span' }); doSomethingSlow(); diff --git a/packages/node-experimental/src/index.ts b/packages/node-experimental/src/index.ts index 5b19697732a8..6899868986ae 100644 --- a/packages/node-experimental/src/index.ts +++ b/packages/node-experimental/src/index.ts @@ -76,8 +76,6 @@ export { SDK_VERSION, getSpanStatusFromHttpCode, setHttpStatus, - // eslint-disable-next-line deprecation/deprecation - trace, captureCheckIn, withMonitor, hapiErrorPlugin, diff --git a/packages/node/src/index.ts b/packages/node/src/index.ts index ac7c54a0cf60..f75875dae7db 100644 --- a/packages/node/src/index.ts +++ b/packages/node/src/index.ts @@ -63,8 +63,6 @@ export { setUser, getSpanStatusFromHttpCode, setHttpStatus, - // eslint-disable-next-line deprecation/deprecation - trace, withScope, withIsolationScope, captureCheckIn, @@ -72,8 +70,6 @@ export { setMeasurement, getActiveSpan, startSpan, - // eslint-disable-next-line deprecation/deprecation - startActiveSpan, startInactiveSpan, startSpanManual, continueTrace, diff --git a/packages/remix/src/index.server.ts b/packages/remix/src/index.server.ts index 6d5a117f965f..ec4cb8f74d16 100644 --- a/packages/remix/src/index.server.ts +++ b/packages/remix/src/index.server.ts @@ -52,8 +52,6 @@ export { setUser, getSpanStatusFromHttpCode, setHttpStatus, - // eslint-disable-next-line deprecation/deprecation - trace, withScope, withIsolationScope, autoDiscoverNodePerformanceMonitoringIntegrations, diff --git a/packages/sveltekit/src/server/index.ts b/packages/sveltekit/src/server/index.ts index 9115d3008ad9..5e17eeb4679a 100644 --- a/packages/sveltekit/src/server/index.ts +++ b/packages/sveltekit/src/server/index.ts @@ -46,8 +46,6 @@ export { setUser, getSpanStatusFromHttpCode, setHttpStatus, - // eslint-disable-next-line deprecation/deprecation - trace, withScope, withIsolationScope, autoDiscoverNodePerformanceMonitoringIntegrations, @@ -78,8 +76,6 @@ export { setMeasurement, getActiveSpan, startSpan, - // eslint-disable-next-line deprecation/deprecation - startActiveSpan, startInactiveSpan, startSpanManual, continueTrace, diff --git a/packages/vercel-edge/src/index.ts b/packages/vercel-edge/src/index.ts index dcd6686d0562..17583ac00cbc 100644 --- a/packages/vercel-edge/src/index.ts +++ b/packages/vercel-edge/src/index.ts @@ -63,8 +63,6 @@ export { setUser, getSpanStatusFromHttpCode, setHttpStatus, - // eslint-disable-next-line deprecation/deprecation - trace, withScope, withIsolationScope, captureCheckIn, From a5140245a0596bfc34ae287c88b5dad152cb47b3 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 12 Feb 2024 09:47:46 -0500 Subject: [PATCH 2/2] fix serverless --- packages/serverless/src/index.ts | 2 -- 1 file changed, 2 deletions(-) diff --git a/packages/serverless/src/index.ts b/packages/serverless/src/index.ts index 74edc639d49b..fe6c47ba8e2c 100644 --- a/packages/serverless/src/index.ts +++ b/packages/serverless/src/index.ts @@ -70,8 +70,6 @@ export { setMeasurement, getActiveSpan, startSpan, - // eslint-disable-next-line deprecation/deprecation - startActiveSpan, startInactiveSpan, startSpanManual, continueTrace,