1 | import { addGlobalEventProcessor, getCurrentHub } from '@sentry/hub';
|
2 | import { arrayify, logger } from '@sentry/utils';
|
3 |
|
4 | var installedIntegrations = [];
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | function filterDuplicates(integrations) {
|
15 | var integrationsByName = {};
|
16 |
|
17 | integrations.forEach(currentInstance => {
|
18 | const { name } = currentInstance;
|
19 |
|
20 | var existingInstance = integrationsByName[name];
|
21 |
|
22 |
|
23 |
|
24 | if (existingInstance && !existingInstance.isDefaultInstance && currentInstance.isDefaultInstance) {
|
25 | return;
|
26 | }
|
27 |
|
28 | integrationsByName[name] = currentInstance;
|
29 | });
|
30 |
|
31 | return Object.values(integrationsByName);
|
32 | }
|
33 |
|
34 |
|
35 | function getIntegrationsToSetup(options) {
|
36 | var defaultIntegrations = options.defaultIntegrations || [];
|
37 | var userIntegrations = options.integrations;
|
38 |
|
39 |
|
40 | defaultIntegrations.forEach(integration => {
|
41 | integration.isDefaultInstance = true;
|
42 | });
|
43 |
|
44 | let integrations;
|
45 |
|
46 | if (Array.isArray(userIntegrations)) {
|
47 | integrations = [...defaultIntegrations, ...userIntegrations];
|
48 | } else if (typeof userIntegrations === 'function') {
|
49 | integrations = arrayify(userIntegrations(defaultIntegrations));
|
50 | } else {
|
51 | integrations = defaultIntegrations;
|
52 | }
|
53 |
|
54 | var finalIntegrations = filterDuplicates(integrations);
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 | var debugIndex = finalIntegrations.findIndex(integration => integration.name === 'Debug');
|
61 | if (debugIndex !== -1) {
|
62 | const [debugInstance] = finalIntegrations.splice(debugIndex, 1);
|
63 | finalIntegrations.push(debugInstance);
|
64 | }
|
65 |
|
66 | return finalIntegrations;
|
67 | }
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 | function setupIntegrations(integrations) {
|
76 | var integrationIndex = {};
|
77 |
|
78 | integrations.forEach(integration => {
|
79 | integrationIndex[integration.name] = integration;
|
80 |
|
81 | if (installedIntegrations.indexOf(integration.name) === -1) {
|
82 | integration.setupOnce(addGlobalEventProcessor, getCurrentHub);
|
83 | installedIntegrations.push(integration.name);
|
84 | (typeof __SENTRY_DEBUG__ === 'undefined' || __SENTRY_DEBUG__) && logger.log(`Integration installed: ${integration.name}`);
|
85 | }
|
86 | });
|
87 |
|
88 | return integrationIndex;
|
89 | }
|
90 |
|
91 | export { getIntegrationsToSetup, installedIntegrations, setupIntegrations };
|
92 |
|