Skip to content

Commit 8c8878d

Browse files
committed
ref(ember): Use new span APIs
1 parent 4a920b5 commit 8c8878d

File tree

2 files changed

+19
-43
lines changed

2 files changed

+19
-43
lines changed

packages/ember/addon/index.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { startSpan } from '@sentry/browser';
66
import type { BrowserOptions } from '@sentry/browser';
77
import * as Sentry from '@sentry/browser';
88
import { SDK_VERSION } from '@sentry/browser';
9-
import type { Transaction } from '@sentry/types';
109
import { GLOBAL_OBJ } from '@sentry/utils';
1110
import Ember from 'ember';
1211

@@ -67,16 +66,6 @@ export function InitSentryForEmber(_runtimeConfig?: BrowserOptions): void {
6766
}
6867
}
6968

70-
/**
71-
* Grabs active transaction off scope.
72-
*
73-
* @deprecated You should not rely on the transaction, but just use `startSpan()` APIs instead.
74-
*/
75-
export const getActiveTransaction = (): Transaction | undefined => {
76-
// eslint-disable-next-line deprecation/deprecation
77-
return Sentry.getCurrentHub().getScope().getTransaction();
78-
};
79-
8069
type RouteConstructor = new (...args: ConstructorParameters<typeof Route>) => Route;
8170

8271
export const instrumentRoutePerformance = <T extends RouteConstructor>(BaseRoute: T): T => {

packages/ember/addon/instance-initializers/sentry-performance.ts

Lines changed: 19 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import type { Span, Transaction } from '@sentry/types';
1212
import { GLOBAL_OBJ, browserPerformanceTimeOrigin, timestampInSeconds } from '@sentry/utils';
1313

1414
import type { BrowserClient } from '..';
15-
import { getActiveTransaction } from '..';
15+
import { getActiveSpan, startInactiveSpan } from '..';
1616
import type { EmberRouterMain, EmberSentryConfig, GlobalConfig, OwnConfig, StartTransactionFunction } from '../types';
1717

1818
type SentryTestRouterService = RouterService & {
@@ -149,10 +149,9 @@ export function _instrumentEmberRouter(
149149
'routing.instrumentation': '@sentry/ember',
150150
},
151151
});
152-
// eslint-disable-next-line deprecation/deprecation
153-
transitionSpan = activeTransaction?.startChild({
152+
transitionSpan = startInactiveSpan({
154153
op: 'ui.ember.transition',
155-
description: `route:${fromRoute} -> route:${toRoute}`,
154+
name: `route:${fromRoute} -> route:${toRoute}`,
156155
origin: 'auto.ui.ember',
157156
});
158157
});
@@ -196,9 +195,8 @@ function _instrumentEmberRunloop(config: EmberSentryConfig): void {
196195
if (previousInstance) {
197196
return;
198197
}
199-
// eslint-disable-next-line deprecation/deprecation
200-
const activeTransaction = getActiveTransaction();
201-
if (!activeTransaction) {
198+
const activeSpan = getActiveSpan();
199+
if (!activeSpan) {
202200
return;
203201
}
204202
if (currentQueueSpan) {
@@ -213,24 +211,20 @@ function _instrumentEmberRunloop(config: EmberSentryConfig): void {
213211
const minQueueDuration = minimumRunloopQueueDuration ?? 5;
214212

215213
if ((now - currentQueueStart) * 1000 >= minQueueDuration) {
216-
activeTransaction
217-
// eslint-disable-next-line deprecation/deprecation
218-
?.startChild({
219-
op: `ui.ember.runloop.${queue}`,
220-
origin: 'auto.ui.ember',
221-
startTimestamp: currentQueueStart,
222-
endTimestamp: now,
223-
})
224-
.end();
214+
startInactiveSpan({
215+
name: 'runloop',
216+
op: `ui.ember.runloop.${queue}`,
217+
origin: 'auto.ui.ember',
218+
startTimestamp: currentQueueStart,
219+
})?.end(now);
225220
}
226221
currentQueueStart = undefined;
227222
}
228223

229224
// Setup for next queue
230225

231-
// eslint-disable-next-line deprecation/deprecation
232-
const stillActiveTransaction = getActiveTransaction();
233-
if (!stillActiveTransaction) {
226+
const stillActiveSpan = getActiveSpan();
227+
if (!stillActiveSpan) {
234228
return;
235229
}
236230
currentQueueStart = timestampInSeconds();
@@ -290,16 +284,12 @@ function processComponentRenderAfter(
290284
const componentRenderDuration = now - begin.now;
291285

292286
if (componentRenderDuration * 1000 >= minComponentDuration) {
293-
// eslint-disable-next-line deprecation/deprecation
294-
const activeTransaction = getActiveTransaction();
295-
// eslint-disable-next-line deprecation/deprecation
296-
activeTransaction?.startChild({
287+
startInactiveSpan({
288+
name: payload.containerKey || payload.object,
297289
op,
298-
description: payload.containerKey || payload.object,
299290
origin: 'auto.ui.ember',
300291
startTimestamp: begin.now,
301-
endTimestamp: now,
302-
});
292+
})?.end(now);
303293
}
304294
}
305295

@@ -377,15 +367,12 @@ function _instrumentInitialLoad(config: EmberSentryConfig): void {
377367
const startTimestamp = (measure.startTime + browserPerformanceTimeOrigin) / 1000;
378368
const endTimestamp = startTimestamp + measure.duration / 1000;
379369

380-
// eslint-disable-next-line deprecation/deprecation
381-
const transaction = getActiveTransaction();
382-
// eslint-disable-next-line deprecation/deprecation
383-
const span = transaction?.startChild({
370+
startInactiveSpan({
384371
op: 'ui.ember.init',
372+
name: 'init',
385373
origin: 'auto.ui.ember',
386374
startTimestamp,
387-
});
388-
span?.end(endTimestamp);
375+
})?.end(endTimestamp);
389376
performance.clearMarks(startName);
390377
performance.clearMarks(endName);
391378

0 commit comments

Comments
 (0)