Skip to content
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

✨ [RUMF-438] add user action reference to the internal context #352

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion packages/rum/src/rum.entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -32,6 +32,7 @@ export interface InternalContext {
view: {
id: string
}
user_action?: UserActionReference
}

const STUBBED_RUM = {
Expand Down
21 changes: 12 additions & 9 deletions packages/rum/src/rum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -219,15 +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,
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
}),
Expand Down
9 changes: 5 additions & 4 deletions packages/rum/src/userActionCollection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@ 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 || (time !== undefined && time < currentUserAction.startTime)) {
return undefined
}
return undefined

return { id: currentUserAction.id }
}

interface UserActionCompleteEvent {
Expand Down