Skip to content

Commit

Permalink
✨ [RUMF-758] keep internal context in v1 format (#625)
Browse files Browse the repository at this point in the history
keep compatibility with logs data format
  • Loading branch information
bcaudan authored Nov 20, 2020
1 parent de06363 commit 8488478
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 47 deletions.
15 changes: 1 addition & 14 deletions packages/logs/src/boot/logs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,5 @@ interface Rum {

function getRUMInternalContext(startTime?: number): Context | undefined {
const rum = (window as any).DD_RUM as Rum
const context = rum && rum.getInternalContext ? rum.getInternalContext(startTime) : undefined
if (!context || !context.session) {
return context
}
// TODO settle on integration strategy
// tslint:disable:no-unsafe-any
const v2context = context as any
v2context.session_id = v2context.session.id
v2context.application_id = v2context.application.id
if (v2context.action) {
v2context.user_action = { id: v2context.action.id }
}
// tslint:enable:no-unsafe-any
return v2context as Context
return rum && rum.getInternalContext ? rum.getInternalContext(startTime) : undefined
}
10 changes: 3 additions & 7 deletions packages/rum/src/domain/internalContext.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,15 +114,11 @@ describe('internal context v2', () => {
setupBuilder.build()

expect(internalContext.get()).toEqual({
action: {
application_id: 'appId',
session_id: '1234',
user_action: {
id: '7890',
},
application: {
id: 'appId',
},
session: {
id: '1234',
},
view: {
id: 'abcde',
referrer: 'referrer',
Expand Down
18 changes: 9 additions & 9 deletions packages/rum/src/domain/internalContext.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import { combine, Configuration, withSnakeCaseKeys } from '@datadog/browser-core'
import { InternalContext } from '../types'
import { InternalContextV2 } from '../typesV2'
import { ParentContexts } from './parentContexts'
import { RumSession } from './rumSession'

/**
* Internal context keep returning v1 format
* to not break compatibility with logs data format
*/
export function startInternalContext(
applicationId: string,
session: RumSession,
Expand All @@ -15,17 +18,14 @@ export function startInternalContext(
if (configuration.isEnabled('v2_format')) {
const viewContext = parentContexts.findViewV2(startTime)
if (session.isTracked() && viewContext && viewContext.session.id) {
const actionContext = parentContexts.findActionV2(startTime)
return (withSnakeCaseKeys(
combine(
{
application: {
id: applicationId,
},
},
viewContext,
parentContexts.findActionV2(startTime)
{ applicationId },
{ sessionId: viewContext.session.id, view: viewContext.view },
actionContext ? { userAction: { id: actionContext.action.id } } : undefined
)
) as unknown) as InternalContextV2
) as unknown) as InternalContext
}
} else {
const viewContext = parentContexts.findView(startTime)
Expand Down
17 changes: 0 additions & 17 deletions packages/rum/src/typesV2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,20 +145,3 @@ export type RumEventV2 =
| RumViewEventV2 & ViewContextV2 & RumContextV2
| RumLongTaskEventV2 & ActionContextV2 & ViewContextV2 & RumContextV2
| RumActionEventV2 & ViewContextV2 & RumContextV2

export interface InternalContextV2 {
application: {
id: string
}
session: {
id: string | undefined
}
view?: {
id: string
url: string
referrer: string
}
action?: {
id: string
}
}

0 comments on commit 8488478

Please sign in to comment.