Skip to content

Commit

Permalink
Revert "[RUM] add session.has_replay (DataDog#687)"
Browse files Browse the repository at this point in the history
This reverts commit 421f145.
  • Loading branch information
kcaffrey authored Jan 29, 2021
1 parent f8e43b8 commit 1b14802
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 51 deletions.
64 changes: 21 additions & 43 deletions packages/rum-core/src/domain/assembly.spec.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
import { DEFAULT_CONFIGURATION, noop } from '@datadog/browser-core'
import { Context, DEFAULT_CONFIGURATION, noop } from '@datadog/browser-core'
import { createRawRumEvent } from '../../test/fixtures'
import { setup, TestSetupBuilder } from '../../test/specHelper'
import { CommonContext, RumEventType } from '../rawRumEvent.types'
import { RumEventType, User } from '../rawRumEvent.types'
import { RumActionEvent, RumEvent, RumLongTaskEvent } from '../rumEvent.types'
import { startRumAssembly } from './assembly'
import { LifeCycle, LifeCycleEventType } from './lifeCycle'

describe('rum assembly', () => {
let setupBuilder: TestSetupBuilder
let lifeCycle: LifeCycle
let commonContext: CommonContext
let globalContext: Context
let user: User
let serverRumEvents: RumEvent[]
let isTracked: boolean
let viewSessionId: string | undefined
Expand All @@ -18,10 +19,8 @@ describe('rum assembly', () => {
beforeEach(() => {
isTracked = true
viewSessionId = '1234'
commonContext = {
context: {},
user: {},
}
globalContext = {}
user = {}
beforeSend = noop
setupBuilder = setup()
.withSession({
Expand Down Expand Up @@ -51,7 +50,10 @@ describe('rum assembly', () => {
}),
})
.beforeBuild(({ applicationId, configuration, lifeCycle: localLifeCycle, session, parentContexts }) => {
startRumAssembly(applicationId, configuration, localLifeCycle, session, parentContexts, () => commonContext)
startRumAssembly(applicationId, configuration, localLifeCycle, session, parentContexts, () => ({
user,
context: globalContext,
}))
})
;({ lifeCycle } = setupBuilder.build())

Expand Down Expand Up @@ -132,7 +134,7 @@ describe('rum assembly', () => {

describe('rum global context', () => {
it('should be merged with event attributes', () => {
commonContext.context = { bar: 'foo' }
globalContext = { bar: 'foo' }
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
startTime: 0,
Expand All @@ -142,7 +144,7 @@ describe('rum assembly', () => {
})

it('should not be included if empty', () => {
commonContext.context = {}
globalContext = {}
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
startTime: 0,
Expand All @@ -152,12 +154,12 @@ describe('rum assembly', () => {
})

it('should ignore subsequent context mutation', () => {
commonContext.context = { bar: 'foo', baz: 'foz' }
globalContext = { bar: 'foo', baz: 'foz' }
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
startTime: 0,
})
delete commonContext.context.bar
delete globalContext.bar
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
startTime: 0,
Expand All @@ -168,7 +170,7 @@ describe('rum assembly', () => {
})

it('should not be automatically snake cased', () => {
commonContext.context = { fooBar: 'foo' }
globalContext = { fooBar: 'foo' }
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
startTime: 0,
Expand All @@ -178,7 +180,7 @@ describe('rum assembly', () => {
})

it('should ignore the current global context when a saved global context is provided', () => {
commonContext.context = { replacedContext: 'b', addedContext: 'x' }
globalContext = { replacedContext: 'b', addedContext: 'x' }

lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
Expand All @@ -196,7 +198,7 @@ describe('rum assembly', () => {

describe('rum user', () => {
it('should be included in event attributes', () => {
commonContext.user = { id: 'foo' }
user = { id: 'foo' }
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
startTime: 0,
Expand All @@ -206,7 +208,7 @@ describe('rum assembly', () => {
})

it('should not be included if empty', () => {
commonContext.user = {}
user = {}
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
startTime: 0,
Expand All @@ -216,7 +218,7 @@ describe('rum assembly', () => {
})

it('should not be automatically snake cased', () => {
commonContext.user = { fooBar: 'foo' }
user = { fooBar: 'foo' }
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
startTime: 0,
Expand All @@ -226,7 +228,7 @@ describe('rum assembly', () => {
})

it('should ignore the current user when a saved common context user is provided', () => {
commonContext.user = { replacedAttribute: 'b', addedAttribute: 'x' }
user = { replacedAttribute: 'b', addedAttribute: 'x' }

lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
Expand Down Expand Up @@ -306,7 +308,7 @@ describe('rum assembly', () => {
})
})

describe('event generation condition', () => {
describe('session', () => {
it('when tracked, it should generate event', () => {
isTracked = true

Expand Down Expand Up @@ -347,28 +349,4 @@ describe('rum assembly', () => {
expect(serverRumEvents.length).toBe(0)
})
})

describe('session context', () => {
it('should include the session type and id', () => {
lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
startTime: 0,
})
expect(serverRumEvents[0].session).toEqual({
has_replay: undefined,
id: '1234',
type: 'user',
})
})

it('should set the session.has_replay attribute if it is defined in the common context', () => {
commonContext.hasReplay = true

lifeCycle.notify(LifeCycleEventType.RAW_RUM_EVENT_COLLECTED, {
rawRumEvent: createRawRumEvent(RumEventType.VIEW),
startTime: 0,
})
expect(serverRumEvents[0].session.has_replay).toBe(true)
})
})
})
3 changes: 1 addition & 2 deletions packages/rum-core/src/domain/assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ export function startRumAssembly(
const viewContext = parentContexts.findView(startTime)
if (session.isTracked() && viewContext && viewContext.session.id) {
const actionContext = parentContexts.findAction(startTime)
const commonContext = savedCommonContext || getCommonContext()
const rumContext: RumContext = {
_dd: {
formatVersion: 2,
Expand All @@ -65,7 +64,6 @@ export function startRumAssembly(
date: new Date().getTime(),
service: configuration.service,
session: {
has_replay: commonContext.hasReplay,
// 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(),
Expand All @@ -75,6 +73,7 @@ export function startRumAssembly(
? combine(rumContext, viewContext, actionContext, rawRumEvent)
: combine(rumContext, viewContext, rawRumEvent)
const serverRumEvent = withSnakeCaseKeys(assembledRumEvent) as RumEvent & Context
const commonContext = savedCommonContext || getCommonContext()

const context = combine(commonContext.context, customerContext)
if (!isEmptyObject(context)) {
Expand Down
1 change: 0 additions & 1 deletion packages/rum-core/src/rawRumEvent.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ export interface RumContext {
service?: string
session: {
type: string
has_replay?: boolean
}
_dd: {
formatVersion: 2
Expand Down
4 changes: 0 additions & 4 deletions packages/rum-core/src/rumEvent.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -568,10 +568,6 @@ export interface CommonProperties {
* Type of the session
*/
readonly type: 'user' | 'synthetics'
/**
* Whether this session has a replay
*/
readonly has_replay?: boolean
[k: string]: unknown
}
/**
Expand Down
2 changes: 1 addition & 1 deletion rum-events-format

0 comments on commit 1b14802

Please sign in to comment.