Skip to content

ref(ember): Use new span APIs #10111

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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