1- import * as Sentry from '@sentry/browser' ;
2- import { SDK_VERSION , BrowserOptions } from '@sentry/browser' ;
3- import { macroCondition , isDevelopingApp , getOwnConfig } from '@embroider/macros' ;
4- import { next } from '@ember/runloop' ;
51import { assert , warn } from '@ember/debug' ;
2+ import type Route from '@ember/routing/route' ;
3+ import { next } from '@ember/runloop' ;
4+ import { getOwnConfig , isDevelopingApp , macroCondition } from '@embroider/macros' ;
5+ import type { BrowserOptions } from '@sentry/browser' ;
6+ import * as Sentry from '@sentry/browser' ;
7+ import { SDK_VERSION } from '@sentry/browser' ;
8+ import type { Transaction } from '@sentry/types' ;
9+ import { GLOBAL_OBJ , timestampInSeconds } from '@sentry/utils' ;
610import Ember from 'ember' ;
7- import { timestampInSeconds , GLOBAL_OBJ } from '@sentry/utils' ;
8- import { GlobalConfig , OwnConfig } from './types' ;
911
10- function _getSentryInitConfig ( ) {
12+ import type { EmberSentryConfig , GlobalConfig , OwnConfig } from './types' ;
13+
14+ function _getSentryInitConfig ( ) : EmberSentryConfig [ 'sentry' ] {
1115 const _global = GLOBAL_OBJ as typeof GLOBAL_OBJ & GlobalConfig ;
1216 _global . __sentryEmberConfig = _global . __sentryEmberConfig ?? { } ;
1317 return _global . __sentryEmberConfig ;
1418}
1519
16- export function InitSentryForEmber ( _runtimeConfig ?: BrowserOptions ) {
20+ export function InitSentryForEmber ( _runtimeConfig ?: BrowserOptions ) : void {
1721 const environmentConfig = getOwnConfig < OwnConfig > ( ) . sentryConfig ;
1822
1923 assert ( 'Missing configuration.' , environmentConfig ) ;
2024 assert ( 'Missing configuration for Sentry.' , environmentConfig . sentry || _runtimeConfig ) ;
2125
2226 if ( ! environmentConfig . sentry ) {
2327 // If environment config is not specified but the above assertion passes, use runtime config.
24- environmentConfig . sentry = { ..._runtimeConfig } as any ;
28+ environmentConfig . sentry = { ..._runtimeConfig } ;
2529 }
2630
2731 // Merge runtime config into environment config, preferring runtime.
@@ -62,12 +66,20 @@ export function InitSentryForEmber(_runtimeConfig?: BrowserOptions) {
6266 }
6367}
6468
65- export const getActiveTransaction = ( ) => {
69+ export const getActiveTransaction = ( ) : Transaction | undefined => {
6670 return Sentry . getCurrentHub ( ) . getScope ( ) . getTransaction ( ) ;
6771} ;
6872
69- export const instrumentRoutePerformance = ( BaseRoute : any ) => {
70- const instrumentFunction = async ( op : string , description : string , fn : Function , args : any ) => {
73+ type RouteConstructor = new ( ...args : ConstructorParameters < typeof Route > ) => Route ;
74+
75+ export const instrumentRoutePerformance = < T extends RouteConstructor > ( BaseRoute : T ) : T => {
76+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
77+ const instrumentFunction = async < X extends ( ...args : unknown [ ] ) => any > (
78+ op : string ,
79+ description : string ,
80+ fn : X ,
81+ args : Parameters < X > ,
82+ ) : Promise < ReturnType < X > > => {
7183 const startTimestamp = timestampInSeconds ( ) ;
7284 const result = await fn ( ...args ) ;
7385
@@ -79,40 +91,38 @@ export const instrumentRoutePerformance = (BaseRoute: any) => {
7991 return result ;
8092 } ;
8193
94+ const routeName = BaseRoute . name ;
95+
8296 return {
83- [ BaseRoute . name ] : class extends BaseRoute {
84- beforeModel ( ...args : any [ ] ) {
97+ // @ts -expect-error TS2545 We do not need to redefine a constructor here
98+ [ routeName ] : class extends BaseRoute {
99+ public beforeModel ( ...args : unknown [ ] ) : void | Promise < unknown > {
85100 return instrumentFunction (
86101 'ui.ember.route.before_model' ,
87- ( < any > this ) . fullRouteName ,
102+ this . fullRouteName ,
88103 super . beforeModel . bind ( this ) ,
89104 args ,
90105 ) ;
91106 }
92107
93- async model ( ...args : any [ ] ) {
94- return instrumentFunction ( 'ui.ember.route.model' , ( < any > this ) . fullRouteName , super . model . bind ( this ) , args ) ;
108+ public async model ( ...args : unknown [ ] ) : Promise < unknown > {
109+ return instrumentFunction ( 'ui.ember.route.model' , this . fullRouteName , super . model . bind ( this ) , args ) ;
95110 }
96111
97- async afterModel ( ...args : any [ ] ) {
98- return instrumentFunction (
99- 'ui.ember.route.after_model' ,
100- ( < any > this ) . fullRouteName ,
101- super . afterModel . bind ( this ) ,
102- args ,
103- ) ;
112+ public afterModel ( ...args : unknown [ ] ) : void | Promise < unknown > {
113+ return instrumentFunction ( 'ui.ember.route.after_model' , this . fullRouteName , super . afterModel . bind ( this ) , args ) ;
104114 }
105115
106- async setupController ( ...args : any [ ] ) {
116+ public setupController ( ...args : unknown [ ] ) : void | Promise < unknown > {
107117 return instrumentFunction (
108118 'ui.ember.route.setup_controller' ,
109- ( < any > this ) . fullRouteName ,
119+ this . fullRouteName ,
110120 super . setupController . bind ( this ) ,
111121 args ,
112122 ) ;
113123 }
114124 } ,
115- } [ BaseRoute . name ] ;
125+ } [ routeName ] as T ;
116126} ;
117127
118128export * from '@sentry/browser' ;
0 commit comments