Skip to content

Commit

Permalink
🐛 move document_version to global context
Browse files Browse the repository at this point in the history
It turns out that the View `_dd.document_version` is replaced by another
unrelated version in the backend. I wanted to duplicate this field so we
can keep the original in views.

Because unknown `_dd` fields are discarded from View events by the
backend, I chose to put it in the global context, similarly to #1757
(and other before).
  • Loading branch information
BenoitZugmeyer committed Dec 21, 2022
1 parent 965a30f commit 56435da
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 11 deletions.
23 changes: 18 additions & 5 deletions packages/rum-core/src/domain/assembly.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import type { RelativeTime } from '@datadog/browser-core'
import { ErrorSource, ONE_MINUTE, display } from '@datadog/browser-core'
import {
updateExperimentalFeatures,
resetExperimentalFeatures,
ErrorSource,
ONE_MINUTE,
display,
} from '@datadog/browser-core'
import { createRumSessionManagerMock } from '../../test/mockRumSessionManager'
import { createRawRumEvent } from '../../test/fixtures'
import type { TestSetupBuilder } from '../../test/specHelper'
Expand Down Expand Up @@ -442,6 +448,10 @@ describe('rum assembly', () => {
})

describe('view context', () => {
afterEach(() => {
resetExperimentalFeatures()
})

it('should be merged with event attributes', () => {
const { lifeCycle } = setupBuilder.build()
notifyRawRumEvent(lifeCycle, {
Expand All @@ -455,15 +465,18 @@ describe('rum assembly', () => {
)
})

it('should include the view document version in non-view events', () => {
it('should include the view document version in global context', () => {
updateExperimentalFeatures(['report_view_document_version'])
const { lifeCycle } = setupBuilder.build()
notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.RESOURCE),
})
expect(serverRumEvents[0]._dd).toEqual(
expect(serverRumEvents[0].context).toEqual(
jasmine.objectContaining({
view: {
document_version: 42,
_dd: {
view: {
document_version: 42,
},
},
})
)
Expand Down
15 changes: 9 additions & 6 deletions packages/rum-core/src/domain/assembly.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { Context, RawError, EventRateLimiter, User } from '@datadog/browser-core'
import {
isExperimentalFeatureEnabled,
combine,
isEmptyObject,
limitModification,
Expand Down Expand Up @@ -104,12 +105,6 @@ export function startRumAssembly(
session: {
plan: session.plan,
},
view:
rawRumEvent.type === RumEventType.VIEW
? undefined
: {
document_version: viewContext.documentVersion,
},
browser_sdk_version: canUseEventBridge() ? __BUILD_ENV__SDK_VERSION__ : undefined,
},
application: {
Expand Down Expand Up @@ -146,6 +141,14 @@ export function startRumAssembly(
;(serverRumEvent.usr as Mutable<RumEvent['usr']>) = commonContext.user as User & Context
}

if (isExperimentalFeatureEnabled('report_view_document_version')) {
serverRumEvent.context._dd = {
view: {
document_version: viewContext.documentVersion,
},
}
}

if (shouldSend(serverRumEvent, configuration.beforeSend, domainContext, eventRateLimiters)) {
if (isEmptyObject(serverRumEvent.context)) {
delete serverRumEvent.context
Expand Down

0 comments on commit 56435da

Please sign in to comment.