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-3965] make service and version fields modifiable #2788

Merged
merged 6 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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/utils/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ interface Assignable {
export function assign<T, U>(target: T, source: U): T & U
export function assign<T, U, V>(target: T, source1: U, source2: V): T & U & V
export function assign<T, U, V, W>(target: T, source1: U, source2: V, source3: W): T & U & V & W
export function assign<T, U, V, W, X>(target: T, source1: U, source2: V, source3: W, source4: X): T & U & V & W & X
export function assign(target: Assignable, ...toAssign: Assignable[]) {
toAssign.forEach((source: Assignable) => {
for (const key in source) {
Expand Down
27 changes: 21 additions & 6 deletions packages/rum-core/src/domain/assembly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,16 @@ export function startRumAssembly(
getCommonContext: () => CommonContext,
reportError: (error: RawError) => void
) {
// TODO: lift this declaration to module level once feature flag is removed
const ROOT_MODIFIABLE_FIELD_PATHS: ModifiableFieldPaths = isExperimentalFeatureEnabled(
ExperimentalFeature.MICRO_FRONTEND
)
? {
service: 'string',
version: 'string',
}
: {}

modifiableFieldPathsByEvent = {
[RumEventType.VIEW]: VIEW_MODIFIABLE_FIELD_PATHS,
[RumEventType.ERROR]: assign(
Expand All @@ -82,24 +92,29 @@ export function startRumAssembly(
'error.fingerprint': 'string',
},
USER_CUSTOMIZABLE_FIELD_PATHS,
VIEW_MODIFIABLE_FIELD_PATHS
VIEW_MODIFIABLE_FIELD_PATHS,
ROOT_MODIFIABLE_FIELD_PATHS
),
[RumEventType.RESOURCE]: assign(
{
'resource.url': 'string',
},
isExperimentalFeatureEnabled(ExperimentalFeature.WRITABLE_RESOURCE_GRAPHQL) && {
'resource.graphql': 'object',
},
isExperimentalFeatureEnabled(ExperimentalFeature.WRITABLE_RESOURCE_GRAPHQL)
? {
'resource.graphql': 'object',
}
: {},
USER_CUSTOMIZABLE_FIELD_PATHS,
VIEW_MODIFIABLE_FIELD_PATHS
VIEW_MODIFIABLE_FIELD_PATHS,
ROOT_MODIFIABLE_FIELD_PATHS
),
[RumEventType.ACTION]: assign(
{
'action.target.name': 'string',
},
USER_CUSTOMIZABLE_FIELD_PATHS,
VIEW_MODIFIABLE_FIELD_PATHS
VIEW_MODIFIABLE_FIELD_PATHS,
ROOT_MODIFIABLE_FIELD_PATHS
),
[RumEventType.LONG_TASK]: assign({}, USER_CUSTOMIZABLE_FIELD_PATHS, VIEW_MODIFIABLE_FIELD_PATHS),
[RumEventType.VITAL]: assign({}, USER_CUSTOMIZABLE_FIELD_PATHS, VIEW_MODIFIABLE_FIELD_PATHS),
Expand Down
4 changes: 2 additions & 2 deletions packages/rum-core/src/rumEvent.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1116,11 +1116,11 @@ export interface CommonProperties {
/**
* The service name for this application
*/
readonly service?: string
service?: string
/**
* The version for this application
*/
readonly version?: string
version?: string
/**
* The build version for this application
*/
Expand Down
32 changes: 32 additions & 0 deletions test/e2e/scenario/microfrontend.scenario.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import { flushEvents, createTest } from '../lib/framework'
const HANDLING_STACK_REGEX = /^Error: \n\s+at testHandlingStack @/

const CONFIG: Partial<RumInitConfiguration> = {
service: 'main-service',
version: '1.0.0',
enableExperimentalFeatures: ['micro_frontend'],
beforeSend: (event: RumEvent, domainContext: RumEventDomainContext) => {
if ('handlingStack' in domainContext) {
Expand Down Expand Up @@ -123,4 +125,34 @@ describe('microfrontend', () => {
expect(event).toBeTruthy()
expect(event?.context?.handlingStack).toMatch(HANDLING_STACK_REGEX)
})

createTest('allow to modify service and version')
.withRum(CONFIG)
.withRumInit((configuration) => {
window.DD_RUM!.init({
...configuration,
beforeSend: (event: RumEvent) => {
if (event.type === 'resource') {
event.service = 'mf-service'
event.version = '0.1.0'
}

return true
},
})
})
.run(async ({ intakeRegistry }) => {
await flushEvents()

const viewEvent = intakeRegistry.rumViewEvents[0]
const resourceEvent = intakeRegistry.rumResourceEvents[0]

expect(viewEvent).toBeTruthy()
expect(viewEvent.service).toBe('main-service')
expect(viewEvent.version).toBe('1.0.0')

expect(resourceEvent).toBeTruthy()
expect(resourceEvent.service).toBe('mf-service')
expect(resourceEvent.version).toBe('0.1.0')
})
})