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' ;
5
1
import { 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' ;
6
10
import Ember from 'ember' ;
7
- import { timestampInSeconds , GLOBAL_OBJ } from '@sentry/utils' ;
8
- import { GlobalConfig , OwnConfig } from './types' ;
9
11
10
- function _getSentryInitConfig ( ) {
12
+ import type { EmberSentryConfig , GlobalConfig , OwnConfig } from './types' ;
13
+
14
+ function _getSentryInitConfig ( ) : EmberSentryConfig [ 'sentry' ] {
11
15
const _global = GLOBAL_OBJ as typeof GLOBAL_OBJ & GlobalConfig ;
12
16
_global . __sentryEmberConfig = _global . __sentryEmberConfig ?? { } ;
13
17
return _global . __sentryEmberConfig ;
14
18
}
15
19
16
- export function InitSentryForEmber ( _runtimeConfig ?: BrowserOptions ) {
20
+ export function InitSentryForEmber ( _runtimeConfig ?: BrowserOptions ) : void {
17
21
const environmentConfig = getOwnConfig < OwnConfig > ( ) . sentryConfig ;
18
22
19
23
assert ( 'Missing configuration.' , environmentConfig ) ;
20
24
assert ( 'Missing configuration for Sentry.' , environmentConfig . sentry || _runtimeConfig ) ;
21
25
22
26
if ( ! environmentConfig . sentry ) {
23
27
// If environment config is not specified but the above assertion passes, use runtime config.
24
- environmentConfig . sentry = { ..._runtimeConfig } as any ;
28
+ environmentConfig . sentry = { ..._runtimeConfig } ;
25
29
}
26
30
27
31
// Merge runtime config into environment config, preferring runtime.
@@ -62,12 +66,20 @@ export function InitSentryForEmber(_runtimeConfig?: BrowserOptions) {
62
66
}
63
67
}
64
68
65
- export const getActiveTransaction = ( ) => {
69
+ export const getActiveTransaction = ( ) : Transaction | undefined => {
66
70
return Sentry . getCurrentHub ( ) . getScope ( ) . getTransaction ( ) ;
67
71
} ;
68
72
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 > > => {
71
83
const startTimestamp = timestampInSeconds ( ) ;
72
84
const result = await fn ( ...args ) ;
73
85
@@ -79,40 +91,38 @@ export const instrumentRoutePerformance = (BaseRoute: any) => {
79
91
return result ;
80
92
} ;
81
93
94
+ const routeName = BaseRoute . name ;
95
+
82
96
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 > {
85
100
return instrumentFunction (
86
101
'ui.ember.route.before_model' ,
87
- ( < any > this ) . fullRouteName ,
102
+ this . fullRouteName ,
88
103
super . beforeModel . bind ( this ) ,
89
104
args ,
90
105
) ;
91
106
}
92
107
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 ) ;
95
110
}
96
111
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 ) ;
104
114
}
105
115
106
- async setupController ( ...args : any [ ] ) {
116
+ public setupController ( ...args : unknown [ ] ) : void | Promise < unknown > {
107
117
return instrumentFunction (
108
118
'ui.ember.route.setup_controller' ,
109
- ( < any > this ) . fullRouteName ,
119
+ this . fullRouteName ,
110
120
super . setupController . bind ( this ) ,
111
121
args ,
112
122
) ;
113
123
}
114
124
} ,
115
- } [ BaseRoute . name ] ;
125
+ } [ routeName ] as T ;
116
126
} ;
117
127
118
128
export * from '@sentry/browser' ;
0 commit comments