-
Notifications
You must be signed in to change notification settings - Fork 168
⚗ [RUM-11393] Add Start/StopAction API #4038
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
Changes from 1 commit
2f11566
065a6fe
aec81c6
270c0cb
b0bc642
a06410a
2080477
b4af4f6
3e88bd7
f129855
2259509
446390e
efe5ffc
2c95977
546fdde
d7a7e14
e8725ba
9864c12
a19c4d0
5b40d1e
b513153
f13b695
969a859
f8c506e
c3ddeeb
e1f4512
fda20bb
80850cf
573cb0a
ee43b93
7946916
4227e82
1b690e5
3e0bbd9
40e8331
8e6763f
feead72
d6a11c0
02fa207
c28599f
20019e3
0dc0e6a
53b70d9
66ce586
c0a3fd5
06d7565
d299a36
7754bcc
33289a4
17846f0
2404882
27d07cf
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 |
|---|---|---|
|
|
@@ -38,43 +38,30 @@ export interface ActionTracker { | |
|
|
||
| export function startActionTracker(lifeCycle: LifeCycle): ActionTracker { | ||
|
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. 💭 thought: With this implementation, custom actions can have a duration and be linked to other events. I think it’s a good direction, but we should check with Product to get their view. We should also align with Frontend to make sure they can handle these new action types coming from the browser. |
||
| const history = createValueHistory<string>({ expireDelay: ACTION_CONTEXT_TIME_OUT_DELAY }) | ||
| const activeEventCountSubscriptions = new Set<ReturnType<typeof trackEventCounts>>() | ||
| const activeSubs = new Set<ReturnType<typeof trackEventCounts>>() | ||
|
|
||
| const sessionRenewalSubscription = lifeCycle.subscribe(LifeCycleEventType.SESSION_RENEWED, () => { | ||
| history.reset() | ||
| activeEventCountSubscriptions.forEach((s) => s.stop()) | ||
| activeEventCountSubscriptions.clear() | ||
| activeSubs.forEach((s) => s.stop()) | ||
| activeSubs.clear() | ||
| }) | ||
|
|
||
| function createTrackedAction(startClocks: ClocksState, metadata?: TrackedActionMetadata): TrackedAction { | ||
| const id = generateUUID() | ||
| const historyEntry: ValueHistoryEntry<string> = history.add(id, startClocks.relative) | ||
| let stopped = false | ||
| let duration: Duration | undefined | ||
|
|
||
| const eventCountsSubscription = trackEventCounts({ | ||
| const sub = trackEventCounts({ | ||
BeltranBulbarellaDD marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| lifeCycle, | ||
| isChildEvent: (event) => | ||
| event.action !== undefined && | ||
| (Array.isArray(event.action.id) ? event.action.id.includes(id) : event.action.id === id), | ||
| }) | ||
| activeEventCountSubscriptions.add(eventCountsSubscription) | ||
| activeSubs.add(sub) | ||
|
|
||
| function stopOrDiscard(endTime?: RelativeTime) { | ||
| if (stopped) { | ||
| return | ||
| } | ||
| stopped = true | ||
|
|
||
| if (endTime !== undefined) { | ||
| historyEntry.close(endTime) | ||
| duration = elapsed(startClocks.relative, endTime) | ||
| } else { | ||
| historyEntry.remove() | ||
| } | ||
|
|
||
| eventCountsSubscription.stop() | ||
| activeEventCountSubscriptions.delete(eventCountsSubscription) | ||
| function cleanup() { | ||
| sub.stop() | ||
| activeSubs.delete(sub) | ||
| } | ||
|
|
||
| return { | ||
|
|
@@ -85,32 +72,32 @@ export function startActionTracker(lifeCycle: LifeCycle): ActionTracker { | |
| return duration | ||
| }, | ||
| get counts() { | ||
| return eventCountsSubscription.eventCounts | ||
| return sub.eventCounts | ||
| }, | ||
| stop(endTime: RelativeTime) { | ||
| historyEntry.close(endTime) | ||
| duration = elapsed(startClocks.relative, endTime) | ||
| cleanup() | ||
| }, | ||
| discard() { | ||
| historyEntry.remove() | ||
| cleanup() | ||
| }, | ||
| stop: stopOrDiscard, | ||
| discard: stopOrDiscard, | ||
| } | ||
| } | ||
|
|
||
| function findActionId(startTime?: RelativeTime): string | string[] | undefined { | ||
| const ids = history.findAll(startTime) | ||
| if (ids.length === 0) { | ||
| return undefined | ||
| } | ||
| return ids | ||
| return ids.length ? ids : undefined | ||
| } | ||
|
|
||
| function stop() { | ||
| sessionRenewalSubscription.unsubscribe() | ||
| activeEventCountSubscriptions.forEach((s) => s.stop()) | ||
| activeEventCountSubscriptions.clear() | ||
| activeSubs.forEach((s) => s.stop()) | ||
| activeSubs.clear() | ||
| history.reset() | ||
| history.stop() | ||
| } | ||
|
|
||
| return { | ||
| createTrackedAction, | ||
| findActionId, | ||
| stop, | ||
| } | ||
| return { createTrackedAction, findActionId, stop } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.