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

✨⚗ [RUM-2682] writable resource.graphql field on Resource events #2550

Merged
merged 1 commit into from
Jan 4, 2024
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
1 change: 1 addition & 0 deletions packages/core/src/tools/experimentalFeatures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export enum ExperimentalFeature {
COLLECT_FLUSH_REASON = 'collect_flush_reason',
ZERO_LCP_TELEMETRY = 'zero_lcp_telemetry',
DISABLE_REPLAY_INLINE_CSS = 'disable_replay_inline_css',
WRITABLE_RESOURCE_GRAPHQL = 'writable_resource_graphql',
}

const enabledExperimentalFeatures: Set<ExperimentalFeature> = new Set()
Expand Down
11 changes: 11 additions & 0 deletions packages/core/test/emulate/mockExperimentalFeatures.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import {
resetExperimentalFeatures,
type ExperimentalFeature,
addExperimentalFeatures,
} from '../../src/tools/experimentalFeatures'
import { registerCleanupTask } from '../registerCleanupTask'

export function mockExperimentalFeatures(enabledFeatures: ExperimentalFeature[]) {
addExperimentalFeatures(enabledFeatures)
registerCleanupTask(resetExperimentalFeatures)
}
1 change: 1 addition & 0 deletions packages/core/test/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ export * from './emulate/eventBridge'
export * from './emulate/eventBridge'
export * from './emulate/stubStorages'
export * from './emulate/mockFlushController'
export * from './emulate/mockExperimentalFeatures'
37 changes: 35 additions & 2 deletions packages/rum-core/src/domain/assembly.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import type { ClocksState, RelativeTime } from '@datadog/browser-core'
import { ErrorSource, ONE_MINUTE, display } from '@datadog/browser-core'
import { ErrorSource, ExperimentalFeature, ONE_MINUTE, display } from '@datadog/browser-core'
import {
initEventBridgeStub,
deleteEventBridgeStub,
cleanupSyntheticsWorkerValues,
mockSyntheticsWorkerValues,
mockExperimentalFeatures,
} from '@datadog/browser-core/test'
import type { TestSetupBuilder } from '../../test'
import {
Expand All @@ -17,7 +18,7 @@ import {
import type { RumEventDomainContext } from '../domainContext.types'
import type { RawRumActionEvent, RawRumErrorEvent, RawRumEvent } from '../rawRumEvent.types'
import { RumEventType } from '../rawRumEvent.types'
import type { RumActionEvent, RumErrorEvent, RumEvent } from '../rumEvent.types'
import type { RumActionEvent, RumErrorEvent, RumEvent, RumResourceEvent } from '../rumEvent.types'
import { startRumAssembly } from './assembly'
import type { LifeCycle, RawRumEventCollectedData } from './lifeCycle'
import { LifeCycleEventType } from './lifeCycle'
Expand Down Expand Up @@ -109,6 +110,38 @@ describe('rum assembly', () => {

expect(serverRumEvents[0].view.name).toBe('added')
})

describe('field resource.graphql on Resource events', () => {
it('by default, it should not be modifiable', () => {
const { lifeCycle } = setupBuilder
.withConfiguration({
beforeSend: (event) => (event.resource!.graphql = { operationType: 'query' }),
})
.build()

notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.RESOURCE, { resource: { url: '/path?foo=bar' } }),
})

expect((serverRumEvents[0] as RumResourceEvent).resource.graphql).toBeUndefined()
})

it('with the writable_resource_graphql experimental flag is set, it should be modifiable', () => {
mockExperimentalFeatures([ExperimentalFeature.WRITABLE_RESOURCE_GRAPHQL])

const { lifeCycle } = setupBuilder
.withConfiguration({
beforeSend: (event) => (event.resource!.graphql = { operationType: 'query' }),
})
.build()

notifyRawRumEvent(lifeCycle, {
rawRumEvent: createRawRumEvent(RumEventType.RESOURCE, { resource: { url: '/path?foo=bar' } }),
})

expect((serverRumEvents[0] as RumResourceEvent).resource.graphql).toEqual({ operationType: 'query' })
})
})
})

describe('context field', () => {
Expand Down
5 changes: 5 additions & 0 deletions packages/rum-core/src/domain/assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import {
canUseEventBridge,
assign,
round,
isExperimentalFeatureEnabled,
ExperimentalFeature,
} from '@datadog/browser-core'
import type { RumEventDomainContext } from '../domainContext.types'
import type {
Expand Down Expand Up @@ -84,6 +86,9 @@ export function startRumAssembly(
{
'resource.url': 'string',
},
isExperimentalFeatureEnabled(ExperimentalFeature.WRITABLE_RESOURCE_GRAPHQL) && {
'resource.graphql': 'object',
},
USER_CUSTOMIZABLE_FIELD_PATHS,
VIEW_MODIFIABLE_FIELD_PATHS
),
Expand Down