|
27 | 27 |
|
28 | 28 | import { i18n } from '@kbn/i18n'; |
29 | 29 | import { CoreSystem } from './core_system'; |
| 30 | +import { ApmSystem } from './apm_system'; |
30 | 31 |
|
31 | 32 | /** @internal */ |
32 | | -export function __kbnBootstrap__() { |
| 33 | +export async function __kbnBootstrap__() { |
33 | 34 | const injectedMetadata = JSON.parse( |
34 | 35 | document.querySelector('kbn-injected-metadata')!.getAttribute('data')! |
35 | 36 | ); |
36 | 37 |
|
37 | | - /** |
38 | | - * `apmConfig` would be populated with relavant APM RUM agent |
39 | | - * configuration if server is started with `ELASTIC_APM_ACTIVE=true` |
40 | | - */ |
41 | | - const apmConfig = injectedMetadata.vars.apmConfig; |
42 | | - const APM_ENABLED = process.env.IS_KIBANA_DISTRIBUTABLE !== 'true' && apmConfig != null; |
| 38 | + const apmSystem = new ApmSystem(injectedMetadata.vars.apmConfig); |
| 39 | + await apmSystem.setup(); |
43 | 40 |
|
44 | | - if (APM_ENABLED) { |
45 | | - // eslint-disable-next-line @typescript-eslint/no-var-requires |
46 | | - const { init, apm } = require('@elastic/apm-rum'); |
47 | | - if (apmConfig.globalLabels) { |
48 | | - apm.addLabels(apmConfig.globalLabels); |
49 | | - } |
50 | | - init(apmConfig); |
| 41 | + let i18nError: Error | undefined; |
| 42 | + try { |
| 43 | + await i18n.load(injectedMetadata.i18n.translationsUrl); |
| 44 | + } catch (error) { |
| 45 | + i18nError = error; |
51 | 46 | } |
52 | 47 |
|
53 | | - i18n |
54 | | - .load(injectedMetadata.i18n.translationsUrl) |
55 | | - .catch((e) => e) |
56 | | - .then(async (i18nError) => { |
57 | | - const coreSystem = new CoreSystem({ |
58 | | - injectedMetadata, |
59 | | - rootDomElement: document.body, |
60 | | - browserSupportsCsp: !(window as any).__kbnCspNotEnforced__, |
61 | | - }); |
| 48 | + const coreSystem = new CoreSystem({ |
| 49 | + injectedMetadata, |
| 50 | + rootDomElement: document.body, |
| 51 | + browserSupportsCsp: !(window as any).__kbnCspNotEnforced__, |
| 52 | + }); |
62 | 53 |
|
63 | | - const setup = await coreSystem.setup(); |
64 | | - if (i18nError && setup) { |
65 | | - setup.fatalErrors.add(i18nError); |
66 | | - } |
67 | | - |
68 | | - const start = await coreSystem.start(); |
| 54 | + const setup = await coreSystem.setup(); |
| 55 | + if (i18nError && setup) { |
| 56 | + setup.fatalErrors.add(i18nError); |
| 57 | + } |
69 | 58 |
|
70 | | - if (APM_ENABLED && start) { |
71 | | - /** |
72 | | - * Register listeners for navigation changes and capture them as |
73 | | - * route-change transactions after Kibana app is bootstrapped |
74 | | - */ |
75 | | - start.application.currentAppId$.subscribe((appId) => { |
76 | | - const apmInstance = (window as any).elasticApm; |
77 | | - if (appId && apmInstance && typeof apmInstance.startTransaction === 'function') { |
78 | | - apmInstance.startTransaction(`/app/${appId}`, 'route-change', { |
79 | | - managed: true, |
80 | | - canReuse: true, |
81 | | - }); |
82 | | - } |
83 | | - }); |
84 | | - } |
85 | | - }); |
| 59 | + const start = await coreSystem.start(); |
| 60 | + await apmSystem.start(start); |
86 | 61 | } |
0 commit comments