From 6a6905eeaf328000ed57d3eeeb10c64635f0dfbc Mon Sep 17 00:00:00 2001 From: k-fish Date: Thu, 6 Oct 2022 14:35:45 -0700 Subject: [PATCH] feat(ember): Add ember-engine-router support When using engines and the 'ember-engines-router-service' addon, this will allow performance monitoring to work, which was previously causing an error since the ember-engines-router-service router doesn't have a 'recognize' function. This hooks into the main router for the application instead, and only setups up route change listening once for navigation transactions. --- .../instance-initializers/sentry-performance.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/packages/ember/addon/instance-initializers/sentry-performance.ts b/packages/ember/addon/instance-initializers/sentry-performance.ts index 8f992f8716cc..108a6bc11b67 100644 --- a/packages/ember/addon/instance-initializers/sentry-performance.ts +++ b/packages/ember/addon/instance-initializers/sentry-performance.ts @@ -372,7 +372,20 @@ export async function instrumentForPerformance(appInstance: ApplicationInstance) new tracing.Integrations.BrowserTracing({ routingInstrumentation: (customStartTransaction, startTransactionOnPageLoad) => { const routerMain = appInstance.lookup('router:main'); - const routerService = appInstance.lookup('service:router'); + let routerService = appInstance.lookup('service:router'); + if (routerService.externalRouter) { + // Using ember-engines-router-service in an engine. + routerService = routerService.externalRouter; + } + if (routerService._hasMountedSentryPerformanceRouting) { + // Routing listens to route changes on the main router, and should not be initialized multiple times per page. + return; + } + if (!routerService.recognize) { + // Router is missing critical functionality to limit cardinality of the transaction names. + return; + } + routerService._hasMountedSentryPerformanceRouting = true; _instrumentEmberRouter(routerService, routerMain, config, customStartTransaction, startTransactionOnPageLoad); }, idleTimeout,