@@ -10,6 +10,8 @@ import { PageState } from '../contexts/pageStateHistory'
10
10
export interface DurationVitalOptions {
11
11
context ?: Context
12
12
description ?: string
13
+ // EXPERIMENTAL: This option is used to mark a vital as a user story.
14
+ userStory ?: boolean
13
15
}
14
16
15
17
export interface DurationVitalReference {
@@ -58,10 +60,18 @@ export function startVitalCollection(
58
60
}
59
61
}
60
62
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
+
61
71
return {
62
72
addDurationVital,
63
73
startDurationVital : ( name : string , options : DurationVitalOptions = { } ) =>
64
- startDurationVital ( customVitalsState , name , options ) ,
74
+ startDurationVital ( customVitalsState , name , options , sendDurationVitalStartEvent ) ,
65
75
stopDurationVital : ( nameOrRef : string | DurationVitalReference , options : DurationVitalOptions = { } ) => {
66
76
stopDurationVital ( addDurationVital , customVitalsState , nameOrRef , options )
67
77
} ,
@@ -71,7 +81,8 @@ export function startVitalCollection(
71
81
export function startDurationVital (
72
82
{ vitalsByName, vitalsByReference } : CustomVitalsState ,
73
83
name : string ,
74
- options : DurationVitalOptions = { }
84
+ options : DurationVitalOptions = { } ,
85
+ sendDurationVitalStart ?: ( vital : DurationVitalStart ) => void
75
86
) {
76
87
const vital = {
77
88
name,
@@ -80,9 +91,18 @@ export function startDurationVital(
80
91
description : options . description ,
81
92
}
82
93
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
+
83
104
// To avoid leaking implementation details of the vital, we return a reference to it.
84
105
const reference : DurationVitalReference = { __dd_vital_reference : true }
85
-
86
106
vitalsByName . set ( name , vital )
87
107
88
108
// To avoid memory leaks caused by the creation of numerous references (e.g., from improper useEffect implementations), we use a WeakMap.
0 commit comments