@@ -9,6 +9,7 @@ import { getActiveTransaction } from '..';
9
9
import { browserPerformanceTimeOrigin , GLOBAL_OBJ , timestampWithMs } from '@sentry/utils' ;
10
10
import { macroCondition , isTesting , getOwnConfig } from '@embroider/macros' ;
11
11
import { EmberSentryConfig , GlobalConfig , OwnConfig } from '../types' ;
12
+ import RouterService from '@ember/routing/router-service' ;
12
13
13
14
function getSentryConfig ( ) {
14
15
const _global = GLOBAL_OBJ as typeof GLOBAL_OBJ & GlobalConfig ;
@@ -308,24 +309,21 @@ function _instrumentInitialLoad(config: EmberSentryConfig) {
308
309
const startName = '@sentry/ember:initial-load-start' ;
309
310
const endName = '@sentry/ember:initial-load-end' ;
310
311
311
- const { performance } = window ;
312
- // @ts -ignore
313
- const HAS_PERFORMANCE = performance && performance . clearMarks && performance . clearMeasures ;
312
+ let { HAS_PERFORMANCE , HAS_PERFORMANCE_TIMING } = _hasPerformanceSupport ( ) ;
314
313
315
314
if ( ! HAS_PERFORMANCE ) {
316
315
return ;
317
316
}
318
317
318
+ const { performance } = window ;
319
+
319
320
if ( config . disableInitialLoadInstrumentation ) {
320
321
performance . clearMarks ( startName ) ;
321
322
performance . clearMarks ( endName ) ;
322
323
return ;
323
324
}
324
325
325
326
// Split performance check in two so clearMarks still happens even if timeOrigin isn't available.
326
- const HAS_PERFORMANCE_TIMING =
327
- // @ts -ignore
328
- performance . measure && performance . getEntriesByName && browserPerformanceTimeOrigin !== undefined ;
329
327
if ( ! HAS_PERFORMANCE_TIMING ) {
330
328
return ;
331
329
}
@@ -356,6 +354,26 @@ function _instrumentInitialLoad(config: EmberSentryConfig) {
356
354
performance . clearMeasures ( measureName ) ;
357
355
}
358
356
357
+ function _hasPerformanceSupport ( ) {
358
+ // TS says that all of these methods are always available, but some of them may not be supported in older browsers
359
+ // So we "pretend" they are all optional in order to be able to check this properly without TS complaining
360
+ const _performance = window . performance as {
361
+ clearMarks ?: Performance [ 'clearMarks' ] ;
362
+ clearMeasures ?: Performance [ 'clearMeasures' ] ;
363
+ measure ?: Performance [ 'measure' ] ;
364
+ getEntriesByName ?: Performance [ 'getEntriesByName' ] ;
365
+ } ;
366
+ const HAS_PERFORMANCE = Boolean ( _performance && _performance . clearMarks && _performance . clearMeasures ) ;
367
+ const HAS_PERFORMANCE_TIMING = Boolean (
368
+ _performance . measure && _performance . getEntriesByName && browserPerformanceTimeOrigin !== undefined ,
369
+ ) ;
370
+
371
+ return {
372
+ HAS_PERFORMANCE ,
373
+ HAS_PERFORMANCE_TIMING ,
374
+ } ;
375
+ }
376
+
359
377
export async function instrumentForPerformance ( appInstance : ApplicationInstance ) {
360
378
const config = getSentryConfig ( ) ;
361
379
const sentryConfig = config . sentry ;
@@ -373,7 +391,9 @@ export async function instrumentForPerformance(appInstance: ApplicationInstance)
373
391
new tracing . Integrations . BrowserTracing ( {
374
392
routingInstrumentation : ( customStartTransaction , startTransactionOnPageLoad ) => {
375
393
const routerMain = appInstance . lookup ( 'router:main' ) ;
376
- let routerService = appInstance . lookup ( 'service:router' ) ;
394
+ let routerService = appInstance . lookup ( 'service:router' ) as
395
+ | RouterService & { externalRouter ?: RouterService ; _hasMountedSentryPerformanceRouting ?: boolean } ;
396
+
377
397
if ( routerService . externalRouter ) {
378
398
// Using ember-engines-router-service in an engine.
379
399
routerService = routerService . externalRouter ;
0 commit comments