-
Notifications
You must be signed in to change notification settings - Fork 170
[Profiling] Add action and vital metadata to profiles #4148
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
base: main
Are you sure you want to change the base?
Changes from all commits
b30b272
52c4fbc
ac62ddd
84bcf8d
5e88cac
48e21b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -68,6 +68,7 @@ export interface DurationVitalReference { | |||||||||||
| } | ||||||||||||
|
|
||||||||||||
| export interface DurationVitalStart extends DurationVitalOptions { | ||||||||||||
| id: string | ||||||||||||
| name: string | ||||||||||||
| startClocks: ClocksState | ||||||||||||
| handlingStack?: string | ||||||||||||
|
|
@@ -116,6 +117,12 @@ export function startVitalCollection( | |||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| function addDurationVitalWithId(vital: DurationVital, vitalId: string) { | ||||||||||||
| if (isValid(vital)) { | ||||||||||||
| lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, processVital(vital, vitalId)) | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
|
Comment on lines
+120
to
+125
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ❓ question: Why do you need this function? |
||||||||||||
| function addOperationStepVital( | ||||||||||||
| name: string, | ||||||||||||
| stepType: 'start' | 'end', | ||||||||||||
|
|
@@ -145,19 +152,22 @@ export function startVitalCollection( | |||||||||||
| addOperationStepVital, | ||||||||||||
| addDurationVital, | ||||||||||||
| startDurationVital: (name: string, options: DurationVitalOptions = {}) => | ||||||||||||
| startDurationVital(customVitalsState, name, options), | ||||||||||||
| startDurationVital(customVitalsState, lifeCycle, name, options), | ||||||||||||
| stopDurationVital: (nameOrRef: string | DurationVitalReference, options: DurationVitalOptions = {}) => { | ||||||||||||
| stopDurationVital(addDurationVital, customVitalsState, nameOrRef, options) | ||||||||||||
| stopDurationVital(addDurationVitalWithId, customVitalsState, nameOrRef, options) | ||||||||||||
| }, | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| export function startDurationVital( | ||||||||||||
| { vitalsByName, vitalsByReference }: CustomVitalsState, | ||||||||||||
| lifeCycle: LifeCycle | undefined, // the lifecycle might not be defined in case datadogRum is not initialized yet | ||||||||||||
| name: string, | ||||||||||||
| options: DurationVitalOptions = {} | ||||||||||||
| ) { | ||||||||||||
| const vitalId = generateUUID() | ||||||||||||
| const vital = { | ||||||||||||
| id: vitalId, | ||||||||||||
|
Comment on lines
+168
to
+170
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🥜 nitpick:
Suggested change
|
||||||||||||
| name, | ||||||||||||
| startClocks: clocksNow(), | ||||||||||||
| ...options, | ||||||||||||
|
|
@@ -171,11 +181,15 @@ export function startDurationVital( | |||||||||||
| // To avoid memory leaks caused by the creation of numerous references (e.g., from improper useEffect implementations), we use a WeakMap. | ||||||||||||
| vitalsByReference.set(reference, vital) | ||||||||||||
|
|
||||||||||||
| if (lifeCycle) { | ||||||||||||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💬 suggestion: Instead of having an optional startDurationVital: (name: string, options: DurationVitalOptions = {}) => {
const ref = startDurationVital(customVitalsState, name, options)
lifeCycle.notify(LifeCycleEventType.VITAL_STARTED, customVitalsState.vitalsByReference.get(ref)!)
return ref
}, |
||||||||||||
| lifeCycle.notify(LifeCycleEventType.VITAL_STARTED, vital) | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| return reference | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| export function stopDurationVital( | ||||||||||||
| stopCallback: (vital: DurationVital) => void, | ||||||||||||
| stopCallback: (vital: DurationVital, vitalId: string) => void, | ||||||||||||
| { vitalsByName, vitalsByReference }: CustomVitalsState, | ||||||||||||
| nameOrRef: string | DurationVitalReference, | ||||||||||||
| options: DurationVitalOptions = {} | ||||||||||||
|
|
@@ -186,7 +200,7 @@ export function stopDurationVital( | |||||||||||
| return | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| stopCallback(buildDurationVital(vitalStart, vitalStart.startClocks, options, clocksNow())) | ||||||||||||
| stopCallback(buildDurationVital(vitalStart, vitalStart.startClocks, options, clocksNow()), vitalStart.id) | ||||||||||||
|
|
||||||||||||
| if (typeof nameOrRef === 'string') { | ||||||||||||
| vitalsByName.delete(nameOrRef) | ||||||||||||
|
|
@@ -212,10 +226,13 @@ function buildDurationVital( | |||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| function processVital(vital: DurationVital | OperationStepVital): RawRumEventCollectedData<RawRumVitalEvent> { | ||||||||||||
| function processVital( | ||||||||||||
| vital: DurationVital | OperationStepVital, | ||||||||||||
| vitalId?: string | ||||||||||||
| ): RawRumEventCollectedData<RawRumVitalEvent> { | ||||||||||||
| const { startClocks, type, name, description, context, handlingStack } = vital | ||||||||||||
| const vitalData = { | ||||||||||||
| id: generateUUID(), | ||||||||||||
| id: vitalId ?? generateUUID(), | ||||||||||||
| type, | ||||||||||||
| name, | ||||||||||||
| description, | ||||||||||||
|
|
||||||||||||
Uh oh!
There was an error while loading. Please reload this page.
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.
💬 suggestion: You could make this part of eventTracker so you have the lifecycle event for click and manual actions. We also are planning to use eventTracker for vitals.
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.
I don't really have a way to know which event type I'm dealing with in the
startmethod of the event tracker, right? So do you imagine one of the two following things:starttakes an optional function executed before returning, and that would in our case emit the life cycle event?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.
Yes right, it’s a bit tricky. Let’s keep it simple.
You can keep it here, but we also need to handle click actions. So it should be added here as well.