diff --git a/src/platform/test/analytics/plugins/analytics_plugin_a/public/plugin.ts b/src/platform/test/analytics/plugins/analytics_plugin_a/public/plugin.ts index bc5490b891b14..96a1ebe03acb6 100644 --- a/src/platform/test/analytics/plugins/analytics_plugin_a/public/plugin.ts +++ b/src/platform/test/analytics/plugins/analytics_plugin_a/public/plugin.ts @@ -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'; @@ -45,6 +46,13 @@ 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, + }, + }, }, }); @@ -52,6 +60,7 @@ export class AnalyticsPluginA implements Plugin { reportEvent('test-plugin-lifecycle', { plugin: 'analyticsPluginA', step: 'setup', + traceId: this.getTransactionTraceId(), }); let found = false; window.__analyticsPluginA__ = { @@ -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 { diff --git a/src/platform/test/analytics/plugins/analytics_plugin_a/server/plugin.ts b/src/platform/test/analytics/plugins/analytics_plugin_a/server/plugin.ts index 8309164882ff5..9812c651a5fb5 100644 --- a/src/platform/test/analytics/plugins/analytics_plugin_a/server/plugin.ts +++ b/src/platform/test/analytics/plugins/analytics_plugin_a/server/plugin.ts @@ -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'; @@ -42,6 +43,13 @@ 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, + }, + }, }, }); @@ -49,6 +57,7 @@ export class AnalyticsPluginAPlugin implements Plugin { reportEvent('test-plugin-lifecycle', { plugin: 'analyticsPluginA', step: 'setup', + traceId: apm.currentTraceIds?.['trace.id'], }); const actions$ = new ReplaySubject(); @@ -137,6 +146,7 @@ export class AnalyticsPluginAPlugin implements Plugin { analytics.reportEvent('test-plugin-lifecycle', { plugin: 'analyticsPluginA', step: 'start', + traceId: apm.currentTraceIds?.['trace.id'], }); } diff --git a/src/platform/test/analytics/tests/analytics_from_the_browser.ts b/src/platform/test/analytics/tests/analytics_from_the_browser.ts index bb1927aaeb935..74ac77a45a13b 100644 --- a/src/platform/test/analytics/tests/analytics_from_the_browser.ts +++ b/src/platform/test/analytics/tests/analytics_from_the_browser.ts @@ -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. }, ]); }); diff --git a/src/platform/test/analytics/tests/analytics_from_the_server.ts b/src/platform/test/analytics/tests/analytics_from_the_server.ts index bb1df0735107e..d157ea7554af2 100644 --- a/src/platform/test/analytics/tests/analytics_from_the_server.ts +++ b/src/platform/test/analytics/tests/analytics_from_the_server.ts @@ -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. }, ]); });