Skip to content

Commit 77f4a4d

Browse files
♻️ refactor modifiable field paths in rum assembly
move shared beforeSend modifiable paths into a common constant and define event-specific paths in a single static map. this removes duplicated per-event setup in startRumAssembly and keeps the allowed field list easier to maintain without changing behavior.
1 parent 4839750 commit 77f4a4d

1 file changed

Lines changed: 33 additions & 58 deletions

File tree

packages/rum-core/src/domain/assembly.ts

Lines changed: 33 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,46 @@ import type { ModifiableFieldPaths } from './limitModification'
1818
import { limitModification } from './limitModification'
1919
import type { Hooks, AssembleHookParams } from './hooks'
2020

21-
const VIEW_MODIFIABLE_FIELD_PATHS: ModifiableFieldPaths = {
21+
const COMMON_MODIFIABLE_FIELD_PATHS: ModifiableFieldPaths = {
2222
'view.name': 'string',
2323
'view.url': 'string',
2424
'view.referrer': 'string',
25-
}
26-
27-
const USER_CUSTOMIZABLE_FIELD_PATHS: ModifiableFieldPaths = {
2825
context: 'object',
29-
}
30-
31-
const ROOT_MODIFIABLE_FIELD_PATHS: ModifiableFieldPaths = {
3226
service: 'string',
3327
version: 'string',
3428
}
3529

36-
let modifiableFieldPathsByEvent: { [key in RumEventType]: ModifiableFieldPaths }
30+
const MODIFIABLE_FIELD_PATHS_BY_EVENT: Record<AssembledRumEvent['type'], ModifiableFieldPaths> = {
31+
[RumEventType.VIEW]: {
32+
...COMMON_MODIFIABLE_FIELD_PATHS,
33+
'view.performance.lcp.resource_url': 'string',
34+
},
35+
[RumEventType.ERROR]: {
36+
...COMMON_MODIFIABLE_FIELD_PATHS,
37+
'error.message': 'string',
38+
'error.stack': 'string',
39+
'error.handling_stack': 'string',
40+
'error.resource.url': 'string',
41+
'error.fingerprint': 'string',
42+
},
43+
[RumEventType.RESOURCE]: {
44+
...COMMON_MODIFIABLE_FIELD_PATHS,
45+
'resource.url': 'string',
46+
'resource.graphql.variables': 'string',
47+
'resource.request.headers': 'object',
48+
'resource.response.headers': 'object',
49+
},
50+
[RumEventType.ACTION]: {
51+
...COMMON_MODIFIABLE_FIELD_PATHS,
52+
'action.target.name': 'string',
53+
},
54+
[RumEventType.LONG_TASK]: {
55+
...COMMON_MODIFIABLE_FIELD_PATHS,
56+
'long_task.scripts[].source_url': 'string',
57+
'long_task.scripts[].invoker': 'string',
58+
},
59+
[RumEventType.VITAL]: COMMON_MODIFIABLE_FIELD_PATHS,
60+
}
3761

3862
export function startRumAssembly(
3963
configuration: RumConfiguration,
@@ -42,55 +66,6 @@ export function startRumAssembly(
4266
reportError: (error: RawError) => void,
4367
eventRateLimit?: number
4468
) {
45-
modifiableFieldPathsByEvent = {
46-
[RumEventType.VIEW]: {
47-
'view.performance.lcp.resource_url': 'string',
48-
...USER_CUSTOMIZABLE_FIELD_PATHS,
49-
...VIEW_MODIFIABLE_FIELD_PATHS,
50-
...ROOT_MODIFIABLE_FIELD_PATHS,
51-
},
52-
// view_update events are created post-assembly in startRumBatch.ts and never reach this pipeline.
53-
// The full view already went through assembly (as RumEventType.VIEW), so any beforeSend
54-
// modifications (e.g. PII scrubbing) are already reflected in the view_update diff.
55-
[RumEventType.VIEW_UPDATE]: {},
56-
[RumEventType.ERROR]: {
57-
'error.message': 'string',
58-
'error.stack': 'string',
59-
'error.handling_stack': 'string',
60-
'error.resource.url': 'string',
61-
'error.fingerprint': 'string',
62-
...USER_CUSTOMIZABLE_FIELD_PATHS,
63-
...VIEW_MODIFIABLE_FIELD_PATHS,
64-
...ROOT_MODIFIABLE_FIELD_PATHS,
65-
},
66-
[RumEventType.RESOURCE]: {
67-
'resource.url': 'string',
68-
'resource.graphql.variables': 'string',
69-
'resource.request.headers': 'object',
70-
'resource.response.headers': 'object',
71-
...USER_CUSTOMIZABLE_FIELD_PATHS,
72-
...VIEW_MODIFIABLE_FIELD_PATHS,
73-
...ROOT_MODIFIABLE_FIELD_PATHS,
74-
},
75-
[RumEventType.ACTION]: {
76-
'action.target.name': 'string',
77-
...USER_CUSTOMIZABLE_FIELD_PATHS,
78-
...VIEW_MODIFIABLE_FIELD_PATHS,
79-
...ROOT_MODIFIABLE_FIELD_PATHS,
80-
},
81-
[RumEventType.LONG_TASK]: {
82-
'long_task.scripts[].source_url': 'string',
83-
'long_task.scripts[].invoker': 'string',
84-
...USER_CUSTOMIZABLE_FIELD_PATHS,
85-
...VIEW_MODIFIABLE_FIELD_PATHS,
86-
...ROOT_MODIFIABLE_FIELD_PATHS,
87-
},
88-
[RumEventType.VITAL]: {
89-
...USER_CUSTOMIZABLE_FIELD_PATHS,
90-
...VIEW_MODIFIABLE_FIELD_PATHS,
91-
...ROOT_MODIFIABLE_FIELD_PATHS,
92-
},
93-
}
9469
const eventRateLimiters = {
9570
[RumEventType.ERROR]: createEventRateLimiter(RumEventType.ERROR, reportError, eventRateLimit),
9671
[RumEventType.ACTION]: createEventRateLimiter(RumEventType.ACTION, reportError, eventRateLimit),
@@ -133,7 +108,7 @@ function shouldSend(
133108
eventRateLimiters: { [key in RumEventType]?: EventRateLimiter }
134109
) {
135110
if (beforeSend) {
136-
const result = limitModification(event, modifiableFieldPathsByEvent[event.type], (event) =>
111+
const result = limitModification(event, MODIFIABLE_FIELD_PATHS_BY_EVENT[event.type], (event) =>
137112
beforeSend(event, domainContext)
138113
)
139114
if (result === false && event.type !== RumEventType.VIEW) {

0 commit comments

Comments
 (0)