-
Notifications
You must be signed in to change notification settings - Fork 148
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* ♻️ move types to a dedicated file * ✨ define v2 types and events * ✨ generate long tasks in v2 * ✨ handle v2 events * ✨ add format validation during unit tests
- Loading branch information
Showing
36 changed files
with
915 additions
and
253 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[submodule "rum-events-format"] | ||
path = rum-events-format | ||
url = https://github.com/DataDog/rum-events-format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ bundle | |
cjs | ||
esm | ||
coverage | ||
rum-events-format |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { combine, Configuration, Context, withSnakeCaseKeys } from '@datadog/browser-core' | ||
import { LifeCycle, LifeCycleEventType } from './lifeCycle' | ||
import { ParentContexts } from './parentContexts' | ||
import { RumSession } from './rumSession' | ||
import { RawRumEvent, RumContext, RumErrorEvent, RumEventCategory, RumLongTaskEvent, RumResourceEvent } from './types' | ||
import { | ||
RawRumEventV2, | ||
RumContextV2, | ||
RumErrorEventV2, | ||
RumEventType, | ||
RumLongTaskEventV2, | ||
RumResourceEventV2, | ||
} from './typesV2' | ||
|
||
interface BrowserWindow extends Window { | ||
_DATADOG_SYNTHETICS_BROWSER?: unknown | ||
} | ||
|
||
enum SessionType { | ||
SYNTHETICS = 'synthetics', | ||
USER = 'user', | ||
} | ||
|
||
export function startRumAssemblyV2( | ||
applicationId: string, | ||
configuration: Configuration, | ||
lifeCycle: LifeCycle, | ||
session: RumSession, | ||
parentContexts: ParentContexts, | ||
getGlobalContext: () => Context | ||
) { | ||
lifeCycle.subscribe( | ||
LifeCycleEventType.RAW_RUM_EVENT_V2_COLLECTED, | ||
({ | ||
startTime, | ||
rawRumEvent, | ||
savedGlobalContext, | ||
customerContext, | ||
}: { | ||
startTime: number | ||
rawRumEvent: RawRumEventV2 | ||
savedGlobalContext?: Context | ||
customerContext?: Context | ||
}) => { | ||
const viewContext = parentContexts.findViewV2(startTime) | ||
if (session.isTracked() && viewContext && viewContext.session.id) { | ||
const actionContext = parentContexts.findActionV2(startTime) | ||
const rumContext: RumContextV2 = { | ||
_dd: { | ||
formatVersion: 2, | ||
}, | ||
application: { | ||
id: applicationId, | ||
}, | ||
date: new Date().getTime(), | ||
service: configuration.service, | ||
session: { | ||
// must be computed on each event because synthetics instrumentation can be done after sdk execution | ||
// cf https://github.com/puppeteer/puppeteer/issues/3667 | ||
type: getSessionType(), | ||
}, | ||
} | ||
const rumEvent = needToAssembleWithAction(rawRumEvent) | ||
? combine(rumContext, viewContext, actionContext, rawRumEvent) | ||
: combine(rumContext, viewContext, rawRumEvent) | ||
const serverRumEvent = combine( | ||
savedGlobalContext || getGlobalContext(), | ||
customerContext, | ||
withSnakeCaseKeys(rumEvent) | ||
) | ||
lifeCycle.notify(LifeCycleEventType.RUM_EVENT_V2_COLLECTED, { rumEvent, serverRumEvent }) | ||
} | ||
} | ||
) | ||
} | ||
|
||
function needToAssembleWithAction( | ||
event: RawRumEventV2 | ||
): event is RumErrorEventV2 | RumResourceEventV2 | RumLongTaskEventV2 { | ||
return [RumEventType.ERROR, RumEventType.RESOURCE, RumEventType.LONG_TASK].indexOf(event.type) !== -1 | ||
} | ||
|
||
function getSessionType() { | ||
return (window as BrowserWindow)._DATADOG_SYNTHETICS_BROWSER === undefined ? SessionType.USER : SessionType.SYNTHETICS | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,10 @@ | ||
export { Datacenter } from '@datadog/browser-core' | ||
export { RumUserConfiguration, RumGlobal, datadogRum, InternalContext } from './rum.entry' | ||
export { RumEventCategory, RumResourceEvent, RumViewEvent, RumUserActionEvent } from './rum' | ||
export { RumEvent } from './assembly' | ||
export { RumUserConfiguration, RumGlobal, datadogRum } from './rum.entry' | ||
export { | ||
InternalContext, | ||
RumEvent, | ||
RumEventCategory, | ||
RumUserActionEvent, | ||
RumViewEvent, | ||
RumResourceEvent, | ||
} from './types' |
Oops, something went wrong.