From 795486e8fbbd6689d7654502984af8861e7f91bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Zugmeyer?= Date: Thu, 9 Apr 2020 17:20:43 +0200 Subject: [PATCH 1/2] =?UTF-8?q?=E2=9C=A8=20[RUMF-438]=20add=20user=20actio?= =?UTF-8?q?n=20reference=20to=20the=20internal=20context?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Logs and traces will automatically pick up and associate this to their sent data. --- packages/rum/src/rum.entry.ts | 3 ++- packages/rum/src/rum.ts | 1 + packages/rum/src/userActionCollection.ts | 13 +++++++++---- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/packages/rum/src/rum.entry.ts b/packages/rum/src/rum.entry.ts index a5f610ce02..6678bb5d0e 100644 --- a/packages/rum/src/rum.entry.ts +++ b/packages/rum/src/rum.entry.ts @@ -20,7 +20,7 @@ import { LifeCycle, LifeCycleEventType } from './lifeCycle' import { startPerformanceCollection } from './performanceCollection' import { startRum } from './rum' import { startRumSession } from './rumSession' -import { startUserActionCollection } from './userActionCollection' +import { startUserActionCollection, UserActionReference } from './userActionCollection' export interface RumUserConfiguration extends UserConfiguration { applicationId: string @@ -32,6 +32,7 @@ export interface InternalContext { view: { id: string } + user_action?: UserActionReference } const STUBBED_RUM = { diff --git a/packages/rum/src/rum.ts b/packages/rum/src/rum.ts index 46c6196b27..81fc2f1b9a 100644 --- a/packages/rum/src/rum.ts +++ b/packages/rum/src/rum.ts @@ -223,6 +223,7 @@ export function startRum( return { application_id: applicationId, session_id: viewContext.sessionId, + user_action: getUserActionReference(), view: { id: viewContext.id, }, diff --git a/packages/rum/src/userActionCollection.ts b/packages/rum/src/userActionCollection.ts index 009a79829a..a7a712a7a6 100644 --- a/packages/rum/src/userActionCollection.ts +++ b/packages/rum/src/userActionCollection.ts @@ -74,11 +74,16 @@ let currentUserAction: { id: string; startTime: number } | undefined export interface UserActionReference { id: string } -export function getUserActionReference(time: number): UserActionReference | undefined { - if (currentUserAction && time >= currentUserAction.startTime) { - return { id: currentUserAction.id } +export function getUserActionReference(time?: number): UserActionReference | undefined { + if (!currentUserAction) { + return undefined } - return undefined + + if (time !== undefined && time < currentUserAction.startTime) { + return undefined + } + + return { id: currentUserAction.id } } interface UserActionCompleteEvent { From c27458c246cedafc5711274cd317971bf8620764 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Beno=C3=AEt=20Zugmeyer?= Date: Thu, 9 Apr 2020 18:58:13 +0200 Subject: [PATCH 2/2] =?UTF-8?q?=F0=9F=91=8C=20[RUM]=20InternalContext=20ty?= =?UTF-8?q?pe=20enforcement=20and=20code=20format?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/rum/src/rum.ts | 22 ++++++++++++---------- packages/rum/src/userActionCollection.ts | 6 +----- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/packages/rum/src/rum.ts b/packages/rum/src/rum.ts index 81fc2f1b9a..849a571def 100644 --- a/packages/rum/src/rum.ts +++ b/packages/rum/src/rum.ts @@ -29,7 +29,7 @@ import { computeSize, isValidResource, } from './resourceUtils' -import { RumGlobal } from './rum.entry' +import { InternalContext, RumGlobal } from './rum.entry' import { RumSession } from './rumSession' import { getUserActionReference, UserActionReference } from './userActionCollection' import { trackView, viewContext, ViewMeasures } from './viewTracker' @@ -219,16 +219,18 @@ export function startRum( addUserAction: monitor((name: string, context?: Context) => { lifeCycle.notify(LifeCycleEventType.USER_ACTION_COLLECTED, { context, name, type: UserActionType.CUSTOM }) }), - getInternalContext: monitor(() => { - return { - application_id: applicationId, - session_id: viewContext.sessionId, - user_action: getUserActionReference(), - view: { - id: viewContext.id, - }, + getInternalContext: monitor( + (): InternalContext => { + return { + application_id: applicationId, + session_id: viewContext.sessionId, + user_action: getUserActionReference(), + view: { + id: viewContext.id, + }, + } } - }), + ), setRumGlobalContext: monitor((context: Context) => { globalContext = context }), diff --git a/packages/rum/src/userActionCollection.ts b/packages/rum/src/userActionCollection.ts index a7a712a7a6..b57e074168 100644 --- a/packages/rum/src/userActionCollection.ts +++ b/packages/rum/src/userActionCollection.ts @@ -75,11 +75,7 @@ export interface UserActionReference { id: string } export function getUserActionReference(time?: number): UserActionReference | undefined { - if (!currentUserAction) { - return undefined - } - - if (time !== undefined && time < currentUserAction.startTime) { + if (!currentUserAction || (time !== undefined && time < currentUserAction.startTime)) { return undefined }