-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
2843c96
commit c0de7ea
Showing
12 changed files
with
403 additions
and
11 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
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
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
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
98 changes: 98 additions & 0 deletions
98
packages/rum-core/src/domain/longAnimationFrame/longAnimationFrameCollection.spec.ts
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,98 @@ | ||
import { type RelativeTime, type ServerDuration } from '@datadog/browser-core' | ||
import { registerCleanupTask } from '@datadog/browser-core/test' | ||
import { collectAndValidateRawRumEvents, createPerformanceEntry, mockPerformanceObserver } from '../../../test' | ||
import { RumPerformanceEntryType } from '../../browser/performanceObservable' | ||
import { RumEventType, RumLongTaskEntryType } from '../../rawRumEvent.types' | ||
import { LifeCycle } from '../lifeCycle' | ||
import type { RumConfiguration } from '../configuration' | ||
import { startLongAnimationFrameCollection } from './longAnimationFrameCollection' | ||
|
||
describe('long animation frames collection', () => { | ||
it('should create raw rum event from long animation frame performance entry', () => { | ||
const { notifyPerformanceEntries, rawRumEvents } = setupLongAnimationFrameCollection() | ||
const PerformanceLongAnimationFrameTiming = createPerformanceEntry(RumPerformanceEntryType.LONG_ANIMATION_FRAME) | ||
|
||
notifyPerformanceEntries([PerformanceLongAnimationFrameTiming]) | ||
|
||
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_ANIMATION_FRAME, | ||
duration: (82 * 1e6) as ServerDuration, | ||
blocking_duration: 0 as ServerDuration, | ||
first_ui_event_timestamp: 0 as RelativeTime, | ||
render_start: 1421.5 as RelativeTime, | ||
style_and_layout_start: 1428 as RelativeTime, | ||
scripts: [ | ||
{ | ||
duration: (6 * 1e6) as ServerDuration, | ||
pause_duration: 0 as ServerDuration, | ||
forced_style_and_layout_duration: 0 as ServerDuration, | ||
start_time: 1348 as RelativeTime, | ||
execution_start: 1348.7 as RelativeTime, | ||
source_url: 'http://example.com/script.js', | ||
source_function_name: '', | ||
source_char_position: 9876, | ||
invoker: 'http://example.com/script.js', | ||
invoker_type: 'classic-script', | ||
window_attribution: 'self', | ||
}, | ||
], | ||
}, | ||
type: RumEventType.LONG_TASK, | ||
_dd: { | ||
discarded: false, | ||
}, | ||
}) | ||
expect(rawRumEvents[0].domainContext).toEqual({ | ||
performanceEntry: { | ||
name: 'long-animation-frame', | ||
duration: 82, | ||
entryType: 'long-animation-frame', | ||
startTime: 1234, | ||
renderStart: 1421.5, | ||
styleAndLayoutStart: 1428, | ||
firstUIEventTimestamp: 0, | ||
blockingDuration: 0, | ||
scripts: [ | ||
{ | ||
name: 'script', | ||
entryType: 'script', | ||
startTime: 1348, | ||
duration: 6, | ||
invoker: 'http://example.com/script.js', | ||
invokerType: 'classic-script', | ||
windowAttribution: 'self', | ||
executionStart: 1348.7, | ||
forcedStyleAndLayoutDuration: 0, | ||
pauseDuration: 0, | ||
sourceURL: 'http://example.com/script.js', | ||
sourceFunctionName: '', | ||
sourceCharPosition: 9876, | ||
}, | ||
], | ||
toJSON: jasmine.any(Function), | ||
}, | ||
}) | ||
}) | ||
}) | ||
|
||
function setupLongAnimationFrameCollection() { | ||
const lifeCycle = new LifeCycle() | ||
const configuration = {} as RumConfiguration | ||
|
||
const notifyPerformanceEntries = mockPerformanceObserver().notifyPerformanceEntries | ||
const rawRumEvents = collectAndValidateRawRumEvents(lifeCycle) | ||
const { stop: stopLongAnimationFrameCollection } = startLongAnimationFrameCollection(lifeCycle, configuration) | ||
|
||
registerCleanupTask(() => { | ||
stopLongAnimationFrameCollection() | ||
}) | ||
|
||
return { | ||
notifyPerformanceEntries, | ||
rawRumEvents, | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
packages/rum-core/src/domain/longAnimationFrame/longAnimationFrameCollection.ts
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,58 @@ | ||
import { toServerDuration, relativeToClocks, generateUUID } from '@datadog/browser-core' | ||
import type { RawRumLongAnimationFrameEvent } 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 startLongAnimationFrameCollection(lifeCycle: LifeCycle, configuration: RumConfiguration) { | ||
const performanceResourceSubscription = createPerformanceObservable(configuration, { | ||
type: RumPerformanceEntryType.LONG_ANIMATION_FRAME, | ||
buffered: true, | ||
}).subscribe((entries) => { | ||
for (const entry of entries) { | ||
const startClocks = relativeToClocks(entry.startTime) | ||
|
||
const rawRumEvent: RawRumLongAnimationFrameEvent = { | ||
date: startClocks.timeStamp, | ||
long_task: { | ||
id: generateUUID(), | ||
entry_type: RumLongTaskEntryType.LONG_ANIMATION_FRAME, | ||
duration: toServerDuration(entry.duration), | ||
blocking_duration: toServerDuration(entry.blockingDuration), | ||
first_ui_event_timestamp: relativeToClocks(entry.firstUIEventTimestamp).relative, | ||
render_start: relativeToClocks(entry.renderStart).relative, | ||
style_and_layout_start: relativeToClocks(entry.styleAndLayoutStart).relative, | ||
scripts: entry.scripts.map((script) => ({ | ||
duration: toServerDuration(script.duration), | ||
pause_duration: toServerDuration(script.pauseDuration), | ||
forced_style_and_layout_duration: toServerDuration(script.forcedStyleAndLayoutDuration), | ||
start_time: relativeToClocks(script.startTime).relative, | ||
execution_start: relativeToClocks(script.executionStart).relative, | ||
source_url: script.sourceURL, | ||
source_function_name: script.sourceFunctionName, | ||
source_char_position: script.sourceCharPosition, | ||
invoker: script.invoker, | ||
invoker_type: script.invokerType, | ||
window_attribution: script.windowAttribution, | ||
})), | ||
}, | ||
type: RumEventType.LONG_TASK, | ||
_dd: { | ||
discarded: false, | ||
}, | ||
} | ||
|
||
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, { | ||
rawRumEvent, | ||
startTime: startClocks.relative, | ||
domainContext: { performanceEntry: entry }, | ||
}) | ||
} | ||
}) | ||
|
||
return { | ||
stop: () => performanceResourceSubscription.unsubscribe(), | ||
} | ||
} |
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
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
Oops, something went wrong.