-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
95 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
/** | ||
* This is the entry point used to boot the frontend when serving a application | ||
* that lives in the Kibana Platform. | ||
* | ||
* Any changes to this file should be kept in sync with | ||
* src/legacy/ui/ui_bundles/app_entry_template.js | ||
*/ | ||
import type { InternalApplicationStart } from './application'; | ||
|
||
interface ApmConfig { | ||
// AgentConfigOptions is not exported from @elastic/apm-rum | ||
globalLabels?: Record<string, string>; | ||
} | ||
|
||
interface StartDeps { | ||
application: InternalApplicationStart; | ||
} | ||
|
||
export class ApmSystem { | ||
private readonly enabled: boolean; | ||
/** | ||
* `apmConfig` would be populated with relevant APM RUM agent | ||
* configuration if server is started with `ELASTIC_APM_ACTIVE=true` | ||
*/ | ||
constructor(private readonly apmConfig?: ApmConfig) { | ||
this.enabled = process.env.IS_KIBANA_DISTRIBUTABLE !== 'true' && apmConfig != null; | ||
} | ||
|
||
async setup() { | ||
if (!this.enabled) return; | ||
const { init, apm } = await import('@elastic/apm-rum'); | ||
const { globalLabels, ...apmConfig } = this.apmConfig!; | ||
if (globalLabels) { | ||
apm.addLabels(globalLabels); | ||
} | ||
|
||
init(apmConfig); | ||
} | ||
|
||
async start(start?: StartDeps) { | ||
if (!this.enabled || !start) return; | ||
/** | ||
* Register listeners for navigation changes and capture them as | ||
* route-change transactions after Kibana app is bootstrapped | ||
*/ | ||
start.application.currentAppId$.subscribe((appId) => { | ||
const apmInstance = (window as any).elasticApm; | ||
if (appId && apmInstance && typeof apmInstance.startTransaction === 'function') { | ||
apmInstance.startTransaction(`/app/${appId}`, 'route-change', { | ||
managed: true, | ||
canReuse: true, | ||
}); | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters