From c3dbf48d9af72681f5b09d080e8e627d6d2dc92c Mon Sep 17 00:00:00 2001 From: Thomas Lebeau Date: Thu, 9 Jan 2025 11:58:10 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=E2=9C=A8=20Collect=20long=20animation=20fr?= =?UTF-8?q?ames=20as=20long=20task=20events?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/src/tools/experimentalFeatures.ts | 1 - packages/rum-core/src/boot/startRum.spec.ts | 6 +- packages/rum-core/src/boot/startRum.ts | 13 +-- .../src/browser/performanceObservable.ts | 12 --- .../longTask/longTaskCollection.spec.ts | 84 ------------------- .../src/domain/longTask/longTaskCollection.ts | 46 ---------- packages/rum-core/test/fixtures.ts | 12 --- 7 files changed, 6 insertions(+), 168 deletions(-) delete mode 100644 packages/rum-core/src/domain/longTask/longTaskCollection.spec.ts delete mode 100644 packages/rum-core/src/domain/longTask/longTaskCollection.ts diff --git a/packages/core/src/tools/experimentalFeatures.ts b/packages/core/src/tools/experimentalFeatures.ts index c822e2591f..2fd839cba3 100644 --- a/packages/core/src/tools/experimentalFeatures.ts +++ b/packages/core/src/tools/experimentalFeatures.ts @@ -16,7 +16,6 @@ import { objectHasValue } from './utils/objectUtils' export enum ExperimentalFeature { WRITABLE_RESOURCE_GRAPHQL = 'writable_resource_graphql', REMOTE_CONFIGURATION = 'remote_configuration', - LONG_ANIMATION_FRAME = 'long_animation_frame', ACTION_NAME_MASKING = 'action_name_masking', CONSISTENT_TRACE_SAMPLING = 'consistent_trace_sampling', DELAY_VIEWPORT_COLLECTION = 'delay_viewport_collection', diff --git a/packages/rum-core/src/boot/startRum.spec.ts b/packages/rum-core/src/boot/startRum.spec.ts index ad300a6f8b..f9e6fd9567 100644 --- a/packages/rum-core/src/boot/startRum.spec.ts +++ b/packages/rum-core/src/boot/startRum.spec.ts @@ -38,7 +38,7 @@ import { SESSION_KEEP_ALIVE_INTERVAL, THROTTLE_VIEW_UPDATE_PERIOD } from '../dom import { startViewCollection } from '../domain/view/viewCollection' import type { RumEvent, RumViewEvent } from '../rumEvent.types' import type { LocationChange } from '../browser/locationChangeObservable' -import { startLongTaskCollection } from '../domain/longTask/longTaskCollection' +import { startLongAnimationFrameCollection } from '../domain/longAnimationFrame/longAnimationFrameCollection' import type { RumSessionManager } from '..' import type { RumConfiguration } from '../domain/configuration' import { RumEventType } from '../rawRumEvent.types' @@ -94,7 +94,7 @@ function startRumStub( noopRecorderApi ) - startLongTaskCollection(lifeCycle, configuration) + startLongAnimationFrameCollection(lifeCycle, configuration) return { stop: () => { rumEventCollectionStop() @@ -279,7 +279,7 @@ describe('rum events url', () => { changeLocation('http://foo.com/?bar=qux') notifyPerformanceEntries([ - createPerformanceEntry(RumPerformanceEntryType.LONG_TASK, { + createPerformanceEntry(RumPerformanceEntryType.LONG_ANIMATION_FRAME, { startTime: (relativeNow() - 5) as RelativeTime, }), ]) diff --git a/packages/rum-core/src/boot/startRum.ts b/packages/rum-core/src/boot/startRum.ts index c04645e49e..e9698bbd3f 100644 --- a/packages/rum-core/src/boot/startRum.ts +++ b/packages/rum-core/src/boot/startRum.ts @@ -17,8 +17,6 @@ import { addTelemetryDebug, CustomerDataType, drainPreStartTelemetry, - isExperimentalFeatureEnabled, - ExperimentalFeature, } from '@datadog/browser-core' import { createDOMMutationObservable } from '../browser/domMutationObservable' import { createWindowOpenObservable } from '../browser/windowOpenObservable' @@ -29,7 +27,6 @@ import { startViewHistory } from '../domain/contexts/viewHistory' import { startRequestCollection } from '../domain/requestCollection' import { startActionCollection } from '../domain/action/actionCollection' import { startErrorCollection } from '../domain/error/errorCollection' -import { startLongTaskCollection } from '../domain/longTask/longTaskCollection' import { startResourceCollection } from '../domain/resource/resourceCollection' import { startViewCollection } from '../domain/view/viewCollection' import type { RumSessionManager } from '../domain/rumSessionManager' @@ -177,13 +174,9 @@ export function startRum( const { stop: stopResourceCollection } = startResourceCollection(lifeCycle, configuration, pageStateHistory) cleanupTasks.push(stopResourceCollection) - if (isExperimentalFeatureEnabled(ExperimentalFeature.LONG_ANIMATION_FRAME)) { - if (configuration.trackLongTasks) { - const { stop: stopLongAnimationFrameCollection } = startLongAnimationFrameCollection(lifeCycle, configuration) - cleanupTasks.push(stopLongAnimationFrameCollection) - } - } else { - startLongTaskCollection(lifeCycle, configuration) + if (configuration.trackLongTasks) { + const { stop: stopLongAnimationFrameCollection } = startLongAnimationFrameCollection(lifeCycle, configuration) + cleanupTasks.push(stopLongAnimationFrameCollection) } const { addError } = startErrorCollection(lifeCycle, configuration, pageStateHistory, featureFlagContexts) diff --git a/packages/rum-core/src/browser/performanceObservable.ts b/packages/rum-core/src/browser/performanceObservable.ts index 000710becc..4fd07060cc 100644 --- a/packages/rum-core/src/browser/performanceObservable.ts +++ b/packages/rum-core/src/browser/performanceObservable.ts @@ -23,21 +23,12 @@ export enum RumPerformanceEntryType { FIRST_INPUT = 'first-input', LARGEST_CONTENTFUL_PAINT = 'largest-contentful-paint', LAYOUT_SHIFT = 'layout-shift', - LONG_TASK = 'longtask', LONG_ANIMATION_FRAME = 'long-animation-frame', NAVIGATION = 'navigation', PAINT = 'paint', RESOURCE = 'resource', } -export interface RumPerformanceLongTaskTiming { - name: string - entryType: RumPerformanceEntryType.LONG_TASK - startTime: RelativeTime - duration: Duration - toJSON(): Omit -} - export interface RumPerformanceResourceTiming { entryType: RumPerformanceEntryType.RESOURCE initiatorType: string @@ -164,7 +155,6 @@ export interface RumPerformanceLongAnimationFrameTiming { export type RumPerformanceEntry = | RumPerformanceResourceTiming - | RumPerformanceLongTaskTiming | RumPerformanceLongAnimationFrameTiming | RumPerformancePaintTiming | RumPerformanceNavigationTiming @@ -179,7 +169,6 @@ export type EntryTypeToReturnType = { [RumPerformanceEntryType.LARGEST_CONTENTFUL_PAINT]: RumLargestContentfulPaintTiming [RumPerformanceEntryType.LAYOUT_SHIFT]: RumLayoutShiftTiming [RumPerformanceEntryType.PAINT]: RumPerformancePaintTiming - [RumPerformanceEntryType.LONG_TASK]: RumPerformanceLongTaskTiming [RumPerformanceEntryType.LONG_ANIMATION_FRAME]: RumPerformanceLongAnimationFrameTiming [RumPerformanceEntryType.NAVIGATION]: RumPerformanceNavigationTiming [RumPerformanceEntryType.RESOURCE]: RumPerformanceResourceTiming @@ -223,7 +212,6 @@ export function createPerformanceObservable( const fallbackSupportedEntryTypes = [ RumPerformanceEntryType.RESOURCE, RumPerformanceEntryType.NAVIGATION, - RumPerformanceEntryType.LONG_TASK, RumPerformanceEntryType.PAINT, ] if (fallbackSupportedEntryTypes.includes(options.type)) { diff --git a/packages/rum-core/src/domain/longTask/longTaskCollection.spec.ts b/packages/rum-core/src/domain/longTask/longTaskCollection.spec.ts deleted file mode 100644 index c438a14583..0000000000 --- a/packages/rum-core/src/domain/longTask/longTaskCollection.spec.ts +++ /dev/null @@ -1,84 +0,0 @@ -import type { RelativeTime, ServerDuration } from '@datadog/browser-core' -import { - collectAndValidateRawRumEvents, - createPerformanceEntry, - mockPerformanceObserver, - mockRumConfiguration, -} from '../../../test' -import type { RumPerformanceEntry } from '../../browser/performanceObservable' -import { RumPerformanceEntryType } from '../../browser/performanceObservable' -import type { RawRumEvent } from '../../rawRumEvent.types' -import { RumEventType, RumLongTaskEntryType } from '../../rawRumEvent.types' -import type { RawRumEventCollectedData } from '../lifeCycle' -import { LifeCycle } from '../lifeCycle' -import { startLongTaskCollection } from './longTaskCollection' - -describe('long task collection', () => { - let lifeCycle = new LifeCycle() - let rawRumEvents: Array> = [] - let notifyPerformanceEntries: (entries: RumPerformanceEntry[]) => void - - function setupLongTaskCollection(trackLongTasks = true) { - ;({ notifyPerformanceEntries } = mockPerformanceObserver()) - - lifeCycle = new LifeCycle() - startLongTaskCollection(lifeCycle, mockRumConfiguration({ trackLongTasks })) - - rawRumEvents = collectAndValidateRawRumEvents(lifeCycle) - } - - it('should only listen to long task performance entry', () => { - setupLongTaskCollection() - - notifyPerformanceEntries([ - createPerformanceEntry(RumPerformanceEntryType.NAVIGATION), - createPerformanceEntry(RumPerformanceEntryType.LONG_TASK), - createPerformanceEntry(RumPerformanceEntryType.PAINT), - ]) - - expect(rawRumEvents.length).toBe(1) - }) - - it('should collect when trackLongTasks=true', () => { - setupLongTaskCollection() - - notifyPerformanceEntries([createPerformanceEntry(RumPerformanceEntryType.LONG_TASK)]) - expect(rawRumEvents.length).toBe(1) - }) - - it('should not collect when trackLongTasks=false', () => { - setupLongTaskCollection(false) - - notifyPerformanceEntries([createPerformanceEntry(RumPerformanceEntryType.LONG_TASK)]) - - expect(rawRumEvents.length).toBe(0) - }) - - it('should create raw rum event from performance entry', () => { - setupLongTaskCollection() - notifyPerformanceEntries([createPerformanceEntry(RumPerformanceEntryType.LONG_TASK)]) - - expect(rawRumEvents[0].startTime).toBe(1234 as RelativeTime) - expect(rawRumEvents[0].rawRumEvent).toEqual({ - date: jasmine.any(Number), - long_task: { - id: jasmine.any(String), - entry_type: RumLongTaskEntryType.LONG_TASK, - duration: (100 * 1e6) as ServerDuration, - }, - type: RumEventType.LONG_TASK, - _dd: { - discarded: false, - }, - }) - expect(rawRumEvents[0].domainContext).toEqual({ - performanceEntry: { - name: 'self', - duration: 100, - entryType: 'longtask', - startTime: 1234, - toJSON: jasmine.any(Function), - }, - }) - }) -}) diff --git a/packages/rum-core/src/domain/longTask/longTaskCollection.ts b/packages/rum-core/src/domain/longTask/longTaskCollection.ts deleted file mode 100644 index 2ab4819a08..0000000000 --- a/packages/rum-core/src/domain/longTask/longTaskCollection.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { toServerDuration, relativeToClocks, generateUUID } from '@datadog/browser-core' -import type { RawRumLongTaskEvent } from '../../rawRumEvent.types' -import { RumEventType, RumLongTaskEntryType } from '../../rawRumEvent.types' -import type { LifeCycle } from '../lifeCycle' -import { LifeCycleEventType } from '../lifeCycle' -import { createPerformanceObservable, RumPerformanceEntryType } from '../../browser/performanceObservable' -import type { RumConfiguration } from '../configuration' -export function startLongTaskCollection(lifeCycle: LifeCycle, configuration: RumConfiguration) { - const performanceLongTaskSubscription = createPerformanceObservable(configuration, { - type: RumPerformanceEntryType.LONG_TASK, - buffered: true, - }).subscribe((entries) => { - for (const entry of entries) { - if (entry.entryType !== RumPerformanceEntryType.LONG_TASK) { - break - } - if (!configuration.trackLongTasks) { - break - } - const startClocks = relativeToClocks(entry.startTime) - const rawRumEvent: RawRumLongTaskEvent = { - date: startClocks.timeStamp, - long_task: { - id: generateUUID(), - entry_type: RumLongTaskEntryType.LONG_TASK, - duration: toServerDuration(entry.duration), - }, - type: RumEventType.LONG_TASK, - _dd: { - discarded: false, - }, - } - lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, { - rawRumEvent, - startTime: startClocks.relative, - domainContext: { performanceEntry: entry }, - }) - } - }) - - return { - stop() { - performanceLongTaskSubscription.unsubscribe() - }, - } -} diff --git a/packages/rum-core/test/fixtures.ts b/packages/rum-core/test/fixtures.ts index afc06c1aa9..bd3888176c 100644 --- a/packages/rum-core/test/fixtures.ts +++ b/packages/rum-core/test/fixtures.ts @@ -171,18 +171,6 @@ export function createPerformanceEntry( loadEventEnd: 567 as RelativeTime, ...overrides, } as EntryTypeToReturnType[T] - - case RumPerformanceEntryType.LONG_TASK: { - const entry = { - name: 'self', - duration: 100 as Duration, - entryType: RumPerformanceEntryType.LONG_TASK, - startTime: 1234 as RelativeTime, - ...overrides, - } as EntryTypeToReturnType[T] - - return { ...entry, toJSON: () => entry } - } case RumPerformanceEntryType.LONG_ANIMATION_FRAME: { const entry = { name: 'long-animation-frame', From e9d3e8394b9f8f71e545dda8f566b52a67bc97c4 Mon Sep 17 00:00:00 2001 From: Thomas Lebeau Date: Fri, 10 Jan 2025 11:21:50 +0100 Subject: [PATCH 2/3] =?UTF-8?q?=E2=9C=85=20ignore=20loaf=20console=20warni?= =?UTF-8?q?ngs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/e2e/lib/helpers/browser.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/e2e/lib/helpers/browser.ts b/test/e2e/lib/helpers/browser.ts index 260d098f19..952c1fe661 100644 --- a/test/e2e/lib/helpers/browser.ts +++ b/test/e2e/lib/helpers/browser.ts @@ -69,7 +69,13 @@ export async function withBrowserLogs(fn: (logs: BrowserLog[]) => void) { // https://github.com/webdriverio/webdriverio/issues/4275 if (browser.getLogs) { const logs = (await browser.getLogs('browser')) as BrowserLog[] - fn(logs) + + const filterdLogs = logs.filter( + // Ignore long-animation-frame warning (only happens on Edge) + (log) => !log.message.includes("The entry type 'long-animation-frame' does not exist or isn't supported") + ) + + fn(filterdLogs) } } From 923877d36b7b43ca112128139b18a90a9c407dcc Mon Sep 17 00:00:00 2001 From: Thomas Lebeau Date: Mon, 13 Jan 2025 09:10:26 +0100 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=91=8C=20fallback=20to=20long=20task?= =?UTF-8?q?=20when=20loAF=20is=20not=20supported?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/rum-core/src/boot/startRum.ts | 10 ++- .../src/browser/performanceObservable.ts | 12 +++ .../longTask/longTaskCollection.spec.ts | 84 +++++++++++++++++++ .../src/domain/longTask/longTaskCollection.ts | 46 ++++++++++ packages/rum-core/test/fixtures.ts | 12 +++ test/e2e/lib/helpers/browser.ts | 8 +- 6 files changed, 163 insertions(+), 9 deletions(-) create mode 100644 packages/rum-core/src/domain/longTask/longTaskCollection.spec.ts create mode 100644 packages/rum-core/src/domain/longTask/longTaskCollection.ts diff --git a/packages/rum-core/src/boot/startRum.ts b/packages/rum-core/src/boot/startRum.ts index e9698bbd3f..c374b5590b 100644 --- a/packages/rum-core/src/boot/startRum.ts +++ b/packages/rum-core/src/boot/startRum.ts @@ -48,6 +48,8 @@ import type { CustomVitalsState } from '../domain/vital/vitalCollection' import { startVitalCollection } from '../domain/vital/vitalCollection' import { startCiVisibilityContext } from '../domain/contexts/ciVisibilityContext' import { startLongAnimationFrameCollection } from '../domain/longAnimationFrame/longAnimationFrameCollection' +import { RumPerformanceEntryType } from '../browser/performanceObservable' +import { startLongTaskCollection } from '../domain/longTask/longTaskCollection' import type { RecorderApi } from './rumPublicApi' export type StartRum = typeof startRum @@ -175,8 +177,12 @@ export function startRum( cleanupTasks.push(stopResourceCollection) if (configuration.trackLongTasks) { - const { stop: stopLongAnimationFrameCollection } = startLongAnimationFrameCollection(lifeCycle, configuration) - cleanupTasks.push(stopLongAnimationFrameCollection) + if (PerformanceObserver.supportedEntryTypes?.includes(RumPerformanceEntryType.LONG_ANIMATION_FRAME)) { + const { stop: stopLongAnimationFrameCollection } = startLongAnimationFrameCollection(lifeCycle, configuration) + cleanupTasks.push(stopLongAnimationFrameCollection) + } else { + startLongTaskCollection(lifeCycle, configuration) + } } const { addError } = startErrorCollection(lifeCycle, configuration, pageStateHistory, featureFlagContexts) diff --git a/packages/rum-core/src/browser/performanceObservable.ts b/packages/rum-core/src/browser/performanceObservable.ts index 4fd07060cc..000710becc 100644 --- a/packages/rum-core/src/browser/performanceObservable.ts +++ b/packages/rum-core/src/browser/performanceObservable.ts @@ -23,12 +23,21 @@ export enum RumPerformanceEntryType { FIRST_INPUT = 'first-input', LARGEST_CONTENTFUL_PAINT = 'largest-contentful-paint', LAYOUT_SHIFT = 'layout-shift', + LONG_TASK = 'longtask', LONG_ANIMATION_FRAME = 'long-animation-frame', NAVIGATION = 'navigation', PAINT = 'paint', RESOURCE = 'resource', } +export interface RumPerformanceLongTaskTiming { + name: string + entryType: RumPerformanceEntryType.LONG_TASK + startTime: RelativeTime + duration: Duration + toJSON(): Omit +} + export interface RumPerformanceResourceTiming { entryType: RumPerformanceEntryType.RESOURCE initiatorType: string @@ -155,6 +164,7 @@ export interface RumPerformanceLongAnimationFrameTiming { export type RumPerformanceEntry = | RumPerformanceResourceTiming + | RumPerformanceLongTaskTiming | RumPerformanceLongAnimationFrameTiming | RumPerformancePaintTiming | RumPerformanceNavigationTiming @@ -169,6 +179,7 @@ export type EntryTypeToReturnType = { [RumPerformanceEntryType.LARGEST_CONTENTFUL_PAINT]: RumLargestContentfulPaintTiming [RumPerformanceEntryType.LAYOUT_SHIFT]: RumLayoutShiftTiming [RumPerformanceEntryType.PAINT]: RumPerformancePaintTiming + [RumPerformanceEntryType.LONG_TASK]: RumPerformanceLongTaskTiming [RumPerformanceEntryType.LONG_ANIMATION_FRAME]: RumPerformanceLongAnimationFrameTiming [RumPerformanceEntryType.NAVIGATION]: RumPerformanceNavigationTiming [RumPerformanceEntryType.RESOURCE]: RumPerformanceResourceTiming @@ -212,6 +223,7 @@ export function createPerformanceObservable( const fallbackSupportedEntryTypes = [ RumPerformanceEntryType.RESOURCE, RumPerformanceEntryType.NAVIGATION, + RumPerformanceEntryType.LONG_TASK, RumPerformanceEntryType.PAINT, ] if (fallbackSupportedEntryTypes.includes(options.type)) { diff --git a/packages/rum-core/src/domain/longTask/longTaskCollection.spec.ts b/packages/rum-core/src/domain/longTask/longTaskCollection.spec.ts new file mode 100644 index 0000000000..c438a14583 --- /dev/null +++ b/packages/rum-core/src/domain/longTask/longTaskCollection.spec.ts @@ -0,0 +1,84 @@ +import type { RelativeTime, ServerDuration } from '@datadog/browser-core' +import { + collectAndValidateRawRumEvents, + createPerformanceEntry, + mockPerformanceObserver, + mockRumConfiguration, +} from '../../../test' +import type { RumPerformanceEntry } from '../../browser/performanceObservable' +import { RumPerformanceEntryType } from '../../browser/performanceObservable' +import type { RawRumEvent } from '../../rawRumEvent.types' +import { RumEventType, RumLongTaskEntryType } from '../../rawRumEvent.types' +import type { RawRumEventCollectedData } from '../lifeCycle' +import { LifeCycle } from '../lifeCycle' +import { startLongTaskCollection } from './longTaskCollection' + +describe('long task collection', () => { + let lifeCycle = new LifeCycle() + let rawRumEvents: Array> = [] + let notifyPerformanceEntries: (entries: RumPerformanceEntry[]) => void + + function setupLongTaskCollection(trackLongTasks = true) { + ;({ notifyPerformanceEntries } = mockPerformanceObserver()) + + lifeCycle = new LifeCycle() + startLongTaskCollection(lifeCycle, mockRumConfiguration({ trackLongTasks })) + + rawRumEvents = collectAndValidateRawRumEvents(lifeCycle) + } + + it('should only listen to long task performance entry', () => { + setupLongTaskCollection() + + notifyPerformanceEntries([ + createPerformanceEntry(RumPerformanceEntryType.NAVIGATION), + createPerformanceEntry(RumPerformanceEntryType.LONG_TASK), + createPerformanceEntry(RumPerformanceEntryType.PAINT), + ]) + + expect(rawRumEvents.length).toBe(1) + }) + + it('should collect when trackLongTasks=true', () => { + setupLongTaskCollection() + + notifyPerformanceEntries([createPerformanceEntry(RumPerformanceEntryType.LONG_TASK)]) + expect(rawRumEvents.length).toBe(1) + }) + + it('should not collect when trackLongTasks=false', () => { + setupLongTaskCollection(false) + + notifyPerformanceEntries([createPerformanceEntry(RumPerformanceEntryType.LONG_TASK)]) + + expect(rawRumEvents.length).toBe(0) + }) + + it('should create raw rum event from performance entry', () => { + setupLongTaskCollection() + notifyPerformanceEntries([createPerformanceEntry(RumPerformanceEntryType.LONG_TASK)]) + + expect(rawRumEvents[0].startTime).toBe(1234 as RelativeTime) + expect(rawRumEvents[0].rawRumEvent).toEqual({ + date: jasmine.any(Number), + long_task: { + id: jasmine.any(String), + entry_type: RumLongTaskEntryType.LONG_TASK, + duration: (100 * 1e6) as ServerDuration, + }, + type: RumEventType.LONG_TASK, + _dd: { + discarded: false, + }, + }) + expect(rawRumEvents[0].domainContext).toEqual({ + performanceEntry: { + name: 'self', + duration: 100, + entryType: 'longtask', + startTime: 1234, + toJSON: jasmine.any(Function), + }, + }) + }) +}) diff --git a/packages/rum-core/src/domain/longTask/longTaskCollection.ts b/packages/rum-core/src/domain/longTask/longTaskCollection.ts new file mode 100644 index 0000000000..2ab4819a08 --- /dev/null +++ b/packages/rum-core/src/domain/longTask/longTaskCollection.ts @@ -0,0 +1,46 @@ +import { toServerDuration, relativeToClocks, generateUUID } from '@datadog/browser-core' +import type { RawRumLongTaskEvent } from '../../rawRumEvent.types' +import { RumEventType, RumLongTaskEntryType } from '../../rawRumEvent.types' +import type { LifeCycle } from '../lifeCycle' +import { LifeCycleEventType } from '../lifeCycle' +import { createPerformanceObservable, RumPerformanceEntryType } from '../../browser/performanceObservable' +import type { RumConfiguration } from '../configuration' +export function startLongTaskCollection(lifeCycle: LifeCycle, configuration: RumConfiguration) { + const performanceLongTaskSubscription = createPerformanceObservable(configuration, { + type: RumPerformanceEntryType.LONG_TASK, + buffered: true, + }).subscribe((entries) => { + for (const entry of entries) { + if (entry.entryType !== RumPerformanceEntryType.LONG_TASK) { + break + } + if (!configuration.trackLongTasks) { + break + } + const startClocks = relativeToClocks(entry.startTime) + const rawRumEvent: RawRumLongTaskEvent = { + date: startClocks.timeStamp, + long_task: { + id: generateUUID(), + entry_type: RumLongTaskEntryType.LONG_TASK, + duration: toServerDuration(entry.duration), + }, + type: RumEventType.LONG_TASK, + _dd: { + discarded: false, + }, + } + lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, { + rawRumEvent, + startTime: startClocks.relative, + domainContext: { performanceEntry: entry }, + }) + } + }) + + return { + stop() { + performanceLongTaskSubscription.unsubscribe() + }, + } +} diff --git a/packages/rum-core/test/fixtures.ts b/packages/rum-core/test/fixtures.ts index bd3888176c..afc06c1aa9 100644 --- a/packages/rum-core/test/fixtures.ts +++ b/packages/rum-core/test/fixtures.ts @@ -171,6 +171,18 @@ export function createPerformanceEntry( loadEventEnd: 567 as RelativeTime, ...overrides, } as EntryTypeToReturnType[T] + + case RumPerformanceEntryType.LONG_TASK: { + const entry = { + name: 'self', + duration: 100 as Duration, + entryType: RumPerformanceEntryType.LONG_TASK, + startTime: 1234 as RelativeTime, + ...overrides, + } as EntryTypeToReturnType[T] + + return { ...entry, toJSON: () => entry } + } case RumPerformanceEntryType.LONG_ANIMATION_FRAME: { const entry = { name: 'long-animation-frame', diff --git a/test/e2e/lib/helpers/browser.ts b/test/e2e/lib/helpers/browser.ts index 952c1fe661..260d098f19 100644 --- a/test/e2e/lib/helpers/browser.ts +++ b/test/e2e/lib/helpers/browser.ts @@ -69,13 +69,7 @@ export async function withBrowserLogs(fn: (logs: BrowserLog[]) => void) { // https://github.com/webdriverio/webdriverio/issues/4275 if (browser.getLogs) { const logs = (await browser.getLogs('browser')) as BrowserLog[] - - const filterdLogs = logs.filter( - // Ignore long-animation-frame warning (only happens on Edge) - (log) => !log.message.includes("The entry type 'long-animation-frame' does not exist or isn't supported") - ) - - fn(filterdLogs) + fn(logs) } }