-
Notifications
You must be signed in to change notification settings - Fork 141
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[RUM-5705] Collect Long Animation Frames #2924
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b0bc943
[RUM-5705] Collect Long Animation Frames
thomas-lebeau 6243371
fix fixture
thomas-lebeau 4d9f22a
fix Loaf types
thomas-lebeau 2dc41b4
♻️ use a performance observable instead of the lifecycle
thomas-lebeau aa095bd
✅ add untit test
thomas-lebeau 6224eff
Merge branch 'main' into thomas.lebeau/loaf
thomas-lebeau 8735d4b
👌 use collectAndValidateRawRumEvents after merging main
thomas-lebeau afe5c7e
sync rum-events-format
thomas-lebeau File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Despites the name suggest, it's a relative time similarly to
renderStart