|
1 | | -import type { Integration, IntegrationClass } from '@sentry/types'; |
2 | | -import { dynamicRequire } from '@sentry/utils'; |
| 1 | +import type { Integration } from '@sentry/types'; |
3 | 2 |
|
4 | | -import type { Express } from './express'; |
5 | | -import type { Fastify } from './fastify'; |
6 | | -import type { GraphQL } from './graphql'; |
7 | | -import type { Mongo } from './mongo'; |
8 | | -import type { Mongoose } from './mongoose'; |
9 | | -import type { Mysql } from './mysql'; |
10 | | -import type { Mysql2 } from './mysql2'; |
11 | | -import type { Nest } from './nest'; |
12 | | -import type { Postgres } from './postgres'; |
13 | | -import type { Prisma } from './prisma'; |
| 3 | +import { Express } from './express'; |
| 4 | +import { Fastify } from './fastify'; |
| 5 | +import { GraphQL } from './graphql'; |
| 6 | +import { Mongo } from './mongo'; |
| 7 | +import { Mongoose } from './mongoose'; |
| 8 | +import { Mysql } from './mysql'; |
| 9 | +import { Mysql2 } from './mysql2'; |
| 10 | +import { Nest } from './nest'; |
| 11 | +import type { NodePerformanceIntegration } from './NodePerformanceIntegration'; |
| 12 | +import { Postgres } from './postgres'; |
| 13 | +import { Prisma } from './prisma'; |
14 | 14 |
|
15 | | -const INTEGRATIONS = [ |
| 15 | +const INTEGRATIONS: (() => NodePerformanceIntegration<unknown>)[] = [ |
16 | 16 | () => { |
17 | | - const integration = dynamicRequire(module, './express') as { |
18 | | - Express: IntegrationClass<Express>; |
19 | | - }; |
20 | | - return new integration.Express(); |
| 17 | + return new Express(); |
21 | 18 | }, |
22 | 19 | () => { |
23 | | - const integration = dynamicRequire(module, './fastify') as { |
24 | | - Fastify: IntegrationClass<Fastify>; |
25 | | - }; |
26 | | - return new integration.Fastify(); |
| 20 | + return new Fastify(); |
27 | 21 | }, |
28 | 22 | () => { |
29 | | - const integration = dynamicRequire(module, './graphql') as { |
30 | | - GraphQL: IntegrationClass<GraphQL>; |
31 | | - }; |
32 | | - return new integration.GraphQL(); |
| 23 | + return new GraphQL(); |
33 | 24 | }, |
34 | 25 | () => { |
35 | | - const integration = dynamicRequire(module, './mongo') as { |
36 | | - Mongo: IntegrationClass<Mongo>; |
37 | | - }; |
38 | | - return new integration.Mongo(); |
| 26 | + return new Mongo(); |
39 | 27 | }, |
40 | 28 | () => { |
41 | | - const integration = dynamicRequire(module, './mongoose') as { |
42 | | - Mongoose: IntegrationClass<Mongoose>; |
43 | | - }; |
44 | | - return new integration.Mongoose(); |
| 29 | + return new Mongoose(); |
45 | 30 | }, |
46 | 31 | () => { |
47 | | - const integration = dynamicRequire(module, './mysql') as { |
48 | | - Mysql: IntegrationClass<Mysql>; |
49 | | - }; |
50 | | - return new integration.Mysql(); |
| 32 | + return new Mysql(); |
51 | 33 | }, |
52 | 34 | () => { |
53 | | - const integration = dynamicRequire(module, './mysql2') as { |
54 | | - Mysql2: IntegrationClass<Mysql2>; |
55 | | - }; |
56 | | - return new integration.Mysql2(); |
| 35 | + return new Mysql2(); |
57 | 36 | }, |
58 | 37 | () => { |
59 | | - const integration = dynamicRequire(module, './postgres') as { |
60 | | - Postgres: IntegrationClass<Postgres>; |
61 | | - }; |
62 | | - return new integration.Postgres(); |
| 38 | + return new Postgres(); |
63 | 39 | }, |
64 | 40 | () => { |
65 | | - const integration = dynamicRequire(module, './prisma') as { |
66 | | - Prisma: IntegrationClass<Prisma>; |
67 | | - }; |
68 | | - return new integration.Prisma(); |
| 41 | + return new Prisma(); |
69 | 42 | }, |
70 | 43 | () => { |
71 | | - const integration = dynamicRequire(module, './nest') as { |
72 | | - Nest: IntegrationClass<Nest>; |
73 | | - }; |
74 | | - return new integration.Nest(); |
| 44 | + return new Nest(); |
75 | 45 | }, |
76 | 46 | ]; |
77 | 47 |
|
78 | | -/** TODO */ |
| 48 | +/** |
| 49 | + * Get auto-dsicovered performance integrations. |
| 50 | + * Note that due to the way OpenTelemetry instrumentation works, this will generally still return Integrations |
| 51 | + * for stuff that may not be installed. This is because Otel only instruments when the module is imported/required, |
| 52 | + * so if the package is not required at all it will not be patched, and thus not instrumented. |
| 53 | + * But the _Sentry_ Integration will still be added. |
| 54 | + * This _may_ be a bit confusing because it shows all integrations as being installed in the debug logs, but this is |
| 55 | + * technically not wrong because we install it (it just doesn't do anything). |
| 56 | + */ |
79 | 57 | export function getAutoPerformanceIntegrations(): Integration[] { |
80 | 58 | const loadedIntegrations = INTEGRATIONS.map(tryLoad => { |
81 | 59 | try { |
82 | | - return tryLoad(); |
| 60 | + const integration = tryLoad(); |
| 61 | + const isLoaded = integration.loadInstrumentations(); |
| 62 | + return isLoaded ? integration : false; |
83 | 63 | } catch (_) { |
84 | | - return undefined; |
| 64 | + return false; |
85 | 65 | } |
86 | 66 | }).filter(integration => !!integration) as Integration[]; |
87 | 67 |
|
|
0 commit comments