From 8c8878d91e516ce3b1416e5915f246feb9f7732c Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Mon, 8 Jan 2024 16:03:18 -0500 Subject: [PATCH 1/3] ref(ember): Use new span APIs --- packages/ember/addon/index.ts | 11 ---- .../sentry-performance.ts | 51 +++++++------------ 2 files changed, 19 insertions(+), 43 deletions(-) diff --git a/packages/ember/addon/index.ts b/packages/ember/addon/index.ts index 4179df0d1dd2..8c6e0be76d57 100644 --- a/packages/ember/addon/index.ts +++ b/packages/ember/addon/index.ts @@ -6,7 +6,6 @@ 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 } from '@sentry/utils'; import Ember from 'ember'; @@ -67,16 +66,6 @@ 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(); -}; - type RouteConstructor = new (...args: ConstructorParameters) => Route; export const instrumentRoutePerformance = (BaseRoute: T): T => { diff --git a/packages/ember/addon/instance-initializers/sentry-performance.ts b/packages/ember/addon/instance-initializers/sentry-performance.ts index d61801fa6d17..999474b798bc 100644 --- a/packages/ember/addon/instance-initializers/sentry-performance.ts +++ b/packages/ember/addon/instance-initializers/sentry-performance.ts @@ -12,7 +12,7 @@ import type { Span, Transaction } from '@sentry/types'; import { GLOBAL_OBJ, browserPerformanceTimeOrigin, timestampInSeconds } from '@sentry/utils'; import type { BrowserClient } from '..'; -import { getActiveTransaction } from '..'; +import { getActiveSpan, startInactiveSpan } from '..'; import type { EmberRouterMain, EmberSentryConfig, GlobalConfig, OwnConfig, StartTransactionFunction } from '../types'; type SentryTestRouterService = RouterService & { @@ -149,10 +149,9 @@ export function _instrumentEmberRouter( 'routing.instrumentation': '@sentry/ember', }, }); - // eslint-disable-next-line deprecation/deprecation - transitionSpan = activeTransaction?.startChild({ + transitionSpan = startInactiveSpan({ op: 'ui.ember.transition', - description: `route:${fromRoute} -> route:${toRoute}`, + name: `route:${fromRoute} -> route:${toRoute}`, origin: 'auto.ui.ember', }); }); @@ -196,9 +195,8 @@ function _instrumentEmberRunloop(config: EmberSentryConfig): void { if (previousInstance) { return; } - // eslint-disable-next-line deprecation/deprecation - const activeTransaction = getActiveTransaction(); - if (!activeTransaction) { + const activeSpan = getActiveSpan(); + if (!activeSpan) { return; } if (currentQueueSpan) { @@ -213,24 +211,20 @@ function _instrumentEmberRunloop(config: EmberSentryConfig): void { const minQueueDuration = minimumRunloopQueueDuration ?? 5; if ((now - currentQueueStart) * 1000 >= minQueueDuration) { - activeTransaction - // eslint-disable-next-line deprecation/deprecation - ?.startChild({ - op: `ui.ember.runloop.${queue}`, - origin: 'auto.ui.ember', - startTimestamp: currentQueueStart, - endTimestamp: now, - }) - .end(); + startInactiveSpan({ + name: 'runloop', + op: `ui.ember.runloop.${queue}`, + origin: 'auto.ui.ember', + startTimestamp: currentQueueStart, + })?.end(now); } currentQueueStart = undefined; } // Setup for next queue - // eslint-disable-next-line deprecation/deprecation - const stillActiveTransaction = getActiveTransaction(); - if (!stillActiveTransaction) { + const stillActiveSpan = getActiveSpan(); + if (!stillActiveSpan) { return; } currentQueueStart = timestampInSeconds(); @@ -290,16 +284,12 @@ 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({ + startInactiveSpan({ + name: payload.containerKey || payload.object, op, - description: payload.containerKey || payload.object, origin: 'auto.ui.ember', startTimestamp: begin.now, - endTimestamp: now, - }); + })?.end(now); } } @@ -377,15 +367,12 @@ 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({ + startInactiveSpan({ op: 'ui.ember.init', + name: 'init', origin: 'auto.ui.ember', startTimestamp, - }); - span?.end(endTimestamp); + })?.end(endTimestamp); performance.clearMarks(startName); performance.clearMarks(endName); From 97e08275992ca4295f6686a5d6f89ce802eced3f Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Tue, 9 Jan 2024 09:36:35 -0500 Subject: [PATCH 2/3] add back getActiveTransaction --- packages/ember/addon/index.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/packages/ember/addon/index.ts b/packages/ember/addon/index.ts index 8c6e0be76d57..1e47f661cd2a 100644 --- a/packages/ember/addon/index.ts +++ b/packages/ember/addon/index.ts @@ -9,6 +9,7 @@ import { SDK_VERSION } from '@sentry/browser'; import { GLOBAL_OBJ } from '@sentry/utils'; import Ember from 'ember'; +import type { Transaction } from '@sentry/types'; import type { EmberSentryConfig, GlobalConfig, OwnConfig } from './types'; function _getSentryInitConfig(): EmberSentryConfig['sentry'] { @@ -68,6 +69,11 @@ export function InitSentryForEmber(_runtimeConfig?: BrowserOptions): void { type RouteConstructor = new (...args: ConstructorParameters) => Route; +export const getActiveTransaction = (): Transaction | undefined => { + // eslint-disable-next-line deprecation/deprecation + return Sentry.getCurrentHub().getScope().getTransaction(); +}; + export const instrumentRoutePerformance = (BaseRoute: T): T => { // eslint-disable-next-line @typescript-eslint/no-explicit-any const instrumentFunction = async any>( From 0214c4f3ad877beb288c8cf5b6e30c8d450eb813 Mon Sep 17 00:00:00 2001 From: Abhijeet Prasad Date: Tue, 9 Jan 2024 09:37:30 -0500 Subject: [PATCH 3/3] fix comment --- packages/ember/addon/index.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/ember/addon/index.ts b/packages/ember/addon/index.ts index 1e47f661cd2a..57429c64f789 100644 --- a/packages/ember/addon/index.ts +++ b/packages/ember/addon/index.ts @@ -67,13 +67,18 @@ export function InitSentryForEmber(_runtimeConfig?: BrowserOptions): void { } } -type RouteConstructor = new (...args: ConstructorParameters) => Route; - +/** + * 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(); }; +type RouteConstructor = new (...args: ConstructorParameters) => Route; + export const instrumentRoutePerformance = (BaseRoute: T): T => { // eslint-disable-next-line @typescript-eslint/no-explicit-any const instrumentFunction = async any>(