|
1 | 1 | import type { Integration, IntegrationClass } from '@sentry/types'; |
2 | 2 | import { dynamicRequire } from '@sentry/utils'; |
3 | 3 |
|
4 | | -export const lazyLoadedNodePerformanceMonitoringIntegrations: (() => Integration)[] = [ |
| 4 | +export interface LazyLoadedIntegration<T = object> extends Integration { |
| 5 | + /** |
| 6 | + * Loads the integration's dependency and caches it so it doesn't have to be loaded again. |
| 7 | + * |
| 8 | + * If this returns undefined, the dependency could not be loaded. |
| 9 | + */ |
| 10 | + loadDependency(): T | undefined; |
| 11 | +} |
| 12 | + |
| 13 | +export const lazyLoadedNodePerformanceMonitoringIntegrations: (() => LazyLoadedIntegration)[] = [ |
5 | 14 | () => { |
6 | 15 | const integration = dynamicRequire(module, './apollo') as { |
7 | | - Apollo: IntegrationClass<Integration>; |
| 16 | + Apollo: IntegrationClass<LazyLoadedIntegration>; |
8 | 17 | }; |
9 | 18 | return new integration.Apollo(); |
10 | 19 | }, |
11 | 20 | () => { |
12 | 21 | const integration = dynamicRequire(module, './apollo') as { |
13 | | - Apollo: IntegrationClass<Integration>; |
| 22 | + Apollo: IntegrationClass<LazyLoadedIntegration>; |
14 | 23 | }; |
15 | 24 | return new integration.Apollo({ useNestjs: true }); |
16 | 25 | }, |
17 | 26 | () => { |
18 | 27 | const integration = dynamicRequire(module, './graphql') as { |
19 | | - GraphQL: IntegrationClass<Integration>; |
| 28 | + GraphQL: IntegrationClass<LazyLoadedIntegration>; |
20 | 29 | }; |
21 | 30 | return new integration.GraphQL(); |
22 | 31 | }, |
23 | 32 | () => { |
24 | 33 | const integration = dynamicRequire(module, './mongo') as { |
25 | | - Mongo: IntegrationClass<Integration>; |
| 34 | + Mongo: IntegrationClass<LazyLoadedIntegration>; |
26 | 35 | }; |
27 | 36 | return new integration.Mongo(); |
28 | 37 | }, |
29 | 38 | () => { |
30 | 39 | const integration = dynamicRequire(module, './mongo') as { |
31 | | - Mongo: IntegrationClass<Integration>; |
| 40 | + Mongo: IntegrationClass<LazyLoadedIntegration>; |
32 | 41 | }; |
33 | 42 | return new integration.Mongo({ mongoose: true }); |
34 | 43 | }, |
35 | 44 | () => { |
36 | 45 | const integration = dynamicRequire(module, './mysql') as { |
37 | | - Mysql: IntegrationClass<Integration>; |
| 46 | + Mysql: IntegrationClass<LazyLoadedIntegration>; |
38 | 47 | }; |
39 | 48 | return new integration.Mysql(); |
40 | 49 | }, |
41 | 50 | () => { |
42 | 51 | const integration = dynamicRequire(module, './postgres') as { |
43 | | - Postgres: IntegrationClass<Integration>; |
| 52 | + Postgres: IntegrationClass<LazyLoadedIntegration>; |
44 | 53 | }; |
45 | 54 | return new integration.Postgres(); |
46 | 55 | }, |
|
0 commit comments