Skip to content

Commit

Permalink
ref(ember): Use new span APIs (#10111)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhiPrasad authored Jan 9, 2024
1 parent 15ab8ee commit 5623fd8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 33 deletions.
2 changes: 1 addition & 1 deletion packages/ember/addon/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ 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';

import type { Transaction } from '@sentry/types';
import type { EmberSentryConfig, GlobalConfig, OwnConfig } from './types';

function _getSentryInitConfig(): EmberSentryConfig['sentry'] {
Expand Down
51 changes: 19 additions & 32 deletions packages/ember/addon/instance-initializers/sentry-performance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 & {
Expand Down Expand Up @@ -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',
});
});
Expand Down Expand Up @@ -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) {
Expand All @@ -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();
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 5623fd8

Please sign in to comment.