Skip to content

Commit

Permalink
✨[RUMF-435] add session type on all events
Browse files Browse the repository at this point in the history
- `user` for regular session
- `synthetics` for browser test sessions
  • Loading branch information
bcaudan committed Apr 8, 2020
1 parent fa49ad9 commit 6043938
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/rum/src/rum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ export interface RumUserActionEvent {

export type RumEvent = RumErrorEvent | RumResourceEvent | RumViewEvent | RumLongTaskEvent | RumUserActionEvent

enum SessionType {
SYNTHETICS = 'synthetics',
USER = 'user',
}

export function startRum(
applicationId: string,
lifeCycle: LifeCycle,
Expand All @@ -177,12 +182,17 @@ export function startRum(
)
)

const sessionTpe = getSessionType()

const batch = startRumBatch(
configuration,
session,
() => ({
applicationId,
date: new Date().getTime(),
session: {
type: sessionTpe,
},
sessionId: viewContext.sessionId,
view: {
id: viewContext.id,
Expand Down Expand Up @@ -411,3 +421,11 @@ export function handleLongTaskEntry(entry: PerformanceLongTaskTiming, addRumEven
userActionId: getUserActionId(entry.startTime),
})
}

interface BrowserWindow extends Window {
_DATADOG_SYNTHETICS_BROWSER?: unknown
}

function getSessionType() {
return (window as BrowserWindow)._DATADOG_SYNTHETICS_BROWSER === undefined ? SessionType.USER : SessionType.SYNTHETICS
}

0 comments on commit 6043938

Please sign in to comment.