|
| 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