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-758] keep internal context in v1 format (experimental) #625

Merged
merged 1 commit into from
Nov 20, 2020
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
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
}
}