Skip to content

Commit 5a0698c

Browse files
Integrate congyao/RUM-9952-send-event-on-vital-start (#3570) into staging-22
Integrated commit sha: 00e6022 Co-authored-by: cy-moi <[email protected]>
2 parents ddab235 + 00e6022 commit 5a0698c

File tree

1 file changed

+23
-3
lines changed

1 file changed

+23
-3
lines changed

packages/rum-core/src/domain/vital/vitalCollection.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import { PageState } from '../contexts/pageStateHistory'
1010
export interface DurationVitalOptions {
1111
context?: Context
1212
description?: string
13+
// EXPERIMENTAL: This option is used to mark a vital as a user story.
14+
userStory?: boolean
1315
}
1416

1517
export interface DurationVitalReference {
@@ -58,10 +60,18 @@ export function startVitalCollection(
5860
}
5961
}
6062

63+
function sendDurationVitalStartEvent(vital: DurationVitalStart) {
64+
if (vital) {
65+
// temporary hack to send an event when the vital is started
66+
const durationVitalStart = buildDurationVital(vital, vital.startClocks, {}, clocksNow())
67+
addDurationVital(durationVitalStart)
68+
}
69+
}
70+
6171
return {
6272
addDurationVital,
6373
startDurationVital: (name: string, options: DurationVitalOptions = {}) =>
64-
startDurationVital(customVitalsState, name, options),
74+
startDurationVital(customVitalsState, name, options, sendDurationVitalStartEvent),
6575
stopDurationVital: (nameOrRef: string | DurationVitalReference, options: DurationVitalOptions = {}) => {
6676
stopDurationVital(addDurationVital, customVitalsState, nameOrRef, options)
6777
},
@@ -71,7 +81,8 @@ export function startVitalCollection(
7181
export function startDurationVital(
7282
{ vitalsByName, vitalsByReference }: CustomVitalsState,
7383
name: string,
74-
options: DurationVitalOptions = {}
84+
options: DurationVitalOptions = {},
85+
sendDurationVitalStart?: (vital: DurationVitalStart) => void
7586
) {
7687
const vital = {
7788
name,
@@ -80,9 +91,18 @@ export function startDurationVital(
8091
description: options.description,
8192
}
8293

94+
// EXPERIMENTAL: If the user story option is set, we send a start event immediately.
95+
if (sendDurationVitalStart && options.userStory) {
96+
sendDurationVitalStart(vital)
97+
vital.context = combine(vital.context, {
98+
userStory: options.userStory,
99+
id: generateUUID(),
100+
status: 'in-progress',
101+
})
102+
}
103+
83104
// To avoid leaking implementation details of the vital, we return a reference to it.
84105
const reference: DurationVitalReference = { __dd_vital_reference: true }
85-
86106
vitalsByName.set(name, vital)
87107

88108
// To avoid memory leaks caused by the creation of numerous references (e.g., from improper useEffect implementations), we use a WeakMap.

0 commit comments

Comments
 (0)