@newrelic/browser-agent 1.241.0 → 1.243.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +1465 -0
- package/dist/cjs/cdn/polyfills/lite.js +13 -1
- package/dist/cjs/cdn/polyfills/pro.js +17 -1
- package/dist/cjs/cdn/polyfills/spa.js +18 -1
- package/dist/cjs/common/config/state/init.js +32 -5
- package/dist/cjs/common/constants/env.cdn.js +1 -1
- package/dist/cjs/common/constants/env.npm.js +1 -1
- package/dist/cjs/common/dom/query-selector.js +16 -0
- package/dist/cjs/common/session/session-entity.js +20 -2
- package/dist/cjs/common/wrap/wrap-function.js +1 -1
- package/dist/cjs/features/ajax/aggregate/index.js +1 -1
- package/dist/cjs/features/session_replay/aggregate/index.js +84 -50
- package/dist/cjs/features/utils/feature-base.js +1 -2
- package/dist/cjs/features/utils/instrument-base.js +1 -0
- package/dist/cjs/loaders/api/api.js +2 -2
- package/dist/cjs/loaders/api/apiAsync.js +0 -37
- package/dist/cjs/loaders/configure/configure.js +1 -1
- package/dist/cjs/loaders/configure/public-path.js +6 -3
- package/dist/esm/cdn/polyfills/lite.js +8 -1
- package/dist/esm/cdn/polyfills/pro.js +13 -2
- package/dist/esm/cdn/polyfills/spa.js +13 -1
- package/dist/esm/common/config/state/init.js +32 -5
- package/dist/esm/common/constants/env.cdn.js +1 -1
- package/dist/esm/common/constants/env.npm.js +1 -1
- package/dist/esm/common/dom/query-selector.js +9 -0
- package/dist/esm/common/session/session-entity.js +18 -1
- package/dist/esm/common/wrap/wrap-function.js +1 -1
- package/dist/esm/features/ajax/aggregate/index.js +1 -1
- package/dist/esm/features/session_replay/aggregate/index.js +83 -50
- package/dist/esm/features/utils/feature-base.js +1 -2
- package/dist/esm/features/utils/instrument-base.js +1 -0
- package/dist/esm/loaders/api/api.js +2 -2
- package/dist/esm/loaders/api/apiAsync.js +1 -36
- package/dist/esm/loaders/configure/configure.js +1 -1
- package/dist/esm/loaders/configure/public-path.js +6 -3
- package/dist/types/common/config/state/init.d.ts.map +1 -1
- package/dist/types/common/dom/query-selector.d.ts +2 -0
- package/dist/types/common/dom/query-selector.d.ts.map +1 -0
- package/dist/types/common/session/session-entity.d.ts +5 -0
- package/dist/types/common/session/session-entity.d.ts.map +1 -1
- package/dist/types/features/session_replay/aggregate/index.d.ts +11 -14
- package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/utils/feature-base.d.ts.map +1 -1
- package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
- package/dist/types/loaders/api/api.d.ts.map +1 -1
- package/dist/types/loaders/api/apiAsync.d.ts.map +1 -1
- package/dist/types/loaders/configure/public-path.d.ts +1 -1
- package/dist/types/loaders/configure/public-path.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/cdn/polyfills/lite.js +14 -1
- package/src/cdn/polyfills/pro.js +23 -2
- package/src/cdn/polyfills/spa.js +24 -1
- package/src/common/config/state/init.js +33 -4
- package/src/common/dom/query-selector.js +9 -0
- package/src/common/session/session-entity.js +20 -1
- package/src/common/wrap/wrap-function.js +1 -1
- package/src/features/ajax/aggregate/index.js +2 -2
- package/src/features/session_replay/aggregate/index.js +82 -34
- package/src/features/utils/feature-base.js +1 -2
- package/src/features/utils/instrument-base.js +1 -0
- package/src/loaders/api/api.js +1 -2
- package/src/loaders/api/apiAsync.js +1 -39
- package/src/loaders/configure/configure.js +1 -1
- package/src/loaders/configure/public-path.js +6 -3
- package/src/common/aggregate/aggregator.test.js +0 -107
- package/src/common/config/state/configurable.test.js +0 -73
- package/src/common/config/state/info.test.js +0 -31
- package/src/common/config/state/init.test.js +0 -28
- package/src/common/config/state/loader-config.test.js +0 -21
- package/src/common/config/state/runtime.test.js +0 -21
- package/src/common/constants/env.cdn.test.js +0 -7
- package/src/common/constants/env.npm.test.js +0 -7
- package/src/common/constants/env.test.js +0 -7
- package/src/common/constants/runtime.test.js +0 -176
- package/src/common/deny-list/deny-list.test.js +0 -104
- package/src/common/drain/drain.test.js +0 -74
- package/src/common/event-emitter/contextual-ee.component-test.js +0 -293
- package/src/common/event-emitter/handle.test.js +0 -56
- package/src/common/event-emitter/register-handler.test.js +0 -61
- package/src/common/harvest/harvest-scheduler.test.js +0 -492
- package/src/common/harvest/harvest.test.js +0 -813
- package/src/common/ids/id.test.js +0 -92
- package/src/common/ids/unique-id.test.js +0 -58
- package/src/common/session/session-entity.component-test.js +0 -346
- package/src/common/storage/local-storage.test.js +0 -17
- package/src/common/timer/interaction-timer.component-test.js +0 -212
- package/src/common/timer/timer.test.js +0 -99
- package/src/common/timing/nav-timing.test.js +0 -161
- package/src/common/url/canonicalize-url.test.js +0 -45
- package/src/common/url/clean-url.test.js +0 -25
- package/src/common/url/encode.test.js +0 -81
- package/src/common/url/location.test.js +0 -15
- package/src/common/url/parse-url.test.js +0 -110
- package/src/common/url/protocol.test.js +0 -17
- package/src/common/util/console.test.js +0 -34
- package/src/common/util/data-size.test.js +0 -56
- package/src/common/util/feature-flags.test.js +0 -94
- package/src/common/util/get-or-set.test.js +0 -58
- package/src/common/util/invoke.test.js +0 -65
- package/src/common/util/map-own.test.js +0 -52
- package/src/common/util/obfuscate.component-test.js +0 -173
- package/src/common/util/stringify.test.js +0 -49
- package/src/common/util/submit-data.test.js +0 -183
- package/src/common/util/traverse.test.js +0 -50
- package/src/common/vitals/cumulative-layout-shift.test.js +0 -71
- package/src/common/vitals/first-contentful-paint.test.js +0 -124
- package/src/common/vitals/first-input-delay.test.js +0 -88
- package/src/common/vitals/first-paint.test.js +0 -127
- package/src/common/vitals/interaction-to-next-paint.test.js +0 -74
- package/src/common/vitals/largest-contentful-paint.test.js +0 -94
- package/src/common/vitals/long-task.test.js +0 -122
- package/src/common/vitals/time-to-first-byte.test.js +0 -147
- package/src/common/vitals/vital-metric.test.js +0 -171
- package/src/common/wrap/wrap-promise.component-test.js +0 -110
- package/src/features/ajax/instrument/distributed-tracing.test.js +0 -375
- package/src/features/jserrors/aggregate/canonical-function-name.test.js +0 -13
- package/src/features/jserrors/aggregate/compute-stack-trace.test.js +0 -414
- package/src/features/jserrors/aggregate/format-stack-trace.test.js +0 -39
- package/src/features/jserrors/aggregate/string-hash-code.test.js +0 -12
- package/src/features/metrics/aggregate/framework-detection.test.js +0 -332
- package/src/features/page_view_timing/aggregate/index.component-test.js +0 -86
- package/src/features/session_replay/aggregate/index.component-test.js +0 -317
- package/src/features/spa/aggregate/interaction-node.test.js +0 -17
- package/src/features/utils/agent-session.test.js +0 -194
- package/src/features/utils/aggregate-base.test.js +0 -123
- package/src/features/utils/feature-base.test.js +0 -45
- package/src/features/utils/handler-cache.test.js +0 -72
- package/src/features/utils/instrument-base.test.js +0 -216
- package/src/features/utils/lazy-feature-loader.test.js +0 -37
- package/src/loaders/api/api.component-test.js +0 -45
- package/src/loaders/api/api.test.js +0 -85
- package/src/loaders/api/apiAsync.test.js +0 -17
|
@@ -1,110 +0,0 @@
|
|
|
1
|
-
import { faker } from '@faker-js/faker'
|
|
2
|
-
import { globalScope } from '../constants/runtime'
|
|
3
|
-
|
|
4
|
-
let promiseConstructorCalls
|
|
5
|
-
|
|
6
|
-
beforeEach(async () => {
|
|
7
|
-
promiseConstructorCalls = []
|
|
8
|
-
|
|
9
|
-
// Proxy the global Promise to prevent the wrapping from
|
|
10
|
-
// messing with Jest internal promises
|
|
11
|
-
window.Promise = new Proxy(class extends Promise {}, {
|
|
12
|
-
construct (target, args) {
|
|
13
|
-
promiseConstructorCalls.push(args)
|
|
14
|
-
|
|
15
|
-
return Reflect.construct(target, args)
|
|
16
|
-
}
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
;(await import('./wrap-promise')).wrapPromise()
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
afterEach(() => {
|
|
23
|
-
jest.resetModules()
|
|
24
|
-
})
|
|
25
|
-
|
|
26
|
-
test('should wrap promise constructor', async () => {
|
|
27
|
-
const promiseInstance = new globalScope.Promise(jest.fn())
|
|
28
|
-
|
|
29
|
-
expect(promiseInstance).toBeInstanceOf(Promise)
|
|
30
|
-
expect(promiseConstructorCalls.length).toBeGreaterThan(0)
|
|
31
|
-
expect(globalScope.Promise.toString()).toMatch(/\[native code\]/)
|
|
32
|
-
expect(globalScope.Promise.name).toEqual('Promise')
|
|
33
|
-
})
|
|
34
|
-
|
|
35
|
-
describe('all', () => {
|
|
36
|
-
test('should work with acceptable iterables', async () => {
|
|
37
|
-
const resolveValue = faker.datatype.uuid()
|
|
38
|
-
const customIterable = new CustomIterable([
|
|
39
|
-
new globalScope.Promise(resolve => resolve(resolveValue))
|
|
40
|
-
])
|
|
41
|
-
const arrayIterable = [
|
|
42
|
-
new globalScope.Promise(resolve => resolve(resolveValue))
|
|
43
|
-
]
|
|
44
|
-
const setIterable = new Set()
|
|
45
|
-
setIterable.add(new globalScope.Promise(resolve => resolve(resolveValue)))
|
|
46
|
-
|
|
47
|
-
await expect(globalScope.Promise.all(customIterable)).resolves.toEqual([resolveValue])
|
|
48
|
-
await expect(globalScope.Promise.all(arrayIterable)).resolves.toEqual([resolveValue])
|
|
49
|
-
await expect(globalScope.Promise.all(setIterable)).resolves.toEqual([resolveValue])
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
test.each([null, undefined])('should not try to iterate a non-iterable %s', async (input) => {
|
|
53
|
-
jest.spyOn(globalScope.Promise, 'resolve')
|
|
54
|
-
|
|
55
|
-
await expect(globalScope.Promise.all(input)).rejects.toThrow()
|
|
56
|
-
expect(globalScope.Promise.resolve).not.toHaveBeenCalled()
|
|
57
|
-
})
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
describe('race', () => {
|
|
61
|
-
test('should work with acceptable iterables', async () => {
|
|
62
|
-
jest.spyOn(globalScope.Promise, 'resolve')
|
|
63
|
-
|
|
64
|
-
const resolveValue = faker.datatype.uuid()
|
|
65
|
-
const customIterable = new CustomIterable([
|
|
66
|
-
new globalScope.Promise(resolve => resolve(resolveValue))
|
|
67
|
-
])
|
|
68
|
-
const arrayIterable = [
|
|
69
|
-
new globalScope.Promise(resolve => resolve(resolveValue))
|
|
70
|
-
]
|
|
71
|
-
const setIterable = new Set()
|
|
72
|
-
setIterable.add(new globalScope.Promise(resolve => resolve(resolveValue)))
|
|
73
|
-
|
|
74
|
-
await expect(globalScope.Promise.race(customIterable)).resolves.toEqual(resolveValue)
|
|
75
|
-
await expect(globalScope.Promise.race(arrayIterable)).resolves.toEqual(resolveValue)
|
|
76
|
-
await expect(globalScope.Promise.race(setIterable)).resolves.toEqual(resolveValue)
|
|
77
|
-
expect(globalScope.Promise.resolve).toHaveBeenCalled()
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
test.each([null, undefined])('should not try to iterate a non-iterable %s', async (input) => {
|
|
81
|
-
jest.spyOn(globalScope.Promise, 'resolve')
|
|
82
|
-
|
|
83
|
-
await expect(globalScope.Promise.race(input)).rejects.toThrow()
|
|
84
|
-
expect(globalScope.Promise.resolve).not.toHaveBeenCalled()
|
|
85
|
-
})
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
class CustomIterable {
|
|
89
|
-
#iterables = []
|
|
90
|
-
|
|
91
|
-
constructor (iterables) {
|
|
92
|
-
this.#iterables = iterables
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
[Symbol.iterator] () {
|
|
96
|
-
return {
|
|
97
|
-
index: 0,
|
|
98
|
-
iterables: this.#iterables,
|
|
99
|
-
next () {
|
|
100
|
-
return {
|
|
101
|
-
done: this.index >= this.iterables.length,
|
|
102
|
-
value: this.iterables[this.index++] || undefined
|
|
103
|
-
}
|
|
104
|
-
},
|
|
105
|
-
[Symbol.iterator] () {
|
|
106
|
-
return this
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
@@ -1,375 +0,0 @@
|
|
|
1
|
-
import { faker } from '@faker-js/faker'
|
|
2
|
-
import { DT } from './distributed-tracing'
|
|
3
|
-
import { getLoaderConfig, getConfiguration, getConfigurationValue } from '../../../common/config/config'
|
|
4
|
-
import * as runtimeModule from '../../../common/constants/runtime'
|
|
5
|
-
|
|
6
|
-
jest.enableAutomock()
|
|
7
|
-
jest.unmock('./distributed-tracing')
|
|
8
|
-
|
|
9
|
-
let agentIdentifier
|
|
10
|
-
let dtInstance
|
|
11
|
-
|
|
12
|
-
beforeEach(() => {
|
|
13
|
-
agentIdentifier = faker.datatype.uuid()
|
|
14
|
-
dtInstance = new DT(agentIdentifier)
|
|
15
|
-
|
|
16
|
-
jest.mocked(getLoaderConfig).mockReturnValue({
|
|
17
|
-
accountID: '1234',
|
|
18
|
-
agentID: '5678',
|
|
19
|
-
trustKey: '1'
|
|
20
|
-
})
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
afterEach(() => {
|
|
24
|
-
jest.clearAllMocks()
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
test('newrelic header has the correct format', () => {
|
|
28
|
-
const agentConfig = {
|
|
29
|
-
distributed_tracing: { enabled: true }
|
|
30
|
-
}
|
|
31
|
-
jest.mocked(getConfiguration).mockReturnValue(agentConfig)
|
|
32
|
-
jest.mocked(getConfigurationValue).mockReturnValue(agentConfig.distributed_tracing)
|
|
33
|
-
|
|
34
|
-
const payload = dtInstance.generateTracePayload({
|
|
35
|
-
sameOrigin: true
|
|
36
|
-
})
|
|
37
|
-
const header = JSON.parse(atob(payload.newrelicHeader))
|
|
38
|
-
|
|
39
|
-
expect(payload.spanId).toEqual(header.d.id)
|
|
40
|
-
expect(payload.traceId).toEqual(header.d.tr)
|
|
41
|
-
expect(payload.timestamp).toEqual(header.d.ti)
|
|
42
|
-
|
|
43
|
-
const loaderConfig = getLoaderConfig()
|
|
44
|
-
expect(header.d.ty).toEqual('Browser')
|
|
45
|
-
expect(header.d.ac).toEqual(loaderConfig.accountID)
|
|
46
|
-
expect(header.d.ap).toEqual(loaderConfig.agentID)
|
|
47
|
-
expect(header.d.tk).toEqual(loaderConfig.trustKey)
|
|
48
|
-
})
|
|
49
|
-
|
|
50
|
-
test('newrelic header is not generated for same-origin calls when disabled in configuration', () => {
|
|
51
|
-
const agentConfig = {
|
|
52
|
-
distributed_tracing: {
|
|
53
|
-
enabled: true,
|
|
54
|
-
exclude_newrelic_header: true
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
jest.mocked(getConfiguration).mockReturnValue(agentConfig)
|
|
58
|
-
jest.mocked(getConfigurationValue).mockReturnValue(agentConfig.distributed_tracing)
|
|
59
|
-
|
|
60
|
-
const payload = dtInstance.generateTracePayload({
|
|
61
|
-
sameOrigin: true
|
|
62
|
-
})
|
|
63
|
-
|
|
64
|
-
expect(payload.newrelicHeader).toBeUndefined()
|
|
65
|
-
expect(typeof payload.traceContextParentHeader).toEqual('string')
|
|
66
|
-
expect(typeof payload.traceContextStateHeader).toEqual('string')
|
|
67
|
-
})
|
|
68
|
-
|
|
69
|
-
test('newrelic header is added to cross-origin calls by default', () => {
|
|
70
|
-
const agentConfig = {
|
|
71
|
-
distributed_tracing: {
|
|
72
|
-
enabled: true,
|
|
73
|
-
allowed_origins: ['https://someotherdomain.com']
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
jest.mocked(getConfiguration).mockReturnValue(agentConfig)
|
|
77
|
-
jest.mocked(getConfigurationValue).mockReturnValue(agentConfig.distributed_tracing)
|
|
78
|
-
|
|
79
|
-
const payload = dtInstance.generateTracePayload({
|
|
80
|
-
sameOrigin: false,
|
|
81
|
-
hostname: 'someotherdomain.com',
|
|
82
|
-
protocol: 'https',
|
|
83
|
-
port: '443'
|
|
84
|
-
})
|
|
85
|
-
|
|
86
|
-
expect(payload.newrelicHeader).not.toBeUndefined()
|
|
87
|
-
})
|
|
88
|
-
|
|
89
|
-
test('newrelic header is added to cross-origin calls when enabled in configuration', () => {
|
|
90
|
-
const agentConfig = {
|
|
91
|
-
distributed_tracing: {
|
|
92
|
-
enabled: true,
|
|
93
|
-
allowed_origins: ['https://someotherdomain.com'],
|
|
94
|
-
cors_use_newrelic_header: true
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
jest.mocked(getConfiguration).mockReturnValue(agentConfig)
|
|
98
|
-
jest.mocked(getConfigurationValue).mockReturnValue(agentConfig.distributed_tracing)
|
|
99
|
-
|
|
100
|
-
const payload = dtInstance.generateTracePayload({
|
|
101
|
-
sameOrigin: false,
|
|
102
|
-
hostname: 'someotherdomain.com',
|
|
103
|
-
protocol: 'https',
|
|
104
|
-
port: '443'
|
|
105
|
-
})
|
|
106
|
-
|
|
107
|
-
expect(payload.newrelicHeader).not.toBeUndefined()
|
|
108
|
-
})
|
|
109
|
-
|
|
110
|
-
test('newrelic header is not added to cross-origin calls when disabled in configuration', () => {
|
|
111
|
-
const agentConfig = {
|
|
112
|
-
distributed_tracing: {
|
|
113
|
-
enabled: true,
|
|
114
|
-
allowed_origins: ['https://someotherdomain.com'],
|
|
115
|
-
cors_use_newrelic_header: false
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
jest.mocked(getConfiguration).mockReturnValue(agentConfig)
|
|
119
|
-
jest.mocked(getConfigurationValue).mockReturnValue(agentConfig.distributed_tracing)
|
|
120
|
-
|
|
121
|
-
const payload = dtInstance.generateTracePayload({
|
|
122
|
-
sameOrigin: false,
|
|
123
|
-
hostname: 'someotherdomain.com',
|
|
124
|
-
protocol: 'https',
|
|
125
|
-
port: '443'
|
|
126
|
-
})
|
|
127
|
-
|
|
128
|
-
expect(payload.newrelicHeader).toBeUndefined()
|
|
129
|
-
})
|
|
130
|
-
|
|
131
|
-
test('trace context headers are generated with the correct format', () => {
|
|
132
|
-
const agentConfig = {
|
|
133
|
-
distributed_tracing: {
|
|
134
|
-
enabled: true
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
jest.mocked(getConfiguration).mockReturnValue(agentConfig)
|
|
138
|
-
jest.mocked(getConfigurationValue).mockReturnValue(agentConfig.distributed_tracing)
|
|
139
|
-
|
|
140
|
-
const payload = dtInstance.generateTracePayload({
|
|
141
|
-
sameOrigin: true
|
|
142
|
-
})
|
|
143
|
-
const parentHeader = payload.traceContextParentHeader
|
|
144
|
-
const stateHeader = payload.traceContextStateHeader
|
|
145
|
-
|
|
146
|
-
const parentHeaderParts = parentHeader.split('-')
|
|
147
|
-
expect(parentHeaderParts[0]).toEqual('00')
|
|
148
|
-
expect(parentHeaderParts[1]).toEqual(payload.traceId)
|
|
149
|
-
expect(parentHeaderParts[2]).toEqual(payload.spanId)
|
|
150
|
-
expect(parentHeaderParts[3]).toEqual('01')
|
|
151
|
-
|
|
152
|
-
const loaderConfig = getLoaderConfig()
|
|
153
|
-
const stateHeaderKey = stateHeader.substring(0, stateHeader.indexOf('='))
|
|
154
|
-
expect(stateHeaderKey).toEqual(`${loaderConfig.trustKey}@nr`)
|
|
155
|
-
|
|
156
|
-
const stateHeaderParts = stateHeader.substring(stateHeader.indexOf('=') + 1).split('-')
|
|
157
|
-
expect(stateHeaderParts[0]).toEqual('0')
|
|
158
|
-
expect(stateHeaderParts[1]).toEqual('1')
|
|
159
|
-
expect(stateHeaderParts[2]).toEqual(loaderConfig.accountID)
|
|
160
|
-
expect(stateHeaderParts[3]).toEqual(loaderConfig.agentID)
|
|
161
|
-
expect(stateHeaderParts[4]).toEqual(payload.spanId)
|
|
162
|
-
expect(stateHeaderParts[5]).toEqual('')
|
|
163
|
-
expect(stateHeaderParts[6]).toEqual('')
|
|
164
|
-
expect(stateHeaderParts[7]).toEqual('')
|
|
165
|
-
expect(stateHeaderParts[8]).toEqual(payload.timestamp.toString())
|
|
166
|
-
})
|
|
167
|
-
|
|
168
|
-
test('trace context headers are not added to cross-origin calls by default', () => {
|
|
169
|
-
const agentConfig = {
|
|
170
|
-
distributed_tracing: {
|
|
171
|
-
enabled: true,
|
|
172
|
-
allowed_origins: ['https://someotherdomain.com']
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
jest.mocked(getConfiguration).mockReturnValue(agentConfig)
|
|
176
|
-
jest.mocked(getConfigurationValue).mockReturnValue(agentConfig.distributed_tracing)
|
|
177
|
-
|
|
178
|
-
const payload = dtInstance.generateTracePayload({
|
|
179
|
-
sameOrigin: false,
|
|
180
|
-
hostname: 'someotherdomain.com',
|
|
181
|
-
protocol: 'https',
|
|
182
|
-
port: '443'
|
|
183
|
-
})
|
|
184
|
-
|
|
185
|
-
expect(payload.traceContextParentHeader).toBeUndefined()
|
|
186
|
-
expect(payload.traceContextStateHeader).toBeUndefined()
|
|
187
|
-
})
|
|
188
|
-
|
|
189
|
-
test('trace context headers are added to cross-origin calls when enabled in configuration', () => {
|
|
190
|
-
const agentConfig = {
|
|
191
|
-
distributed_tracing: {
|
|
192
|
-
enabled: true,
|
|
193
|
-
allowed_origins: ['https://someotherdomain.com'],
|
|
194
|
-
cors_use_tracecontext_headers: true
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
jest.mocked(getConfiguration).mockReturnValue(agentConfig)
|
|
198
|
-
jest.mocked(getConfigurationValue).mockReturnValue(agentConfig.distributed_tracing)
|
|
199
|
-
|
|
200
|
-
const payload = dtInstance.generateTracePayload({
|
|
201
|
-
sameOrigin: false,
|
|
202
|
-
hostname: 'someotherdomain.com',
|
|
203
|
-
protocol: 'https',
|
|
204
|
-
port: '443'
|
|
205
|
-
})
|
|
206
|
-
|
|
207
|
-
expect(payload.traceContextParentHeader).not.toBeUndefined()
|
|
208
|
-
expect(payload.traceContextStateHeader).not.toBeUndefined()
|
|
209
|
-
})
|
|
210
|
-
|
|
211
|
-
test('trace context headers are not added to cross-origin calls when disabled in configuration', () => {
|
|
212
|
-
const agentConfig = {
|
|
213
|
-
distributed_tracing: {
|
|
214
|
-
enabled: true,
|
|
215
|
-
allowed_origins: ['https://someotherdomain.com'],
|
|
216
|
-
cors_use_tracecontext_headers: false
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
jest.mocked(getConfiguration).mockReturnValue(agentConfig)
|
|
220
|
-
jest.mocked(getConfigurationValue).mockReturnValue(agentConfig.distributed_tracing)
|
|
221
|
-
|
|
222
|
-
const payload = dtInstance.generateTracePayload({
|
|
223
|
-
sameOrigin: false,
|
|
224
|
-
hostname: 'someotherdomain.com',
|
|
225
|
-
protocol: 'https',
|
|
226
|
-
port: '443'
|
|
227
|
-
})
|
|
228
|
-
|
|
229
|
-
expect(payload.traceContextParentHeader).toBeUndefined()
|
|
230
|
-
expect(payload.traceContextStateHeader).toBeUndefined()
|
|
231
|
-
})
|
|
232
|
-
|
|
233
|
-
test('newrelic header is generated when configuration has numeric values', () => {
|
|
234
|
-
jest.mocked(getLoaderConfig).mockReturnValue({
|
|
235
|
-
accountID: 1234,
|
|
236
|
-
agentID: 5678,
|
|
237
|
-
trustKey: 1
|
|
238
|
-
})
|
|
239
|
-
|
|
240
|
-
const agentConfig = {
|
|
241
|
-
distributed_tracing: {
|
|
242
|
-
enabled: true
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
jest.mocked(getConfiguration).mockReturnValue(agentConfig)
|
|
246
|
-
jest.mocked(getConfigurationValue).mockReturnValue(agentConfig.distributed_tracing)
|
|
247
|
-
|
|
248
|
-
const payload = dtInstance.generateTracePayload({
|
|
249
|
-
sameOrigin: true
|
|
250
|
-
})
|
|
251
|
-
const header = JSON.parse(atob(payload.newrelicHeader))
|
|
252
|
-
|
|
253
|
-
expect(payload.spanId).toEqual(header.d.id)
|
|
254
|
-
expect(payload.traceId).toEqual(header.d.tr)
|
|
255
|
-
expect(payload.timestamp).toEqual(header.d.ti)
|
|
256
|
-
|
|
257
|
-
const loaderConfig = getLoaderConfig()
|
|
258
|
-
expect(header.d.ty).toEqual('Browser')
|
|
259
|
-
expect(header.d.ac).toEqual(loaderConfig.accountID.toString())
|
|
260
|
-
expect(header.d.ap).toEqual(loaderConfig.agentID.toString())
|
|
261
|
-
expect(header.d.tk).toEqual(loaderConfig.trustKey.toString())
|
|
262
|
-
})
|
|
263
|
-
|
|
264
|
-
test('no trace headers are generated when the loader config object is empty', () => {
|
|
265
|
-
const agentConfig = {
|
|
266
|
-
}
|
|
267
|
-
jest.mocked(getConfiguration).mockReturnValue(agentConfig)
|
|
268
|
-
jest.mocked(getConfigurationValue).mockReturnValue(agentConfig.distributed_tracing)
|
|
269
|
-
|
|
270
|
-
const payload = dtInstance.generateTracePayload({
|
|
271
|
-
sameOrigin: true
|
|
272
|
-
})
|
|
273
|
-
|
|
274
|
-
expect(payload).toBeNull()
|
|
275
|
-
})
|
|
276
|
-
|
|
277
|
-
test.each([null, undefined])('no trace headers are generated when the loader config accountID is %s', (accountID) => {
|
|
278
|
-
jest.mocked(getLoaderConfig).mockReturnValue({
|
|
279
|
-
accountID,
|
|
280
|
-
agentID: '5678',
|
|
281
|
-
trustKey: '1'
|
|
282
|
-
})
|
|
283
|
-
|
|
284
|
-
const agentConfig = {
|
|
285
|
-
distributed_tracing: {
|
|
286
|
-
enabled: true
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
jest.mocked(getConfiguration).mockReturnValue(agentConfig)
|
|
290
|
-
jest.mocked(getConfigurationValue).mockReturnValue(agentConfig.distributed_tracing)
|
|
291
|
-
|
|
292
|
-
const payload = dtInstance.generateTracePayload({
|
|
293
|
-
sameOrigin: true
|
|
294
|
-
})
|
|
295
|
-
|
|
296
|
-
expect(payload).toBeNull()
|
|
297
|
-
})
|
|
298
|
-
|
|
299
|
-
test.each([null, undefined])('no trace headers are generated when the loader config agentID is %s', (agentID) => {
|
|
300
|
-
jest.mocked(getLoaderConfig).mockReturnValue({
|
|
301
|
-
accountID: '1234',
|
|
302
|
-
agentID,
|
|
303
|
-
trustKey: '1'
|
|
304
|
-
})
|
|
305
|
-
|
|
306
|
-
const agentConfig = {
|
|
307
|
-
distributed_tracing: {
|
|
308
|
-
enabled: true
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
jest.mocked(getConfiguration).mockReturnValue(agentConfig)
|
|
312
|
-
jest.mocked(getConfigurationValue).mockReturnValue(agentConfig.distributed_tracing)
|
|
313
|
-
|
|
314
|
-
const payload = dtInstance.generateTracePayload({
|
|
315
|
-
sameOrigin: true
|
|
316
|
-
})
|
|
317
|
-
|
|
318
|
-
expect(payload).toBeNull()
|
|
319
|
-
})
|
|
320
|
-
|
|
321
|
-
test.each([null, undefined])('trace headers are generated without trust key when the loader config trustKey is %s', (trustKey) => {
|
|
322
|
-
jest.mocked(getLoaderConfig).mockReturnValue({
|
|
323
|
-
accountID: '1234',
|
|
324
|
-
agentID: '5678',
|
|
325
|
-
trustKey
|
|
326
|
-
})
|
|
327
|
-
|
|
328
|
-
const agentConfig = {
|
|
329
|
-
distributed_tracing: {
|
|
330
|
-
enabled: true
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
jest.mocked(getConfiguration).mockReturnValue(agentConfig)
|
|
334
|
-
jest.mocked(getConfigurationValue).mockReturnValue(agentConfig.distributed_tracing)
|
|
335
|
-
|
|
336
|
-
const payload = dtInstance.generateTracePayload({
|
|
337
|
-
sameOrigin: true
|
|
338
|
-
})
|
|
339
|
-
const header = JSON.parse(atob(payload.newrelicHeader))
|
|
340
|
-
|
|
341
|
-
expect(payload.spanId).toEqual(header.d.id)
|
|
342
|
-
expect(payload.traceId).toEqual(header.d.tr)
|
|
343
|
-
expect(payload.timestamp).toEqual(header.d.ti)
|
|
344
|
-
|
|
345
|
-
const loaderConfig = getLoaderConfig()
|
|
346
|
-
expect(header.d.ty).toEqual('Browser')
|
|
347
|
-
expect(header.d.ac).toEqual(loaderConfig.accountID.toString())
|
|
348
|
-
expect(header.d.ap).toEqual(loaderConfig.agentID.toString())
|
|
349
|
-
expect(header.d.tk).toBeUndefined()
|
|
350
|
-
})
|
|
351
|
-
|
|
352
|
-
test.each([null, undefined])('newrelic header is not added when btoa global is %s', (replacementBTOA) => {
|
|
353
|
-
jest.replaceProperty(runtimeModule, 'globalScope', {
|
|
354
|
-
btoa: replacementBTOA
|
|
355
|
-
})
|
|
356
|
-
|
|
357
|
-
const agentConfig = {
|
|
358
|
-
distributed_tracing: {
|
|
359
|
-
enabled: true
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
jest.mocked(getConfiguration).mockReturnValue(agentConfig)
|
|
363
|
-
jest.mocked(getConfigurationValue).mockReturnValue(agentConfig.distributed_tracing)
|
|
364
|
-
|
|
365
|
-
const payload = dtInstance.generateTracePayload({
|
|
366
|
-
sameOrigin: true
|
|
367
|
-
})
|
|
368
|
-
|
|
369
|
-
expect(typeof payload.spanId).toEqual('string')
|
|
370
|
-
expect(typeof payload.traceId).toEqual('string')
|
|
371
|
-
expect(typeof payload.timestamp).toEqual('number')
|
|
372
|
-
expect(typeof payload.traceContextParentHeader).toEqual('string')
|
|
373
|
-
expect(typeof payload.traceContextStateHeader).toEqual('string')
|
|
374
|
-
expect(payload.header).toBeUndefined()
|
|
375
|
-
})
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { canonicalFunctionName } from './canonical-function-name'
|
|
2
|
-
|
|
3
|
-
test.each([
|
|
4
|
-
{ input: null, expected: undefined, title: 'Return undefined if no function name' },
|
|
5
|
-
{ input: 'test', expected: 'test', title: 'Simple function name' },
|
|
6
|
-
{ input: 'scope1/scope2/func', expected: 'func', title: 'Remove Firefox scopes' },
|
|
7
|
-
{ input: 'scope1.func', expected: 'func', title: 'Remove Chrome scopes' },
|
|
8
|
-
{ input: '<anonymous>', expected: undefined, title: 'Return undefined ending is non-alphanumeric' }
|
|
9
|
-
])('$title', ({ input, expected }) => {
|
|
10
|
-
const result = canonicalFunctionName(input)
|
|
11
|
-
|
|
12
|
-
expect(result).toEqual(expected)
|
|
13
|
-
})
|