(BaseRoute: T)
| 52 | type RouteConstructor = new (...args: ConstructorParameters<typeof Route>) => Route; |
| 53 | |
| 54 | export const instrumentRoutePerformance = <T extends RouteConstructor>(BaseRoute: T): T => { |
| 55 | // eslint-disable-next-line @typescript-eslint/no-explicit-any |
| 56 | const instrumentFunction = async <X extends (...args: unknown[]) => any>( |
| 57 | op: string, |
| 58 | name: string, |
| 59 | fn: X, |
| 60 | args: Parameters<X>, |
| 61 | source: TransactionSource, |
| 62 | ): Promise<ReturnType<X>> => { |
| 63 | return startSpan( |
| 64 | { |
| 65 | attributes: { |
| 66 | [SEMANTIC_ATTRIBUTE_SENTRY_SOURCE]: source, |
| 67 | [SEMANTIC_ATTRIBUTE_SENTRY_ORIGIN]: 'auto.ui.ember', |
| 68 | }, |
| 69 | op, |
| 70 | name, |
| 71 | onlyIfParent: true, |
| 72 | }, |
| 73 | () => { |
| 74 | return fn(...args); |
| 75 | }, |
| 76 | ); |
| 77 | }; |
| 78 | |
| 79 | const routeName = BaseRoute.name; |
| 80 | |
| 81 | return { |
| 82 | // @ts-expect-error TS2545 We do not need to redefine a constructor here |
| 83 | [routeName]: class extends BaseRoute { |
| 84 | public beforeModel(...args: unknown[]): void | Promise<unknown> { |
| 85 | return instrumentFunction( |
| 86 | 'ui.ember.route.before_model', |
| 87 | this.fullRouteName, |
| 88 | super.beforeModel.bind(this), |
| 89 | args, |
| 90 | 'custom', |
| 91 | ); |
| 92 | } |
| 93 | |
| 94 | public async model(...args: unknown[]): Promise<unknown> { |
| 95 | return instrumentFunction('ui.ember.route.model', this.fullRouteName, super.model.bind(this), args, 'custom'); |
| 96 | } |
| 97 | |
| 98 | public afterModel(...args: unknown[]): void | Promise<unknown> { |
| 99 | return instrumentFunction( |
| 100 | 'ui.ember.route.after_model', |
| 101 | this.fullRouteName, |
| 102 | super.afterModel.bind(this), |
| 103 | args, |
| 104 | 'custom', |
| 105 | ); |
| 106 | } |
| 107 | |
| 108 | public setupController(...args: unknown[]): void | Promise<unknown> { |
| 109 | return instrumentFunction( |
| 110 | 'ui.ember.route.setup_controller', |
| 111 | this.fullRouteName, |
no outgoing calls
no test coverage detected