Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import { apm, Transaction } from '@elastic/apm-rum';
import { BehaviorSubject, filter, firstValueFrom, ReplaySubject } from 'rxjs';
import { takeWhile, tap, toArray } from 'rxjs';
import type { Plugin, CoreSetup, CoreStart, TelemetryCounter, Event } from '@kbn/core/server';
Expand Down Expand Up @@ -45,13 +46,21 @@ export class AnalyticsPluginA implements Plugin {
description: 'The lifecycle step in which the plugin is',
},
},
traceId: {
type: 'keyword',
_meta: {
description: 'The trace ID of the APM transaction',
optional: true,
},
},
},
});

// Report an event before the shipper is registered
reportEvent('test-plugin-lifecycle', {
plugin: 'analyticsPluginA',
step: 'setup',
traceId: this.getTransactionTraceId(),
});
let found = false;
window.__analyticsPluginA__ = {
Expand Down Expand Up @@ -96,9 +105,14 @@ export class AnalyticsPluginA implements Plugin {
analytics.reportEvent('test-plugin-lifecycle', {
plugin: 'analyticsPluginA',
step: 'start',
traceId: this.getTransactionTraceId(),
});
}
public stop() {}

private getTransactionTraceId(): string | undefined {
return (apm.getCurrentTransaction() as Transaction & { traceId: string })?.traceId;
}
}

function isTestPluginLifecycleReportEventAction({ action, meta }: Action): boolean {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* License v3.0 only", or the "Server Side Public License, v 1".
*/

import apm from 'elastic-apm-node';
import { BehaviorSubject, filter, firstValueFrom, ReplaySubject } from 'rxjs';
import { takeWhile, tap, toArray } from 'rxjs';
import { schema } from '@kbn/config-schema';
Expand Down Expand Up @@ -42,13 +43,21 @@ export class AnalyticsPluginAPlugin implements Plugin {
description: 'The lifecycle step in which the plugin is',
},
},
traceId: {
type: 'keyword',
_meta: {
description: 'The trace ID of the APM transaction',
optional: true,
},
},
},
});

// Report an event before the shipper is registered
reportEvent('test-plugin-lifecycle', {
plugin: 'analyticsPluginA',
step: 'setup',
traceId: apm.currentTraceIds?.['trace.id'],
});

const actions$ = new ReplaySubject<Action>();
Expand Down Expand Up @@ -137,6 +146,7 @@ export class AnalyticsPluginAPlugin implements Plugin {
analytics.reportEvent('test-plugin-lifecycle', {
plugin: 'analyticsPluginA',
step: 'start',
traceId: apm.currentTraceIds?.['trace.id'],
});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,19 +148,20 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {

// This helps us to also test the helpers
const events = await ebtUIHelper.getEvents(2, { eventTypes: ['test-plugin-lifecycle'] });
events.forEach(({ trace }) => expect(trace).to.have.property('id'));
expect(events.map(({ trace, ...rest }) => rest)).to.eql([
expect(events).to.eql([
{
timestamp: reportTestPluginLifecycleEventsAction!.meta[setupEvent].timestamp,
event_type: 'test-plugin-lifecycle',
context: initialContext,
properties: { plugin: 'analyticsPluginA', step: 'setup' },
properties: { plugin: 'analyticsPluginA', step: 'setup', traceId: events[0].trace?.id },
trace: { id: events[0].properties.traceId }, // Cross-checking with the properties.traceId to validate that the event reporter (plugin) and the client see the same transaction.
},
{
timestamp: reportTestPluginLifecycleEventsAction!.meta[startEvent].timestamp,
event_type: 'test-plugin-lifecycle',
context: reportEventContext,
properties: { plugin: 'analyticsPluginA', step: 'start' },
properties: { plugin: 'analyticsPluginA', step: 'start', traceId: events[1].trace?.id },
trace: { id: events[1].properties.traceId }, // Cross-checking with the properties.traceId to validate that the event reporter (plugin) and the client see the same transaction.
},
]);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,15 @@ export default function ({ getService }: FtrProviderContext) {
timestamp: reportTestPluginLifecycleEventsAction!.meta[setupEvent].timestamp,
event_type: 'test-plugin-lifecycle',
context: initialContext,
properties: { plugin: 'analyticsPluginA', step: 'setup' },
properties: { plugin: 'analyticsPluginA', step: 'setup', traceId: events[0].trace?.id },
trace: { id: events[0].properties.traceId }, // Cross-checking with the properties.traceId to validate that the event reporter (plugin) and the client see the same transaction.
},
{
timestamp: reportTestPluginLifecycleEventsAction!.meta[startEvent].timestamp,
event_type: 'test-plugin-lifecycle',
context: reportEventContext,
properties: { plugin: 'analyticsPluginA', step: 'start' },
properties: { plugin: 'analyticsPluginA', step: 'start', traceId: events[1].trace?.id },
trace: { id: events[1].properties.traceId }, // Cross-checking with the properties.traceId to validate that the event reporter (plugin) and the client see the same transaction.
},
]);
});
Expand Down