Skip to content

Commit fae739a

Browse files
authored
fix: Preserve agent attributes for log payloads (#1594)
1 parent 6ccc3cd commit fae739a

File tree

2 files changed

+78
-3
lines changed

2 files changed

+78
-3
lines changed

src/features/logging/aggregate/index.js

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ export class Aggregate extends AggregateBase {
110110
common: {
111111
/** Attributes in the `common` section are added to `all` logs generated in the payload */
112112
attributes: {
113+
...this.agentRef.info.jsAttributes, // user-provided custom attributes
113114
'entity.guid': target.entityGuid, // browser entity guid as provided API target OR the default from RUM response if not supplied
114115
...(sessionEntity && {
115116
session: sessionEntity.state.value || '0', // The session ID that we generate and keep across page loads
@@ -123,9 +124,7 @@ export class Aggregate extends AggregateBase {
123124
// The following 3 attributes are evaluated and dropped at ingest processing time and do not get stored on NRDB:
124125
'instrumentation.provider': 'browser',
125126
'instrumentation.version': this.agentRef.runtime.version,
126-
'instrumentation.name': this.agentRef.runtime.loaderType,
127-
// Custom attributes
128-
...this.agentRef.info.jsAttributes
127+
'instrumentation.name': this.agentRef.runtime.loaderType
129128
}
130129
},
131130
/** logs section contains individual unique log entries */
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
import { Aggregate } from '../../../../src/features/logging/aggregate'
2+
import { LOGGING_MODE } from '../../../../src/features/logging/constants'
3+
4+
describe('Logging aggregate', () => {
5+
test('serializer should not overwrite agent reserved attributes with user-provided attributes', () => {
6+
const agentInst = {
7+
agentIdentifier: 'abcd',
8+
info: {
9+
licenseKey: 'licenseKey',
10+
applicationID: '123',
11+
errorBeacon: 'someValue',
12+
jsAttributes: {
13+
agentVersion: 'foobar',
14+
appId: 'foobar',
15+
'entity.guid': 'foobar',
16+
'instrumentation.provider': 'foobar',
17+
'instrumentation.version': 'foobar',
18+
'instrumentation.name': 'foobar',
19+
ptid: 'foobar',
20+
session: 'foobar',
21+
hasReplay: 'foobar',
22+
hasTrace: 'foobar',
23+
standalone: 'foobar',
24+
customAttr: 'customVal'
25+
}
26+
},
27+
init: {
28+
privacy: {
29+
cookies_enabled: true
30+
}
31+
},
32+
runtime: {
33+
version: '1.0.0',
34+
loaderType: 'loaderTypeX',
35+
ptid: 'ptid123',
36+
session: {
37+
state: {
38+
value: '12345',
39+
loggingMode: LOGGING_MODE.INFO,
40+
sessionReplayMode: 1,
41+
sessionTraceMode: 1
42+
}
43+
}
44+
}
45+
}
46+
47+
const logAgg = new Aggregate(agentInst)
48+
const actual = logAgg.serializer([
49+
{
50+
timestamp: 1234,
51+
message: 'test message',
52+
level: 'INFO',
53+
attributes: {
54+
pageUrl: 'http://example.com'
55+
}
56+
}
57+
])
58+
59+
expect(actual[0].common).toEqual({
60+
attributes: {
61+
agentVersion: '1.0.0',
62+
appId: '123',
63+
'entity.guid': undefined,
64+
hasReplay: true,
65+
hasTrace: true,
66+
'instrumentation.name': 'loaderTypeX',
67+
'instrumentation.provider': 'browser',
68+
'instrumentation.version': '1.0.0',
69+
ptid: 'ptid123',
70+
session: '12345',
71+
standalone: false,
72+
customAttr: 'customVal'
73+
}
74+
})
75+
})
76+
})

0 commit comments

Comments
 (0)