mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Keep page load transaction open (#115410)
* keep page load transaction open * cleanup * code review Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
c0b852ff13
commit
ab9f8d1b4b
1 changed files with 19 additions and 0 deletions
|
@ -30,6 +30,7 @@ interface StartDeps {
|
|||
|
||||
export class ApmSystem {
|
||||
private readonly enabled: boolean;
|
||||
private pageLoadTransaction?: Transaction;
|
||||
/**
|
||||
* `apmConfig` would be populated with relevant APM RUM agent
|
||||
* configuration if server is started with elastic.apm.* config.
|
||||
|
@ -49,10 +50,23 @@ export class ApmSystem {
|
|||
this.addHttpRequestNormalization(apm);
|
||||
|
||||
init(apmConfig);
|
||||
this.pageLoadTransaction = apm.getCurrentTransaction();
|
||||
|
||||
// Keep the page load transaction open until all resources finished loading
|
||||
if (this.pageLoadTransaction && this.pageLoadTransaction.type === 'page-load') {
|
||||
// @ts-expect-error 2339
|
||||
this.pageLoadTransaction.block(true);
|
||||
this.pageLoadTransaction.mark('apm-setup');
|
||||
}
|
||||
}
|
||||
|
||||
async start(start?: StartDeps) {
|
||||
if (!this.enabled || !start) return;
|
||||
|
||||
if (this.pageLoadTransaction && this.pageLoadTransaction.type === 'page-load') {
|
||||
this.pageLoadTransaction.mark('apm-start');
|
||||
}
|
||||
|
||||
/**
|
||||
* Register listeners for navigation changes and capture them as
|
||||
* route-change transactions after Kibana app is bootstrapped
|
||||
|
@ -60,6 +74,11 @@ export class ApmSystem {
|
|||
start.application.currentAppId$.subscribe((appId) => {
|
||||
const apmInstance = (window as any).elasticApm;
|
||||
if (appId && apmInstance && typeof apmInstance.startTransaction === 'function') {
|
||||
// Close the page load transaction
|
||||
if (this.pageLoadTransaction && this.pageLoadTransaction.type === 'page-load') {
|
||||
this.pageLoadTransaction.end();
|
||||
this.pageLoadTransaction = undefined;
|
||||
}
|
||||
apmInstance.startTransaction(`/app/${appId}`, 'route-change', {
|
||||
managed: true,
|
||||
canReuse: true,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue