diff --git a/MIGRATION.md b/MIGRATION.md index a91ce9ad8e01..812ce2fa8dbe 100644 --- a/MIGRATION.md +++ b/MIGRATION.md @@ -8,6 +8,10 @@ npx @sentry/migr8@latest This will let you select which updates to run, and automatically update your code. Make sure to still review all code changes! +## Deprecate `scope.getTransaction()` and `getActiveTransaction()` + +Instead, you should not rely on the active transaction, but just use `startSpan()` APIs, which handle this for you. + ## Deprecate arguments for `startSpan()` APIs In v8, the API to start a new span will be reduced from the currently available options. diff --git a/dev-packages/node-integration-tests/suites/express/sentry-trace/baggage-header-out/server.ts b/dev-packages/node-integration-tests/suites/express/sentry-trace/baggage-header-out/server.ts index 4f4fc91b670a..11ccc4d732e0 100644 --- a/dev-packages/node-integration-tests/suites/express/sentry-trace/baggage-header-out/server.ts +++ b/dev-packages/node-integration-tests/suites/express/sentry-trace/baggage-header-out/server.ts @@ -26,6 +26,7 @@ app.use(Sentry.Handlers.tracingHandler()); app.use(cors()); app.get('/test/express', (_req, res) => { + // eslint-disable-next-line deprecation/deprecation const transaction = Sentry.getCurrentHub().getScope().getTransaction(); if (transaction) { // eslint-disable-next-line deprecation/deprecation diff --git a/dev-packages/node-integration-tests/suites/express/sentry-trace/baggage-transaction-name/server.ts b/dev-packages/node-integration-tests/suites/express/sentry-trace/baggage-transaction-name/server.ts index 24c3541d8529..3b1fee1bba18 100644 --- a/dev-packages/node-integration-tests/suites/express/sentry-trace/baggage-transaction-name/server.ts +++ b/dev-packages/node-integration-tests/suites/express/sentry-trace/baggage-transaction-name/server.ts @@ -29,6 +29,7 @@ app.use(Sentry.Handlers.tracingHandler()); app.use(cors()); app.get('/test/express', (_req, res) => { + // eslint-disable-next-line deprecation/deprecation const transaction = Sentry.getCurrentHub().getScope().getTransaction(); if (transaction) { // eslint-disable-next-line deprecation/deprecation diff --git a/packages/angular-ivy/README.md b/packages/angular-ivy/README.md index f487ffa22707..6967e7570a82 100644 --- a/packages/angular-ivy/README.md +++ b/packages/angular-ivy/README.md @@ -215,33 +215,22 @@ export class FooterComponent implements OnInit { } ``` -You can also add your own custom spans by attaching them to the current active transaction using `getActiveTransaction` -helper. For example, if you'd like to track the duration of Angular boostraping process, you can do it as follows: +You can also add your own custom spans via `startSpan()`. For example, if you'd like to track the duration of Angular boostraping process, you can do it as follows: ```javascript import { enableProdMode } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; -import { init, getActiveTransaction } from '@sentry/angular-ivy'; +import { init, startSpan } from '@sentry/angular'; import { AppModule } from './app/app.module'; // ... - -const activeTransaction = getActiveTransaction(); -const boostrapSpan = - activeTransaction && - activeTransaction.startChild({ - description: 'platform-browser-dynamic', - op: 'ui.angular.bootstrap', - }); - -platformBrowserDynamic() - .bootstrapModule(AppModule) - .then(() => console.log(`Bootstrap success`)) - .catch(err => console.error(err)); - .finally(() => { - if (bootstrapSpan) { - boostrapSpan.finish(); - } - }) +startSpan({ + name: 'platform-browser-dynamic', + op: 'ui.angular.bootstrap' + }, + async () => { + await platformBrowserDynamic().bootstrapModule(AppModule); + } +); ``` diff --git a/packages/angular/README.md b/packages/angular/README.md index aa18724839a4..302b060bdb39 100644 --- a/packages/angular/README.md +++ b/packages/angular/README.md @@ -215,33 +215,22 @@ export class FooterComponent implements OnInit { } ``` -You can also add your own custom spans by attaching them to the current active transaction using `getActiveTransaction` -helper. For example, if you'd like to track the duration of Angular boostraping process, you can do it as follows: +You can also add your own custom spans via `startSpan()`. For example, if you'd like to track the duration of Angular boostraping process, you can do it as follows: ```javascript import { enableProdMode } from '@angular/core'; import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'; -import { init, getActiveTransaction } from '@sentry/angular'; +import { init, startSpan } from '@sentry/angular'; import { AppModule } from './app/app.module'; // ... - -const activeTransaction = getActiveTransaction(); -const boostrapSpan = - activeTransaction && - activeTransaction.startChild({ - description: 'platform-browser-dynamic', - op: 'ui.angular.bootstrap', - }); - -platformBrowserDynamic() - .bootstrapModule(AppModule) - .then(() => console.log(`Bootstrap success`)) - .catch(err => console.error(err)); - .finally(() => { - if (bootstrapSpan) { - boostrapSpan.finish(); - } - }) +startSpan({ + name: 'platform-browser-dynamic', + op: 'ui.angular.bootstrap' + }, + async () => { + await platformBrowserDynamic().bootstrapModule(AppModule); + } +); ``` diff --git a/packages/angular/src/index.ts b/packages/angular/src/index.ts index b6f188a35d14..f7f0536463a2 100644 --- a/packages/angular/src/index.ts +++ b/packages/angular/src/index.ts @@ -5,6 +5,7 @@ export * from '@sentry/browser'; export { init } from './sdk'; export { createErrorHandler, SentryErrorHandler } from './errorhandler'; export { + // eslint-disable-next-line deprecation/deprecation getActiveTransaction, // TODO `instrumentAngularRouting` is just an alias for `routingInstrumentation`; deprecate the latter at some point instrumentAngularRouting, // new name diff --git a/packages/angular/src/tracing.ts b/packages/angular/src/tracing.ts index c34fa822cb14..c75c10d0c60e 100644 --- a/packages/angular/src/tracing.ts +++ b/packages/angular/src/tracing.ts @@ -47,9 +47,12 @@ export function routingInstrumentation( export const instrumentAngularRouting = routingInstrumentation; /** - * Grabs active transaction off scope + * Grabs active transaction off scope. + * + * @deprecated You should not rely on the transaction, but just use `startSpan()` APIs instead. */ export function getActiveTransaction(): Transaction | undefined { + // eslint-disable-next-line deprecation/deprecation return getCurrentScope().getTransaction(); } @@ -69,6 +72,7 @@ export class TraceService implements OnDestroy { } const strippedUrl = stripUrlQueryAndFragment(navigationEvent.url); + // eslint-disable-next-line deprecation/deprecation let activeTransaction = getActiveTransaction(); if (!activeTransaction && stashedStartTransactionOnLocationChange) { @@ -116,6 +120,7 @@ export class TraceService implements OnDestroy { (event.state as unknown as RouterState & { root: ActivatedRouteSnapshot }).root, ); + // eslint-disable-next-line deprecation/deprecation const transaction = getActiveTransaction(); // TODO (v8 / #5416): revisit the source condition. Do we want to make the parameterized route the default? if (transaction && transaction.metadata.source === 'url') { @@ -182,6 +187,7 @@ export class TraceDirective implements OnInit, AfterViewInit { this.componentName = UNKNOWN_COMPONENT; } + // eslint-disable-next-line deprecation/deprecation const activeTransaction = getActiveTransaction(); if (activeTransaction) { // eslint-disable-next-line deprecation/deprecation @@ -225,6 +231,7 @@ export function TraceClassDecorator(): ClassDecorator { const originalOnInit = target.prototype.ngOnInit; // eslint-disable-next-line @typescript-eslint/no-explicit-any target.prototype.ngOnInit = function (...args: any[]): ReturnType { + // eslint-disable-next-line deprecation/deprecation const activeTransaction = getActiveTransaction(); if (activeTransaction) { // eslint-disable-next-line deprecation/deprecation @@ -263,6 +270,7 @@ export function TraceMethodDecorator(): MethodDecorator { // eslint-disable-next-line @typescript-eslint/no-explicit-any descriptor.value = function (...args: any[]): ReturnType { const now = timestampInSeconds(); + // eslint-disable-next-line deprecation/deprecation const activeTransaction = getActiveTransaction(); if (activeTransaction) { // eslint-disable-next-line deprecation/deprecation diff --git a/packages/astro/src/index.server.ts b/packages/astro/src/index.server.ts index b038e215496d..2eec2fc1e0e9 100644 --- a/packages/astro/src/index.server.ts +++ b/packages/astro/src/index.server.ts @@ -22,6 +22,7 @@ export { createTransport, // eslint-disable-next-line deprecation/deprecation extractTraceparentData, + // eslint-disable-next-line deprecation/deprecation getActiveTransaction, getHubFromCarrier, getCurrentHub, diff --git a/packages/browser/src/index.ts b/packages/browser/src/index.ts index d9afa470b2ba..97abefea8242 100644 --- a/packages/browser/src/index.ts +++ b/packages/browser/src/index.ts @@ -46,6 +46,7 @@ export { setMeasurement, // eslint-disable-next-line deprecation/deprecation extractTraceparentData, + // eslint-disable-next-line deprecation/deprecation getActiveTransaction, spanStatusfromHttpCode, // eslint-disable-next-line deprecation/deprecation diff --git a/packages/browser/src/profiling/integration.ts b/packages/browser/src/profiling/integration.ts index 3f823429c122..b50c60552a7f 100644 --- a/packages/browser/src/profiling/integration.ts +++ b/packages/browser/src/profiling/integration.ts @@ -24,6 +24,7 @@ const browserProfilingIntegration: IntegrationFn = () => { setup(client) { const scope = getCurrentScope(); + // eslint-disable-next-line deprecation/deprecation const transaction = scope.getTransaction(); if (transaction && isAutomatedPageLoadTransaction(transaction)) { diff --git a/packages/browser/test/unit/profiling/integration.test.ts b/packages/browser/test/unit/profiling/integration.test.ts index ae95927ac2cd..bfcdde5c33ea 100644 --- a/packages/browser/test/unit/profiling/integration.test.ts +++ b/packages/browser/test/unit/profiling/integration.test.ts @@ -50,6 +50,7 @@ describe('BrowserProfilingIntegration', () => { const client = Sentry.getClient(); + // eslint-disable-next-line deprecation/deprecation const currentTransaction = Sentry.getCurrentHub().getScope().getTransaction(); expect(currentTransaction?.op).toBe('pageload'); currentTransaction?.end(); diff --git a/packages/bun/src/index.ts b/packages/bun/src/index.ts index 749299badd74..bb033496da02 100644 --- a/packages/bun/src/index.ts +++ b/packages/bun/src/index.ts @@ -39,6 +39,7 @@ export { // eslint-disable-next-line deprecation/deprecation extractTraceparentData, flush, + // eslint-disable-next-line deprecation/deprecation getActiveTransaction, getHubFromCarrier, getCurrentHub, diff --git a/packages/core/src/metrics/exports.ts b/packages/core/src/metrics/exports.ts index 45759982bc14..03e81ed49f0e 100644 --- a/packages/core/src/metrics/exports.ts +++ b/packages/core/src/metrics/exports.ts @@ -30,6 +30,7 @@ function addToMetricsAggregator( } const { unit, tags, timestamp } = data; const { release, environment } = client.getOptions(); + // eslint-disable-next-line deprecation/deprecation const transaction = scope.getTransaction(); const metricTags: Record = {}; if (release) { diff --git a/packages/core/src/scope.ts b/packages/core/src/scope.ts index 8857329de3dd..54bb9fc52b40 100644 --- a/packages/core/src/scope.ts +++ b/packages/core/src/scope.ts @@ -321,7 +321,8 @@ export class Scope implements ScopeInterface { } /** - * @inheritDoc + * Returns the `Transaction` attached to the scope (if there is one). + * @deprecated You should not rely on the transaction, but just use `startSpan()` APIs instead. */ public getTransaction(): Transaction | undefined { // Often, this span (if it exists at all) will be a transaction, but it's not guaranteed to be. Regardless, it will diff --git a/packages/core/src/tracing/errors.ts b/packages/core/src/tracing/errors.ts index 9030f02efadc..5a885dd1f090 100644 --- a/packages/core/src/tracing/errors.ts +++ b/packages/core/src/tracing/errors.ts @@ -27,6 +27,7 @@ export function registerErrorInstrumentation(): void { * If an error or unhandled promise occurs, we mark the active transaction as failed */ function errorCallback(): void { + // eslint-disable-next-line deprecation/deprecation const activeTransaction = getActiveTransaction(); if (activeTransaction) { const status: SpanStatusType = 'internal_error'; diff --git a/packages/core/src/tracing/idletransaction.ts b/packages/core/src/tracing/idletransaction.ts index 16e5fbcc61e8..4643e6b0c97b 100644 --- a/packages/core/src/tracing/idletransaction.ts +++ b/packages/core/src/tracing/idletransaction.ts @@ -196,6 +196,7 @@ export class IdleTransaction extends Transaction { // if `this._onScope` is `true`, the transaction put itself on the scope when it started if (this._onScope) { const scope = this._idleHub.getScope(); + // eslint-disable-next-line deprecation/deprecation if (scope.getTransaction() === this) { scope.setSpan(undefined); } diff --git a/packages/core/src/tracing/measurement.ts b/packages/core/src/tracing/measurement.ts index b13bcb6b5a4a..7fff22688f20 100644 --- a/packages/core/src/tracing/measurement.ts +++ b/packages/core/src/tracing/measurement.ts @@ -6,6 +6,7 @@ import { getActiveTransaction } from './utils'; * Adds a measurement to the current active transaction. */ export function setMeasurement(name: string, value: number, unit: MeasurementUnit): void { + // eslint-disable-next-line deprecation/deprecation const transaction = getActiveTransaction(); if (transaction) { transaction.setMeasurement(name, value, unit); diff --git a/packages/core/src/tracing/utils.ts b/packages/core/src/tracing/utils.ts index f1b4c0f1ae06..bfea3d5d1e28 100644 --- a/packages/core/src/tracing/utils.ts +++ b/packages/core/src/tracing/utils.ts @@ -4,10 +4,15 @@ import { extractTraceparentData as _extractTraceparentData } from '@sentry/utils import type { Hub } from '../hub'; import { getCurrentHub } from '../hub'; -/** Grabs active transaction off scope, if any */ +/** + * Grabs active transaction off scope. + * + * @deprecated You should not rely on the transaction, but just use `startSpan()` APIs instead. + */ export function getActiveTransaction(maybeHub?: Hub): T | undefined { const hub = maybeHub || getCurrentHub(); const scope = hub.getScope(); + // eslint-disable-next-line deprecation/deprecation return scope.getTransaction() as T | undefined; } diff --git a/packages/deno/src/index.ts b/packages/deno/src/index.ts index f70d511ae8a3..2658d6f31e36 100644 --- a/packages/deno/src/index.ts +++ b/packages/deno/src/index.ts @@ -38,6 +38,7 @@ export { extractTraceparentData, continueTrace, flush, + // eslint-disable-next-line deprecation/deprecation getActiveTransaction, getHubFromCarrier, getCurrentHub, diff --git a/packages/ember/addon/index.ts b/packages/ember/addon/index.ts index 4f62a19b3ba3..4179df0d1dd2 100644 --- a/packages/ember/addon/index.ts +++ b/packages/ember/addon/index.ts @@ -2,11 +2,12 @@ import { assert, warn } from '@ember/debug'; import type Route from '@ember/routing/route'; import { next } from '@ember/runloop'; import { getOwnConfig, isDevelopingApp, macroCondition } from '@embroider/macros'; +import { startSpan } from '@sentry/browser'; import type { BrowserOptions } from '@sentry/browser'; import * as Sentry from '@sentry/browser'; import { SDK_VERSION } from '@sentry/browser'; import type { Transaction } from '@sentry/types'; -import { GLOBAL_OBJ, timestampInSeconds } from '@sentry/utils'; +import { GLOBAL_OBJ } from '@sentry/utils'; import Ember from 'ember'; import type { EmberSentryConfig, GlobalConfig, OwnConfig } from './types'; @@ -66,7 +67,13 @@ export function InitSentryForEmber(_runtimeConfig?: BrowserOptions): void { } } +/** + * Grabs active transaction off scope. + * + * @deprecated You should not rely on the transaction, but just use `startSpan()` APIs instead. + */ export const getActiveTransaction = (): Transaction | undefined => { + // eslint-disable-next-line deprecation/deprecation return Sentry.getCurrentHub().getScope().getTransaction(); }; @@ -80,23 +87,16 @@ export const instrumentRoutePerformance = (BaseRoute fn: X, args: Parameters, ): Promise> => { - const startTimestamp = timestampInSeconds(); - const result = await fn(...args); - - const currentTransaction = getActiveTransaction(); - if (!currentTransaction) { - return result; - } - currentTransaction - // eslint-disable-next-line deprecation/deprecation - .startChild({ + return startSpan( + { op, - description, + name: description, origin: 'auto.ui.ember', - startTimestamp, - }) - .end(); - return result; + }, + () => { + return fn(...args); + }, + ); }; const routeName = BaseRoute.name; diff --git a/packages/ember/addon/instance-initializers/sentry-performance.ts b/packages/ember/addon/instance-initializers/sentry-performance.ts index 1a502d052774..d61801fa6d17 100644 --- a/packages/ember/addon/instance-initializers/sentry-performance.ts +++ b/packages/ember/addon/instance-initializers/sentry-performance.ts @@ -196,6 +196,7 @@ function _instrumentEmberRunloop(config: EmberSentryConfig): void { if (previousInstance) { return; } + // eslint-disable-next-line deprecation/deprecation const activeTransaction = getActiveTransaction(); if (!activeTransaction) { return; @@ -227,6 +228,7 @@ function _instrumentEmberRunloop(config: EmberSentryConfig): void { // Setup for next queue + // eslint-disable-next-line deprecation/deprecation const stillActiveTransaction = getActiveTransaction(); if (!stillActiveTransaction) { return; @@ -288,6 +290,7 @@ function processComponentRenderAfter( const componentRenderDuration = now - begin.now; if (componentRenderDuration * 1000 >= minComponentDuration) { + // eslint-disable-next-line deprecation/deprecation const activeTransaction = getActiveTransaction(); // eslint-disable-next-line deprecation/deprecation activeTransaction?.startChild({ @@ -374,6 +377,7 @@ function _instrumentInitialLoad(config: EmberSentryConfig): void { const startTimestamp = (measure.startTime + browserPerformanceTimeOrigin) / 1000; const endTimestamp = startTimestamp + measure.duration / 1000; + // eslint-disable-next-line deprecation/deprecation const transaction = getActiveTransaction(); // eslint-disable-next-line deprecation/deprecation const span = transaction?.startChild({ diff --git a/packages/nextjs/src/common/utils/wrapperUtils.ts b/packages/nextjs/src/common/utils/wrapperUtils.ts index d5013675486d..be00cb4c7a2a 100644 --- a/packages/nextjs/src/common/utils/wrapperUtils.ts +++ b/packages/nextjs/src/common/utils/wrapperUtils.ts @@ -194,6 +194,7 @@ export async function callDataFetcherTraced Promis ): Promise> { const { parameterizedRoute, dataFetchingMethodName } = options; + // eslint-disable-next-line deprecation/deprecation const transaction = getActiveTransaction(); if (!transaction) { diff --git a/packages/nextjs/src/common/wrapAppGetInitialPropsWithSentry.ts b/packages/nextjs/src/common/wrapAppGetInitialPropsWithSentry.ts index cd6cc4934493..c965cacb3c32 100644 --- a/packages/nextjs/src/common/wrapAppGetInitialPropsWithSentry.ts +++ b/packages/nextjs/src/common/wrapAppGetInitialPropsWithSentry.ts @@ -52,6 +52,7 @@ export function wrapAppGetInitialPropsWithSentry(origAppGetInitialProps: AppGetI }; } = await tracedGetInitialProps.apply(thisArg, args); + // eslint-disable-next-line deprecation/deprecation const requestTransaction = getTransactionFromRequest(req) ?? getCurrentScope().getTransaction(); // Per definition, `pageProps` is not optional, however an increased amount of users doesn't seem to call diff --git a/packages/nextjs/src/common/wrapErrorGetInitialPropsWithSentry.ts b/packages/nextjs/src/common/wrapErrorGetInitialPropsWithSentry.ts index b26e4a2434c3..413c350ef14f 100644 --- a/packages/nextjs/src/common/wrapErrorGetInitialPropsWithSentry.ts +++ b/packages/nextjs/src/common/wrapErrorGetInitialPropsWithSentry.ts @@ -53,6 +53,7 @@ export function wrapErrorGetInitialPropsWithSentry( _sentryBaggage?: string; } = await tracedGetInitialProps.apply(thisArg, args); + // eslint-disable-next-line deprecation/deprecation const requestTransaction = getTransactionFromRequest(req) ?? getCurrentScope().getTransaction(); if (requestTransaction) { errorGetInitialProps._sentryTraceData = spanToTraceHeader(requestTransaction); diff --git a/packages/nextjs/src/common/wrapGetInitialPropsWithSentry.ts b/packages/nextjs/src/common/wrapGetInitialPropsWithSentry.ts index df4e3febfefc..8263f00c3dcb 100644 --- a/packages/nextjs/src/common/wrapGetInitialPropsWithSentry.ts +++ b/packages/nextjs/src/common/wrapGetInitialPropsWithSentry.ts @@ -49,6 +49,7 @@ export function wrapGetInitialPropsWithSentry(origGetInitialProps: GetInitialPro _sentryBaggage?: string; } = (await tracedGetInitialProps.apply(thisArg, args)) ?? {}; // Next.js allows undefined to be returned from a getInitialPropsFunction. + // eslint-disable-next-line deprecation/deprecation const requestTransaction = getTransactionFromRequest(req) ?? getCurrentScope().getTransaction(); if (requestTransaction) { initialProps._sentryTraceData = spanToTraceHeader(requestTransaction); diff --git a/packages/nextjs/src/common/wrapGetServerSidePropsWithSentry.ts b/packages/nextjs/src/common/wrapGetServerSidePropsWithSentry.ts index c74f9db7292b..fff92d31f49b 100644 --- a/packages/nextjs/src/common/wrapGetServerSidePropsWithSentry.ts +++ b/packages/nextjs/src/common/wrapGetServerSidePropsWithSentry.ts @@ -46,6 +46,7 @@ export function wrapGetServerSidePropsWithSentry( >); if (serverSideProps && 'props' in serverSideProps) { + // eslint-disable-next-line deprecation/deprecation const requestTransaction = getTransactionFromRequest(req) ?? getCurrentScope().getTransaction(); if (requestTransaction) { serverSideProps.props._sentryTraceData = spanToTraceHeader(requestTransaction); diff --git a/packages/node/src/handlers.ts b/packages/node/src/handlers.ts index 6d4c6f5a4494..cc4877125507 100644 --- a/packages/node/src/handlers.ts +++ b/packages/node/src/handlers.ts @@ -328,6 +328,7 @@ interface TrpcMiddlewareArguments { export function trpcMiddleware(options: SentryTrpcMiddlewareOptions = {}) { return function ({ path, type, next, rawInput }: TrpcMiddlewareArguments): T { const clientOptions = getClient()?.getOptions(); + // eslint-disable-next-line deprecation/deprecation const sentryTransaction = getCurrentScope().getTransaction(); if (sentryTransaction) { diff --git a/packages/node/src/index.ts b/packages/node/src/index.ts index 47206462b937..f7e2132cce65 100644 --- a/packages/node/src/index.ts +++ b/packages/node/src/index.ts @@ -38,6 +38,7 @@ export { // eslint-disable-next-line deprecation/deprecation extractTraceparentData, flush, + // eslint-disable-next-line deprecation/deprecation getActiveTransaction, getHubFromCarrier, getCurrentHub, diff --git a/packages/node/src/integrations/hapi/index.ts b/packages/node/src/integrations/hapi/index.ts index 409470680a73..f63207b59c7a 100644 --- a/packages/node/src/integrations/hapi/index.ts +++ b/packages/node/src/integrations/hapi/index.ts @@ -45,6 +45,7 @@ export const hapiErrorPlugin = { const server = serverArg as unknown as Server; server.events.on('request', (request, event) => { + // eslint-disable-next-line deprecation/deprecation const transaction = getActiveTransaction(); if (request.response && isBoomObject(request.response)) { @@ -91,6 +92,7 @@ export const hapiTracingPlugin = { }); server.ext('onPreResponse', (request, h) => { + // eslint-disable-next-line deprecation/deprecation const transaction = getActiveTransaction(); if (request.response && isResponseObject(request.response) && transaction) { @@ -110,6 +112,7 @@ export const hapiTracingPlugin = { }); server.ext('onPostHandler', (request, h) => { + // eslint-disable-next-line deprecation/deprecation const transaction = getActiveTransaction(); if (request.response && isResponseObject(request.response) && transaction) { diff --git a/packages/node/test/handlers.test.ts b/packages/node/test/handlers.test.ts index 0eb1237053ad..d234994455bf 100644 --- a/packages/node/test/handlers.test.ts +++ b/packages/node/test/handlers.test.ts @@ -340,6 +340,7 @@ describe('tracingHandler', () => { sentryTracingMiddleware(req, res, next); + // eslint-disable-next-line deprecation/deprecation const transaction = sentryCore.getCurrentHub().getScope().getTransaction(); expect(transaction).toBeDefined(); @@ -463,6 +464,7 @@ describe('tracingHandler', () => { sentryTracingMiddleware(req, res, next); + // eslint-disable-next-line deprecation/deprecation const transaction = sentryCore.getCurrentScope().getTransaction(); expect(transaction?.metadata.request).toEqual(req); diff --git a/packages/react/src/profiler.tsx b/packages/react/src/profiler.tsx index 43a8f166d48b..d3bdd1ed06aa 100644 --- a/packages/react/src/profiler.tsx +++ b/packages/react/src/profiler.tsx @@ -227,6 +227,7 @@ export { withProfiler, Profiler, useProfiler }; export function getActiveTransaction(hub: Hub = getCurrentHub()): T | undefined { if (hub) { const scope = hub.getScope(); + // eslint-disable-next-line deprecation/deprecation return scope.getTransaction() as T | undefined; } diff --git a/packages/remix/src/index.server.ts b/packages/remix/src/index.server.ts index b28ce95caa61..f30b5311d0f6 100644 --- a/packages/remix/src/index.server.ts +++ b/packages/remix/src/index.server.ts @@ -25,6 +25,7 @@ export { createTransport, // eslint-disable-next-line deprecation/deprecation extractTraceparentData, + // eslint-disable-next-line deprecation/deprecation getActiveTransaction, getHubFromCarrier, getCurrentHub, diff --git a/packages/remix/src/utils/instrumentServer.ts b/packages/remix/src/utils/instrumentServer.ts index fc8e8405fd84..b1383725a94d 100644 --- a/packages/remix/src/utils/instrumentServer.ts +++ b/packages/remix/src/utils/instrumentServer.ts @@ -141,6 +141,7 @@ export async function captureRemixServerException(err: unknown, name: string, re const objectifiedErr = objectify(err); captureException(isResponse(objectifiedErr) ? await extractResponseError(objectifiedErr) : objectifiedErr, scope => { + // eslint-disable-next-line deprecation/deprecation const transaction = getActiveTransaction(); const activeTransactionName = transaction ? spanToJSON(transaction) : undefined; @@ -183,6 +184,7 @@ function makeWrappedDocumentRequestFunction(remixVersion?: number) { loadContext?: Record, ): Promise { let res: Response; + // eslint-disable-next-line deprecation/deprecation const activeTransaction = getActiveTransaction(); try { @@ -238,6 +240,7 @@ function makeWrappedDataFunction( } let res: Response | AppData; + // eslint-disable-next-line deprecation/deprecation const activeTransaction = getActiveTransaction(); const currentScope = getCurrentScope(); @@ -294,6 +297,7 @@ function getTraceAndBaggage(): { sentryTrace?: string; sentryBaggage?: string; } { + // eslint-disable-next-line deprecation/deprecation const transaction = getActiveTransaction(); const currentScope = getCurrentScope(); diff --git a/packages/replay/src/replay.ts b/packages/replay/src/replay.ts index b3a1f48d162f..20e59da7a902 100644 --- a/packages/replay/src/replay.ts +++ b/packages/replay/src/replay.ts @@ -699,6 +699,7 @@ export class ReplayContainer implements ReplayContainerInterface { * This is only available if performance is enabled, and if an instrumented router is used. */ public getCurrentRoute(): string | undefined { + // eslint-disable-next-line deprecation/deprecation const lastTransaction = this.lastTransaction || getCurrentScope().getTransaction(); if (!lastTransaction || !['route', 'custom'].includes(lastTransaction.metadata.source)) { return undefined; diff --git a/packages/serverless/src/awsservices.ts b/packages/serverless/src/awsservices.ts index 7dc3ef010abd..41b73f58464e 100644 --- a/packages/serverless/src/awsservices.ts +++ b/packages/serverless/src/awsservices.ts @@ -58,6 +58,7 @@ function wrapMakeRequest( return function (this: TService, operation: string, params?: GenericParams, callback?: MakeRequestCallback) { let span: Span | undefined; const scope = getCurrentScope(); + // eslint-disable-next-line deprecation/deprecation const transaction = scope.getTransaction(); const req = orig.call(this, operation, params); req.on('afterBuild', () => { diff --git a/packages/serverless/src/google-cloud-grpc.ts b/packages/serverless/src/google-cloud-grpc.ts index d3815422e4df..74a88f622333 100644 --- a/packages/serverless/src/google-cloud-grpc.ts +++ b/packages/serverless/src/google-cloud-grpc.ts @@ -109,6 +109,7 @@ function fillGrpcFunction(stub: Stub, serviceIdentifier: string, methodName: str } let span: Span | undefined; const scope = getCurrentScope(); + // eslint-disable-next-line deprecation/deprecation const transaction = scope.getTransaction(); if (transaction) { // eslint-disable-next-line deprecation/deprecation diff --git a/packages/serverless/src/google-cloud-http.ts b/packages/serverless/src/google-cloud-http.ts index 813d65add0e5..87687a52f82e 100644 --- a/packages/serverless/src/google-cloud-http.ts +++ b/packages/serverless/src/google-cloud-http.ts @@ -53,6 +53,7 @@ function wrapRequestFunction(orig: RequestFunction): RequestFunction { return function (this: common.Service, reqOpts: RequestOptions, callback: ResponseCallback): void { let span: Span | undefined; const scope = getCurrentScope(); + // eslint-disable-next-line deprecation/deprecation const transaction = scope.getTransaction(); if (transaction) { const httpMethod = reqOpts.method || 'GET'; diff --git a/packages/serverless/src/index.ts b/packages/serverless/src/index.ts index ce076283b635..749909e39272 100644 --- a/packages/serverless/src/index.ts +++ b/packages/serverless/src/index.ts @@ -27,6 +27,7 @@ export { // eslint-disable-next-line deprecation/deprecation configureScope, createTransport, + // eslint-disable-next-line deprecation/deprecation getActiveTransaction, getCurrentHub, getClient, diff --git a/packages/svelte/src/performance.ts b/packages/svelte/src/performance.ts index e3ba158e6f59..f0aa16d0c961 100644 --- a/packages/svelte/src/performance.ts +++ b/packages/svelte/src/performance.ts @@ -94,5 +94,6 @@ function recordUpdateSpans(componentName: string, initSpan?: Span): void { } function getActiveTransaction(): Transaction | undefined { + // eslint-disable-next-line deprecation/deprecation return getCurrentScope().getTransaction(); } diff --git a/packages/sveltekit/src/client/router.ts b/packages/sveltekit/src/client/router.ts index 2250943909ab..ab967a9d0f13 100644 --- a/packages/sveltekit/src/client/router.ts +++ b/packages/sveltekit/src/client/router.ts @@ -98,6 +98,7 @@ function instrumentNavigations(startTransactionFn: (context: TransactionContext) const parameterizedRouteOrigin = from && from.route.id; const parameterizedRouteDestination = to && to.route.id; + // eslint-disable-next-line deprecation/deprecation activeTransaction = getActiveTransaction(); if (!activeTransaction) { diff --git a/packages/sveltekit/src/server/handle.ts b/packages/sveltekit/src/server/handle.ts index 540de96c6de9..d6eb5555fefd 100644 --- a/packages/sveltekit/src/server/handle.ts +++ b/packages/sveltekit/src/server/handle.ts @@ -95,6 +95,7 @@ export function addSentryCodeToPage(options: SentryHandleOptions): NonNullable { + // eslint-disable-next-line deprecation/deprecation const transaction = getActiveTransaction(); if (transaction) { const traceparentData = spanToTraceHeader(transaction); diff --git a/packages/sveltekit/src/server/index.ts b/packages/sveltekit/src/server/index.ts index 61419c196736..e224df7421a2 100644 --- a/packages/sveltekit/src/server/index.ts +++ b/packages/sveltekit/src/server/index.ts @@ -19,6 +19,7 @@ export { createTransport, // eslint-disable-next-line deprecation/deprecation extractTraceparentData, + // eslint-disable-next-line deprecation/deprecation getActiveTransaction, getHubFromCarrier, getCurrentHub, diff --git a/packages/tracing-internal/src/browser/backgroundtab.ts b/packages/tracing-internal/src/browser/backgroundtab.ts index e13b997b16db..67385b665be4 100644 --- a/packages/tracing-internal/src/browser/backgroundtab.ts +++ b/packages/tracing-internal/src/browser/backgroundtab.ts @@ -12,6 +12,7 @@ import { WINDOW } from './types'; export function registerBackgroundTabDetection(): void { if (WINDOW && WINDOW.document) { WINDOW.document.addEventListener('visibilitychange', () => { + // eslint-disable-next-line deprecation/deprecation const activeTransaction = getActiveTransaction() as IdleTransaction; if (WINDOW.document.hidden && activeTransaction) { const statusType: SpanStatusType = 'cancelled'; diff --git a/packages/tracing-internal/src/browser/browsertracing.ts b/packages/tracing-internal/src/browser/browsertracing.ts index 09209e2655c1..687f5c057ded 100644 --- a/packages/tracing-internal/src/browser/browsertracing.ts +++ b/packages/tracing-internal/src/browser/browsertracing.ts @@ -390,6 +390,7 @@ export class BrowserTracing implements Integration { const { idleTimeout, finalTimeout, heartbeatInterval } = this.options; const op = 'ui.action.click'; + // eslint-disable-next-line deprecation/deprecation const currentTransaction = getActiveTransaction(); if (currentTransaction && currentTransaction.op && ['navigation', 'pageload'].includes(currentTransaction.op)) { DEBUG_BUILD && diff --git a/packages/tracing-internal/src/browser/metrics/index.ts b/packages/tracing-internal/src/browser/metrics/index.ts index beb98783d8fd..72cce4f7aad6 100644 --- a/packages/tracing-internal/src/browser/metrics/index.ts +++ b/packages/tracing-internal/src/browser/metrics/index.ts @@ -69,6 +69,7 @@ export function startTrackingWebVitals(): () => void { export function startTrackingLongTasks(): void { addPerformanceInstrumentationHandler('longtask', ({ entries }) => { for (const entry of entries) { + // eslint-disable-next-line deprecation/deprecation const transaction = getActiveTransaction() as IdleTransaction | undefined; if (!transaction) { return; @@ -94,6 +95,7 @@ export function startTrackingLongTasks(): void { export function startTrackingInteractions(): void { addPerformanceInstrumentationHandler('event', ({ entries }) => { for (const entry of entries) { + // eslint-disable-next-line deprecation/deprecation const transaction = getActiveTransaction() as IdleTransaction | undefined; if (!transaction) { return; diff --git a/packages/tracing-internal/src/exports/index.ts b/packages/tracing-internal/src/exports/index.ts index 7b7f81a9caa1..8c10b3165608 100644 --- a/packages/tracing-internal/src/exports/index.ts +++ b/packages/tracing-internal/src/exports/index.ts @@ -1,6 +1,7 @@ export { // eslint-disable-next-line deprecation/deprecation extractTraceparentData, + // eslint-disable-next-line deprecation/deprecation getActiveTransaction, hasTracingEnabled, IdleTransaction, diff --git a/packages/tracing/src/index.ts b/packages/tracing/src/index.ts index a515db240117..8559188884d7 100644 --- a/packages/tracing/src/index.ts +++ b/packages/tracing/src/index.ts @@ -62,6 +62,7 @@ export const addExtensionMethods = addExtensionMethodsT; * * `getActiveTransaction` can be imported from `@sentry/node`, `@sentry/browser`, or your framework SDK */ +// eslint-disable-next-line deprecation/deprecation export const getActiveTransaction = getActiveTransactionT; /** diff --git a/packages/tracing/test/idletransaction.test.ts b/packages/tracing/test/idletransaction.test.ts index 729b63074700..7e6b186ea82f 100644 --- a/packages/tracing/test/idletransaction.test.ts +++ b/packages/tracing/test/idletransaction.test.ts @@ -34,6 +34,7 @@ describe('IdleTransaction', () => { transaction.initSpanRecorder(10); const scope = hub.getScope(); + // eslint-disable-next-line deprecation/deprecation expect(scope.getTransaction()).toBe(transaction); }); @@ -42,6 +43,7 @@ describe('IdleTransaction', () => { transaction.initSpanRecorder(10); const scope = hub.getScope(); + // eslint-disable-next-line deprecation/deprecation expect(scope.getTransaction()).toBe(undefined); }); @@ -60,6 +62,7 @@ describe('IdleTransaction', () => { jest.runAllTimers(); const scope = hub.getScope(); + // eslint-disable-next-line deprecation/deprecation expect(scope.getTransaction()).toBe(undefined); }); @@ -77,6 +80,7 @@ describe('IdleTransaction', () => { jest.runAllTimers(); const scope = hub.getScope(); + // eslint-disable-next-line deprecation/deprecation expect(scope.getTransaction()).toBe(undefined); }); @@ -99,6 +103,7 @@ describe('IdleTransaction', () => { jest.runAllTimers(); const scope = hub.getScope(); + // eslint-disable-next-line deprecation/deprecation expect(scope.getTransaction()).toBe(otherTransaction); }); }); diff --git a/packages/types/src/scope.ts b/packages/types/src/scope.ts index 7cbe7ff264b5..8d6c1a9d26aa 100644 --- a/packages/types/src/scope.ts +++ b/packages/types/src/scope.ts @@ -147,7 +147,8 @@ export interface Scope { getSpan(): Span | undefined; /** - * Returns the `Transaction` attached to the scope (if there is one) + * Returns the `Transaction` attached to the scope (if there is one). + * @deprecated You should not rely on the transaction, but just use `startSpan()` APIs instead. */ getTransaction(): Transaction | undefined; diff --git a/packages/vercel-edge/src/index.ts b/packages/vercel-edge/src/index.ts index ff8d97fbf398..515b9c8691b7 100644 --- a/packages/vercel-edge/src/index.ts +++ b/packages/vercel-edge/src/index.ts @@ -38,6 +38,7 @@ export { // eslint-disable-next-line deprecation/deprecation extractTraceparentData, flush, + // eslint-disable-next-line deprecation/deprecation getActiveTransaction, getHubFromCarrier, getCurrentHub, diff --git a/packages/vue/src/router.ts b/packages/vue/src/router.ts index 70117e960fe2..5acc19bb825c 100644 --- a/packages/vue/src/router.ts +++ b/packages/vue/src/router.ts @@ -108,6 +108,7 @@ export function vueRouterInstrumentation( } if (startTransactionOnPageLoad && isPageLoadNavigation) { + // eslint-disable-next-line deprecation/deprecation const pageloadTransaction = getActiveTransaction(); if (pageloadTransaction) { if (pageloadTransaction.metadata.source !== 'custom') { diff --git a/packages/vue/src/tracing.ts b/packages/vue/src/tracing.ts index 2fede1c740c8..cff758c4b571 100644 --- a/packages/vue/src/tracing.ts +++ b/packages/vue/src/tracing.ts @@ -32,8 +32,13 @@ const HOOKS: { [key in Operation]: Hook[] } = { update: ['beforeUpdate', 'updated'], }; -/** Grabs active transaction off scope, if any */ +/** + * Grabs active transaction off scope. + * + * @deprecated You should not rely on the transaction, but just use `startSpan()` APIs instead. + */ export function getActiveTransaction(): Transaction | undefined { + // eslint-disable-next-line deprecation/deprecation return getCurrentScope().getTransaction(); } @@ -73,6 +78,7 @@ export const createTracingMixins = (options: TracingOptions): Mixins => { const isRoot = this.$root === this; if (isRoot) { + // eslint-disable-next-line deprecation/deprecation const activeTransaction = getActiveTransaction(); if (activeTransaction) { this.$_sentryRootSpan = @@ -102,6 +108,7 @@ export const createTracingMixins = (options: TracingOptions): Mixins => { // Start a new span if current hook is a 'before' hook. // Otherwise, retrieve the current span and finish it. if (internalHook == internalHooks[0]) { + // eslint-disable-next-line deprecation/deprecation const activeTransaction = (this.$root && this.$root.$_sentryRootSpan) || getActiveTransaction(); if (activeTransaction) { // Cancel old span for this hook operation in case it didn't get cleaned up. We're not actually sure if it