@newrelic/browser-agent 1.237.1 → 1.239.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/dist/cjs/common/config/state/init.js +21 -13
- package/dist/cjs/common/config/state/runtime.js +0 -4
- package/dist/cjs/common/constants/env.cdn.js +1 -1
- package/dist/cjs/common/constants/env.npm.js +1 -1
- package/dist/cjs/common/constants/runtime.js +3 -3
- package/dist/cjs/common/constants/shared-channel.js +3 -1
- package/dist/cjs/common/deny-list/deny-list.js +3 -9
- package/dist/cjs/common/drain/drain.js +1 -1
- package/dist/cjs/common/event-emitter/contextual-ee.js +24 -32
- package/dist/cjs/common/event-emitter/event-context.js +12 -0
- package/dist/cjs/common/harvest/harvest-scheduler.js +2 -4
- package/dist/cjs/common/harvest/harvest.js +4 -7
- package/dist/cjs/common/ids/bundle-id.js +19 -0
- package/dist/cjs/common/serialize/bel-serializer.js +1 -1
- package/dist/cjs/common/session/session-entity.js +16 -12
- package/dist/cjs/common/storage/first-party-cookies.js +5 -4
- package/dist/cjs/common/storage/local-storage.js +3 -2
- package/dist/cjs/common/timer/interaction-timer.js +14 -6
- package/dist/cjs/common/timing/nav-timing.js +1 -1
- package/dist/cjs/common/unload/eol.js +4 -30
- package/dist/cjs/common/util/feature-flags.js +14 -15
- package/dist/cjs/common/util/invoke.js +3 -1
- package/dist/cjs/common/util/obfuscate.js +3 -5
- package/dist/cjs/common/util/traverse.js +1 -0
- package/dist/cjs/common/window/page-visibility.js +1 -2
- package/dist/cjs/common/wrap/wrap-events.js +3 -2
- package/dist/cjs/common/wrap/wrap-fetch.js +1 -3
- package/dist/cjs/common/wrap/wrap-function.js +15 -46
- package/dist/cjs/common/wrap/wrap-jsonp.js +1 -1
- package/dist/cjs/common/wrap/wrap-mutation.js +1 -2
- package/dist/cjs/common/wrap/wrap-promise.js +2 -3
- package/dist/cjs/common/wrap/wrap-xhr.js +23 -27
- package/dist/cjs/features/ajax/aggregate/index.js +5 -7
- package/dist/cjs/features/ajax/instrument/distributed-tracing.js +8 -12
- package/dist/cjs/features/ajax/instrument/index.js +66 -24
- package/dist/cjs/features/jserrors/aggregate/canonical-function-name.js +0 -1
- package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.js +4 -4
- package/dist/cjs/features/jserrors/aggregate/index.js +4 -5
- package/dist/cjs/features/metrics/aggregate/framework-detection.js +103 -7
- package/dist/cjs/features/metrics/aggregate/index.js +20 -37
- package/dist/cjs/features/metrics/instrument/index.js +0 -2
- package/dist/cjs/features/page_action/aggregate/index.js +17 -19
- package/dist/cjs/features/page_view_event/aggregate/index.js +1 -2
- package/dist/cjs/features/page_view_event/instrument/index.js +4 -2
- package/dist/cjs/features/page_view_timing/aggregate/index.js +6 -7
- package/dist/cjs/features/session_replay/aggregate/index.js +5 -3
- package/dist/cjs/features/session_trace/aggregate/index.js +22 -16
- package/dist/cjs/features/spa/aggregate/index.js +14 -20
- package/dist/cjs/features/spa/aggregate/interaction.js +0 -2
- package/dist/cjs/features/spa/aggregate/serializer.js +1 -1
- package/dist/cjs/features/utils/aggregate-base.js +4 -0
- package/dist/cjs/features/utils/handler-cache.js +3 -1
- package/dist/cjs/features/utils/instrument-base.js +24 -6
- package/dist/cjs/loaders/agent-base.js +23 -0
- package/dist/cjs/loaders/agent.js +7 -7
- package/dist/cjs/loaders/api/api.js +34 -4
- package/dist/cjs/loaders/api/apiAsync.js +19 -20
- package/dist/cjs/loaders/api/interaction-types.js +11 -4
- package/dist/cjs/loaders/configure/configure.js +3 -0
- package/dist/cjs/loaders/micro-agent.js +20 -3
- package/dist/esm/common/config/state/init.js +21 -13
- package/dist/esm/common/config/state/runtime.js +0 -4
- package/dist/esm/common/constants/env.cdn.js +1 -1
- package/dist/esm/common/constants/env.npm.js +1 -1
- package/dist/esm/common/constants/runtime.js +1 -1
- package/dist/esm/common/constants/shared-channel.js +3 -1
- package/dist/esm/common/deny-list/deny-list.js +3 -9
- package/dist/esm/common/drain/drain.js +1 -1
- package/dist/esm/common/event-emitter/contextual-ee.js +22 -29
- package/dist/esm/common/event-emitter/event-context.js +5 -0
- package/dist/esm/common/harvest/harvest-scheduler.js +2 -4
- package/dist/esm/common/harvest/harvest.js +4 -7
- package/dist/esm/common/ids/bundle-id.js +13 -0
- package/dist/esm/common/serialize/bel-serializer.js +1 -1
- package/dist/esm/common/session/session-entity.js +16 -12
- package/dist/esm/common/storage/first-party-cookies.js +5 -4
- package/dist/esm/common/storage/local-storage.js +3 -2
- package/dist/esm/common/timer/interaction-timer.js +14 -6
- package/dist/esm/common/timing/nav-timing.js +1 -1
- package/dist/esm/common/unload/eol.js +5 -31
- package/dist/esm/common/util/feature-flags.js +14 -15
- package/dist/esm/common/util/invoke.js +3 -1
- package/dist/esm/common/util/obfuscate.js +3 -5
- package/dist/esm/common/util/traverse.js +1 -0
- package/dist/esm/common/window/page-visibility.js +1 -2
- package/dist/esm/common/wrap/wrap-events.js +4 -3
- package/dist/esm/common/wrap/wrap-fetch.js +2 -4
- package/dist/esm/common/wrap/wrap-function.js +15 -44
- package/dist/esm/common/wrap/wrap-jsonp.js +1 -1
- package/dist/esm/common/wrap/wrap-mutation.js +2 -3
- package/dist/esm/common/wrap/wrap-promise.js +3 -4
- package/dist/esm/common/wrap/wrap-xhr.js +23 -27
- package/dist/esm/features/ajax/aggregate/index.js +5 -7
- package/dist/esm/features/ajax/instrument/distributed-tracing.js +8 -12
- package/dist/esm/features/ajax/instrument/index.js +67 -25
- package/dist/esm/features/jserrors/aggregate/canonical-function-name.js +0 -1
- package/dist/esm/features/jserrors/aggregate/compute-stack-trace.js +4 -4
- package/dist/esm/features/jserrors/aggregate/index.js +4 -5
- package/dist/esm/features/metrics/aggregate/framework-detection.js +103 -7
- package/dist/esm/features/metrics/aggregate/index.js +22 -39
- package/dist/esm/features/metrics/instrument/index.js +1 -3
- package/dist/esm/features/page_action/aggregate/index.js +17 -19
- package/dist/esm/features/page_view_event/aggregate/index.js +1 -2
- package/dist/esm/features/page_view_event/instrument/index.js +4 -2
- package/dist/esm/features/page_view_timing/aggregate/index.js +7 -8
- package/dist/esm/features/session_replay/aggregate/index.js +4 -2
- package/dist/esm/features/session_trace/aggregate/index.js +22 -16
- package/dist/esm/features/spa/aggregate/index.js +14 -20
- package/dist/esm/features/spa/aggregate/interaction.js +0 -2
- package/dist/esm/features/spa/aggregate/serializer.js +1 -1
- package/dist/esm/features/utils/aggregate-base.js +4 -0
- package/dist/esm/features/utils/handler-cache.js +3 -1
- package/dist/esm/features/utils/instrument-base.js +24 -6
- package/dist/esm/loaders/agent-base.js +23 -0
- package/dist/esm/loaders/agent.js +7 -7
- package/dist/esm/loaders/api/api.js +34 -4
- package/dist/esm/loaders/api/apiAsync.js +19 -20
- package/dist/esm/loaders/api/interaction-types.js +11 -4
- package/dist/esm/loaders/configure/configure.js +3 -0
- package/dist/esm/loaders/features/enabled-features.js +1 -1
- package/dist/esm/loaders/micro-agent.js +21 -4
- package/dist/types/common/config/state/init.d.ts.map +1 -1
- package/dist/types/common/config/state/runtime.d.ts.map +1 -1
- package/dist/types/common/constants/runtime.d.ts +1 -1
- package/dist/types/common/constants/runtime.d.ts.map +1 -1
- package/dist/types/common/event-emitter/contextual-ee.d.ts +22 -2
- package/dist/types/common/event-emitter/contextual-ee.d.ts.map +1 -1
- package/dist/types/common/event-emitter/event-context.d.ts +5 -0
- package/dist/types/common/event-emitter/event-context.d.ts.map +1 -0
- package/dist/types/common/event-emitter/register-handler.d.ts +1 -1
- package/dist/types/common/harvest/harvest-scheduler.d.ts.map +1 -1
- package/dist/types/common/harvest/harvest.d.ts.map +1 -1
- package/dist/types/common/ids/bundle-id.d.ts +5 -0
- package/dist/types/common/ids/bundle-id.d.ts.map +1 -0
- package/dist/types/common/session/session-entity.d.ts +12 -15
- package/dist/types/common/session/session-entity.d.ts.map +1 -1
- package/dist/types/common/storage/first-party-cookies.d.ts +1 -1
- package/dist/types/common/storage/first-party-cookies.d.ts.map +1 -1
- package/dist/types/common/storage/local-storage.d.ts.map +1 -1
- package/dist/types/common/timer/interaction-timer.d.ts +3 -0
- package/dist/types/common/timer/interaction-timer.d.ts.map +1 -1
- package/dist/types/common/unload/eol.d.ts +1 -2
- package/dist/types/common/unload/eol.d.ts.map +1 -1
- package/dist/types/common/util/feature-flags.d.ts.map +1 -1
- package/dist/types/common/util/obfuscate.d.ts.map +1 -1
- package/dist/types/common/util/traverse.d.ts.map +1 -1
- package/dist/types/common/window/nreum.d.ts +2 -2
- package/dist/types/common/window/page-visibility.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-events.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-fetch.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-function.d.ts +1 -19
- package/dist/types/common/wrap/wrap-function.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-mutation.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-promise.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-xhr.d.ts.map +1 -1
- package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/ajax/instrument/distributed-tracing.d.ts +1 -1
- package/dist/types/features/ajax/instrument/distributed-tracing.d.ts.map +1 -1
- package/dist/types/features/ajax/instrument/index.d.ts.map +1 -1
- package/dist/types/features/jserrors/aggregate/canonical-function-name.d.ts.map +1 -1
- package/dist/types/features/jserrors/aggregate/index.d.ts +1 -1
- package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/metrics/aggregate/framework-detection.d.ts.map +1 -1
- package/dist/types/features/metrics/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/metrics/instrument/index.d.ts.map +1 -1
- package/dist/types/features/page_action/aggregate/index.d.ts +2 -2
- package/dist/types/features/page_action/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/session_trace/aggregate/index.d.ts +5 -0
- package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/spa/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/spa/aggregate/interaction.d.ts.map +1 -1
- package/dist/types/features/utils/aggregate-base.d.ts +1 -0
- package/dist/types/features/utils/aggregate-base.d.ts.map +1 -1
- package/dist/types/features/utils/handler-cache.d.ts.map +1 -1
- package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
- package/dist/types/loaders/agent-base.d.ts +15 -0
- package/dist/types/loaders/agent-base.d.ts.map +1 -1
- package/dist/types/loaders/agent.d.ts +1 -1
- package/dist/types/loaders/agent.d.ts.map +1 -1
- package/dist/types/loaders/api/api.d.ts +7 -0
- 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/api/interaction-types.d.ts +18 -7
- package/dist/types/loaders/api/interaction-types.d.ts.map +1 -1
- package/dist/types/loaders/configure/configure.d.ts +2 -0
- package/dist/types/loaders/configure/configure.d.ts.map +1 -1
- package/dist/types/loaders/features/features.d.ts +9 -9
- package/dist/types/loaders/micro-agent.d.ts +7 -1
- package/dist/types/loaders/micro-agent.d.ts.map +1 -1
- package/package.json +62 -38
- package/src/common/aggregate/aggregator.test.js +107 -0
- package/src/common/config/state/configurable.test.js +73 -0
- package/src/common/config/state/info.test.js +31 -0
- package/src/common/config/state/init.js +13 -12
- package/src/common/config/state/init.test.js +28 -0
- package/src/common/config/state/loader-config.test.js +21 -0
- package/src/common/config/state/runtime.js +0 -2
- package/src/common/config/state/runtime.test.js +21 -0
- package/src/common/constants/__mocks__/runtime.js +1 -1
- package/src/common/constants/runtime.js +1 -1
- package/src/common/constants/runtime.test.js +2 -2
- package/src/common/constants/shared-channel.js +1 -1
- package/src/common/deny-list/deny-list.js +3 -11
- package/src/common/deny-list/deny-list.test.js +103 -30
- package/src/common/drain/drain.js +1 -1
- package/src/common/drain/drain.test.js +74 -0
- package/src/common/event-emitter/{contextual-ee.test.js → contextual-ee.component-test.js} +15 -32
- package/src/common/event-emitter/contextual-ee.js +26 -37
- package/src/common/event-emitter/event-context.js +5 -0
- package/src/common/harvest/harvest-scheduler.js +2 -5
- package/src/common/harvest/harvest-scheduler.test.js +2 -6
- package/src/common/harvest/harvest.js +4 -7
- package/src/common/harvest/harvest.test.js +1 -3
- package/src/common/ids/__mocks__/bundle-id.js +2 -0
- package/src/common/ids/__mocks__/unique-id.js +17 -0
- package/src/common/ids/bundle-id.js +13 -0
- package/src/common/ids/id.test.js +6 -6
- package/src/common/serialize/bel-serializer.js +1 -1
- package/src/common/session/session-entity.component-test.js +3 -2
- package/src/common/session/session-entity.js +11 -9
- package/src/common/storage/first-party-cookies.js +5 -4
- package/src/common/storage/local-storage.js +3 -2
- package/src/common/timer/interaction-timer.component-test.js +52 -7
- package/src/common/timer/interaction-timer.js +15 -6
- package/src/common/timer/timer.test.js +0 -1
- package/src/common/timing/nav-timing.js +1 -1
- package/src/common/unload/eol.js +5 -31
- package/src/common/url/__mocks__/parse-url.js +15 -0
- package/src/common/url/{encode.component-test.js → encode.test.js} +1 -0
- package/src/common/util/__mocks__/get-or-set.js +5 -0
- package/src/common/util/__mocks__/invoke.js +1 -0
- package/src/common/util/data-size.test.js +0 -1
- package/src/common/util/feature-flags.js +15 -17
- package/src/common/util/feature-flags.test.js +4 -8
- package/src/common/util/invoke.js +1 -1
- package/src/common/util/obfuscate.js +3 -5
- package/src/common/util/submit-data.test.js +1 -1
- package/src/common/util/traverse.js +1 -0
- package/src/common/window/__mocks__/nreum.js +12 -0
- package/src/common/window/page-visibility.js +1 -2
- package/src/common/wrap/wrap-events.js +4 -3
- package/src/common/wrap/wrap-fetch.js +2 -4
- package/src/common/wrap/wrap-function.js +16 -44
- package/src/common/wrap/wrap-jsonp.js +1 -1
- package/src/common/wrap/wrap-mutation.js +2 -3
- package/src/common/wrap/{wrap-promise.test.js → wrap-promise.component-test.js} +2 -32
- package/src/common/wrap/wrap-promise.js +3 -4
- package/src/common/wrap/wrap-xhr.js +24 -28
- package/src/features/ajax/aggregate/index.js +5 -7
- package/src/features/ajax/instrument/distributed-tracing.js +8 -12
- package/src/features/ajax/instrument/distributed-tracing.test.js +375 -0
- package/src/features/ajax/instrument/index.js +62 -27
- package/src/features/jserrors/aggregate/canonical-function-name.js +0 -2
- package/src/features/jserrors/aggregate/compute-stack-trace.js +4 -4
- package/src/features/jserrors/aggregate/compute-stack-trace.test.js +1 -1
- package/src/features/jserrors/aggregate/index.js +4 -5
- package/src/features/metrics/aggregate/framework-detection.js +129 -8
- package/src/features/metrics/aggregate/framework-detection.test.js +213 -82
- package/src/features/metrics/aggregate/index.js +22 -45
- package/src/features/metrics/instrument/index.js +1 -3
- package/src/features/page_action/aggregate/index.js +12 -13
- package/src/features/page_view_event/aggregate/index.js +1 -2
- package/src/features/page_view_event/instrument/index.js +2 -2
- package/src/features/page_view_timing/aggregate/index.js +7 -8
- package/src/features/session_replay/aggregate/index.component-test.js +3 -15
- package/src/features/session_replay/aggregate/index.js +4 -2
- package/src/features/session_trace/aggregate/index.js +22 -16
- package/src/features/spa/aggregate/index.js +14 -20
- package/src/features/spa/aggregate/interaction.js +0 -2
- package/src/features/spa/aggregate/serializer.js +1 -1
- package/src/features/utils/aggregate-base.js +5 -0
- package/src/features/utils/aggregate-base.test.js +2 -1
- package/src/features/utils/handler-cache.js +3 -2
- package/src/features/utils/instrument-base.js +25 -6
- package/src/features/utils/instrument-base.test.js +2 -2
- package/src/loaders/agent-base.js +23 -0
- package/src/loaders/agent.js +7 -7
- package/src/loaders/api/api.component-test.js +45 -0
- package/src/loaders/api/api.js +34 -4
- package/src/loaders/api/api.test.js +85 -0
- package/src/loaders/api/apiAsync.js +19 -20
- package/src/loaders/api/apiAsync.test.js +17 -0
- package/src/loaders/api/interaction-types.js +11 -4
- package/src/loaders/configure/configure.js +3 -0
- package/src/loaders/features/enabled-features.js +1 -1
- package/src/loaders/micro-agent.js +22 -4
- package/dist/cjs/features/metrics/aggregate/endpoint-map.js +0 -14
- package/dist/cjs/features/metrics/aggregate/polyfill-detection.es5.js +0 -14
- package/dist/cjs/features/metrics/aggregate/polyfill-detection.js +0 -53
- package/dist/esm/features/metrics/aggregate/endpoint-map.js +0 -7
- package/dist/esm/features/metrics/aggregate/polyfill-detection.es5.js +0 -8
- package/dist/esm/features/metrics/aggregate/polyfill-detection.js +0 -47
- package/dist/types/features/metrics/aggregate/endpoint-map.d.ts +0 -8
- package/dist/types/features/metrics/aggregate/endpoint-map.d.ts.map +0 -1
- package/dist/types/features/metrics/aggregate/polyfill-detection.d.ts +0 -6
- package/dist/types/features/metrics/aggregate/polyfill-detection.d.ts.map +0 -1
- package/dist/types/features/metrics/aggregate/polyfill-detection.es5.d.ts +0 -7
- package/dist/types/features/metrics/aggregate/polyfill-detection.es5.d.ts.map +0 -1
- package/src/features/metrics/aggregate/endpoint-map.js +0 -7
- package/src/features/metrics/aggregate/polyfill-detection.es5.js +0 -8
- package/src/features/metrics/aggregate/polyfill-detection.es5.test.js +0 -16
- package/src/features/metrics/aggregate/polyfill-detection.js +0 -48
- package/src/features/metrics/aggregate/polyfill-detection.test.js +0 -163
- /package/src/common/url/{protocol.component-test.js → protocol.test.js} +0 -0
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import { ee } from '../event-emitter/contextual-ee'
|
|
10
|
-
|
|
10
|
+
import { bundleId } from '../ids/bundle-id'
|
|
11
|
+
|
|
12
|
+
export const flag = `nr@original:${bundleId}`
|
|
11
13
|
|
|
12
14
|
/**
|
|
13
15
|
* A convenience alias of `hasOwnProperty`.
|
|
@@ -107,26 +109,24 @@ export function createWrapperWithEmitter (emitter, always) {
|
|
|
107
109
|
|
|
108
110
|
/**
|
|
109
111
|
* Creates wrapper functions around each of an array of methods on a specified object.
|
|
110
|
-
* @param {Object} obj
|
|
111
|
-
* @param {string[]} methods
|
|
112
|
-
* @param {string} [prefix='']
|
|
113
|
-
*
|
|
114
|
-
* @param {function|object} [getContext]
|
|
115
|
-
*
|
|
116
|
-
* @param {boolean} [bubble=false]
|
|
117
|
-
*
|
|
112
|
+
* @param {Object} obj The object to which the specified methods belong.
|
|
113
|
+
* @param {string[]} methods An array of method names to be wrapped.
|
|
114
|
+
* @param {string} [prefix=''] A prefix to add to the names of emitted events. If `-` is the first character, also
|
|
115
|
+
* adds the method name before the prefix.
|
|
116
|
+
* @param {function|object} [getContext] The function or object that will serve as the 'this' context for handlers
|
|
117
|
+
* of events emitted by this wrapper.
|
|
118
|
+
* @param {boolean} [bubble=false] If `true`, emitted events should also bubble up to the old emitter upon which
|
|
119
|
+
* the `emitter` in the current scope was based (if it defines one).
|
|
118
120
|
*/
|
|
119
121
|
function inPlace (obj, methods, prefix, getContext, bubble) {
|
|
120
122
|
if (!prefix) prefix = ''
|
|
123
|
+
|
|
121
124
|
// If prefix starts with '-' set this boolean to add the method name to the prefix before passing each one to wrap.
|
|
122
|
-
|
|
123
|
-
var fn
|
|
124
|
-
var method
|
|
125
|
-
var i
|
|
125
|
+
const prependMethodPrefix = (prefix.charAt(0) === '-')
|
|
126
126
|
|
|
127
|
-
for (i = 0; i < methods.length; i++) {
|
|
128
|
-
method = methods[i]
|
|
129
|
-
fn = obj[method]
|
|
127
|
+
for (let i = 0; i < methods.length; i++) {
|
|
128
|
+
const method = methods[i]
|
|
129
|
+
const fn = obj[method]
|
|
130
130
|
|
|
131
131
|
// Unless fn is both wrappable and unwrapped, bail so we don't add extra properties with undefined values.
|
|
132
132
|
if (notWrappable(fn)) continue
|
|
@@ -217,31 +217,3 @@ function copy (from, to, emitter) {
|
|
|
217
217
|
function notWrappable (fn) {
|
|
218
218
|
return !(fn && fn instanceof Function && fn.apply && !fn[flag])
|
|
219
219
|
}
|
|
220
|
-
|
|
221
|
-
/**
|
|
222
|
-
* Creates a wrapped version of a function using a specified wrapper function. The new wrapped function references the
|
|
223
|
-
* original function. Also copies the properties of the original function to the wrapped function.
|
|
224
|
-
* @param {function} fn - A function to be wrapped.
|
|
225
|
-
* @param {function} wrapper - A higher order function that returns a new function, which executes the function passed
|
|
226
|
-
* to the higher order function as an argument.
|
|
227
|
-
* @returns {function} A wrapped function with an internal reference to the original function.
|
|
228
|
-
*/
|
|
229
|
-
export function wrapFunction (fn, wrapper) {
|
|
230
|
-
var wrapped = wrapper(fn)
|
|
231
|
-
wrapped[flag] = fn
|
|
232
|
-
copy(fn, wrapped, ee)
|
|
233
|
-
return wrapped
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
/**
|
|
237
|
-
* Replaces a function with a wrapped version of itself. To preserve object references, rather than taking the function
|
|
238
|
-
* itself as an argument, takes the object on which the particular named function is a property.
|
|
239
|
-
* @param {Object} obj - The object on which the named function is a property.
|
|
240
|
-
* @param {string} fnName - The name of the function to be wrapped.
|
|
241
|
-
* @param {function} wrapper - A higher order function that returns a new function, which executes the function passed
|
|
242
|
-
* to the higher order function as an argument.
|
|
243
|
-
*/
|
|
244
|
-
export function wrapInPlace (obj, fnName, wrapper) {
|
|
245
|
-
var fn = obj[fnName]
|
|
246
|
-
obj[fnName] = wrapFunction(fn, wrapper)
|
|
247
|
-
}
|
|
@@ -9,8 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
import { ee as baseEE } from '../event-emitter/contextual-ee'
|
|
11
11
|
import { createWrapperWithEmitter as wfn } from './wrap-function'
|
|
12
|
-
import {
|
|
13
|
-
import { isBrowserScope } from '../constants/runtime'
|
|
12
|
+
import { globalScope, isBrowserScope } from '../constants/runtime'
|
|
14
13
|
|
|
15
14
|
const wrapped = {}
|
|
16
15
|
|
|
@@ -30,7 +29,7 @@ export function wrapMutation (sharedEE) {
|
|
|
30
29
|
wrapped[ee.debugId] = true // otherwise, first feature to wrap mutations
|
|
31
30
|
|
|
32
31
|
var wrapFn = wfn(ee)
|
|
33
|
-
var OriginalObserver =
|
|
32
|
+
var OriginalObserver = globalScope.MutationObserver
|
|
34
33
|
|
|
35
34
|
if (OriginalObserver) {
|
|
36
35
|
window.MutationObserver = function WrappedMutationObserver (cb) {
|
|
@@ -1,35 +1,5 @@
|
|
|
1
1
|
import { faker } from '@faker-js/faker'
|
|
2
2
|
import { globalScope } from '../constants/runtime'
|
|
3
|
-
import { originals } from '../config/config'
|
|
4
|
-
|
|
5
|
-
jest.mock('./wrap-function', () => ({
|
|
6
|
-
__esModule: true,
|
|
7
|
-
createWrapperWithEmitter: jest.fn(() => (fn) => (...args) => {
|
|
8
|
-
return fn.apply(null, args)
|
|
9
|
-
})
|
|
10
|
-
}))
|
|
11
|
-
jest.mock('../event-emitter/contextual-ee', () => ({
|
|
12
|
-
__esModule: true,
|
|
13
|
-
getOrSetContext: jest.fn(() => ({})),
|
|
14
|
-
ee: {
|
|
15
|
-
get: jest.fn((name) => ({
|
|
16
|
-
debugId: name,
|
|
17
|
-
on: jest.fn(),
|
|
18
|
-
context: jest.fn(() => ({})),
|
|
19
|
-
emit: jest.fn()
|
|
20
|
-
}))
|
|
21
|
-
}
|
|
22
|
-
}))
|
|
23
|
-
jest.mock('../config/config', () => ({
|
|
24
|
-
__esModule: true,
|
|
25
|
-
originals: {}
|
|
26
|
-
}))
|
|
27
|
-
jest.mock('../constants/runtime', () => ({
|
|
28
|
-
__esModule: true,
|
|
29
|
-
globalScope: {
|
|
30
|
-
NREUM: {}
|
|
31
|
-
}
|
|
32
|
-
}))
|
|
33
3
|
|
|
34
4
|
let promiseConstructorCalls
|
|
35
5
|
|
|
@@ -38,7 +8,7 @@ beforeEach(async () => {
|
|
|
38
8
|
|
|
39
9
|
// Proxy the global Promise to prevent the wrapping from
|
|
40
10
|
// messing with Jest internal promises
|
|
41
|
-
|
|
11
|
+
window.Promise = new Proxy(class extends Promise {}, {
|
|
42
12
|
construct (target, args) {
|
|
43
13
|
promiseConstructorCalls.push(args)
|
|
44
14
|
|
|
@@ -57,7 +27,7 @@ test('should wrap promise constructor', async () => {
|
|
|
57
27
|
const promiseInstance = new globalScope.Promise(jest.fn())
|
|
58
28
|
|
|
59
29
|
expect(promiseInstance).toBeInstanceOf(Promise)
|
|
60
|
-
expect(promiseConstructorCalls.length).
|
|
30
|
+
expect(promiseConstructorCalls.length).toBeGreaterThan(0)
|
|
61
31
|
expect(globalScope.Promise.toString()).toMatch(/\[native code\]/)
|
|
62
32
|
expect(globalScope.Promise.name).toEqual('Promise')
|
|
63
33
|
})
|
|
@@ -8,8 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { createWrapperWithEmitter as wrapFn, flag } from './wrap-function'
|
|
11
|
-
import { ee as baseEE
|
|
12
|
-
import { originals } from '../config/config'
|
|
11
|
+
import { ee as baseEE } from '../event-emitter/contextual-ee'
|
|
13
12
|
import { globalScope } from '../constants/runtime'
|
|
14
13
|
|
|
15
14
|
const wrapped = {}
|
|
@@ -29,9 +28,9 @@ export function wrapPromise (sharedEE) {
|
|
|
29
28
|
if (wrapped[promiseEE.debugId]) return promiseEE
|
|
30
29
|
wrapped[promiseEE.debugId] = true // otherwise, first feature to wrap promise
|
|
31
30
|
|
|
32
|
-
var getContext =
|
|
31
|
+
var getContext = promiseEE.context
|
|
33
32
|
var promiseWrapper = wrapFn(promiseEE)
|
|
34
|
-
var prevPromiseObj =
|
|
33
|
+
var prevPromiseObj = globalScope.Promise
|
|
35
34
|
|
|
36
35
|
if (prevPromiseObj) { // ensure there's a Promise API (native or otherwise) to even wrap
|
|
37
36
|
wrap()
|
|
@@ -11,7 +11,6 @@ import { wrapEvents } from './wrap-events'
|
|
|
11
11
|
import { ee as contextualEE } from '../event-emitter/contextual-ee'
|
|
12
12
|
import { eventListenerOpts } from '../event-listener/event-listener-opts'
|
|
13
13
|
import { createWrapperWithEmitter as wfn } from './wrap-function'
|
|
14
|
-
import { originals } from '../config/config'
|
|
15
14
|
import { globalScope } from '../constants/runtime'
|
|
16
15
|
import { warn } from '../util/console'
|
|
17
16
|
|
|
@@ -37,37 +36,33 @@ export function wrapXhr (sharedEE) {
|
|
|
37
36
|
wrapEvents(baseEE) // wrap-events patches XMLHttpRequest.prototype.addEventListener for us
|
|
38
37
|
var wrapFn = wfn(ee)
|
|
39
38
|
|
|
40
|
-
var OrigXHR =
|
|
41
|
-
var MutationObserver =
|
|
42
|
-
var Promise =
|
|
43
|
-
var setImmediate =
|
|
39
|
+
var OrigXHR = globalScope.XMLHttpRequest
|
|
40
|
+
var MutationObserver = globalScope.MutationObserver
|
|
41
|
+
var Promise = globalScope.Promise
|
|
42
|
+
var setImmediate = globalScope.setInterval
|
|
44
43
|
|
|
45
44
|
var READY_STATE_CHANGE = 'readystatechange'
|
|
46
45
|
|
|
47
46
|
var handlers = ['onload', 'onerror', 'onabort', 'onloadstart', 'onloadend', 'onprogress', 'ontimeout']
|
|
48
47
|
var pendingXhrs = []
|
|
49
48
|
|
|
50
|
-
var activeListeners = globalScope.XMLHttpRequest.listeners
|
|
51
|
-
|
|
52
49
|
var XHR = globalScope.XMLHttpRequest = newXHR
|
|
53
50
|
|
|
54
51
|
function newXHR (opts) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
52
|
+
const xhr = new OrigXHR(opts)
|
|
53
|
+
const context = ee.context(xhr)
|
|
54
|
+
|
|
55
|
+
try {
|
|
56
|
+
ee.emit('new-xhr', [xhr], context)
|
|
57
|
+
xhr.addEventListener(READY_STATE_CHANGE, wrapXHR(context), eventListenerOpts(false))
|
|
58
|
+
} catch (e) {
|
|
59
|
+
warn('An error occurred while intercepting XHR', e)
|
|
58
60
|
try {
|
|
59
|
-
ee.emit('
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
warn('An error occured while intercepting XHR', e)
|
|
63
|
-
try {
|
|
64
|
-
ee.emit('internal-error', [e])
|
|
65
|
-
} catch (err) {
|
|
66
|
-
// do nothing
|
|
67
|
-
}
|
|
61
|
+
ee.emit('internal-error', [e])
|
|
62
|
+
} catch (err) {
|
|
63
|
+
// do nothing
|
|
68
64
|
}
|
|
69
65
|
}
|
|
70
|
-
this.listeners.forEach(listener => listener())
|
|
71
66
|
return xhr
|
|
72
67
|
}
|
|
73
68
|
|
|
@@ -87,16 +82,17 @@ export function wrapXhr (sharedEE) {
|
|
|
87
82
|
wrapFn.inPlace(xhr, ['onreadystatechange'], 'fn-', getObject)
|
|
88
83
|
}
|
|
89
84
|
|
|
90
|
-
function wrapXHR () {
|
|
91
|
-
|
|
92
|
-
|
|
85
|
+
function wrapXHR (ctx) {
|
|
86
|
+
return function () {
|
|
87
|
+
var xhr = this
|
|
93
88
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
89
|
+
if (xhr.readyState > 3 && !ctx.resolved) {
|
|
90
|
+
ctx.resolved = true
|
|
91
|
+
ee.emit('xhr-resolved', [], xhr)
|
|
92
|
+
}
|
|
98
93
|
|
|
99
|
-
|
|
94
|
+
wrapFn.inPlace(xhr, handlers, 'fn-', getObject)
|
|
95
|
+
}
|
|
100
96
|
}
|
|
101
97
|
|
|
102
98
|
// Wrapping the onreadystatechange property of XHRs takes some special tricks.
|
|
@@ -10,7 +10,6 @@ import { getConfiguration, getInfo, getRuntime } from '../../../common/config/co
|
|
|
10
10
|
import { HarvestScheduler } from '../../../common/harvest/harvest-scheduler'
|
|
11
11
|
import { setDenyList, shouldCollectEvent } from '../../../common/deny-list/deny-list'
|
|
12
12
|
import { FEATURE_NAME } from '../constants'
|
|
13
|
-
import { drain } from '../../../common/drain/drain'
|
|
14
13
|
import { FEATURE_NAMES } from '../../../loaders/features/features'
|
|
15
14
|
import { SUPPORTABILITY_METRIC_CHANNEL } from '../../metrics/constants'
|
|
16
15
|
import { AggregateBase } from '../../utils/aggregate-base'
|
|
@@ -24,7 +23,7 @@ export class Aggregate extends AggregateBase {
|
|
|
24
23
|
|
|
25
24
|
register('xhr', storeXhr, this.featureName, this.ee)
|
|
26
25
|
if (!allAjaxIsEnabled) {
|
|
27
|
-
drain(
|
|
26
|
+
this.drain()
|
|
28
27
|
return // feature will only collect timeslice metrics & ajax trace nodes if it's not fully enabled
|
|
29
28
|
}
|
|
30
29
|
|
|
@@ -66,8 +65,7 @@ export class Aggregate extends AggregateBase {
|
|
|
66
65
|
|
|
67
66
|
ee.on(`drain-${this.featureName}`, () => { scheduler.startTimer(harvestTimeSeconds) })
|
|
68
67
|
|
|
69
|
-
drain(
|
|
70
|
-
return
|
|
68
|
+
this.drain()
|
|
71
69
|
|
|
72
70
|
function storeXhr (params, metrics, startTime, endTime, type) {
|
|
73
71
|
metrics.time = startTime
|
|
@@ -105,9 +103,9 @@ export class Aggregate extends AggregateBase {
|
|
|
105
103
|
path: params.pathname,
|
|
106
104
|
requestSize: metrics.txSize,
|
|
107
105
|
responseSize: metrics.rxSize,
|
|
108
|
-
type
|
|
109
|
-
startTime
|
|
110
|
-
endTime
|
|
106
|
+
type,
|
|
107
|
+
startTime,
|
|
108
|
+
endTime,
|
|
111
109
|
callbackDuration: metrics.cbTime
|
|
112
110
|
}
|
|
113
111
|
|
|
@@ -11,10 +11,6 @@ import { stringify } from '../../../common/util/stringify'
|
|
|
11
11
|
export class DT {
|
|
12
12
|
constructor (agentIdentifier) {
|
|
13
13
|
this.agentIdentifier = agentIdentifier
|
|
14
|
-
// Binds this class instance context to the following fn used in an external module (exported);
|
|
15
|
-
// Alternatively, can make them class field arrow functions, but requires experimental features/plugin for eslint.
|
|
16
|
-
this.generateTracePayload = this.generateTracePayload.bind(this)
|
|
17
|
-
this.shouldGenerateTrace = this.shouldGenerateTrace.bind(this)
|
|
18
14
|
}
|
|
19
15
|
|
|
20
16
|
generateTracePayload (parsedOrigin) {
|
|
@@ -22,14 +18,14 @@ export class DT {
|
|
|
22
18
|
return null
|
|
23
19
|
}
|
|
24
20
|
|
|
25
|
-
var
|
|
26
|
-
if (!
|
|
21
|
+
var loaderConfig = getLoaderConfig(this.agentIdentifier)
|
|
22
|
+
if (!loaderConfig) {
|
|
27
23
|
return null
|
|
28
24
|
}
|
|
29
25
|
|
|
30
|
-
var accountId = (
|
|
31
|
-
var agentId = (
|
|
32
|
-
var trustKey = (
|
|
26
|
+
var accountId = (loaderConfig.accountID || '').toString() || null
|
|
27
|
+
var agentId = (loaderConfig.agentID || '').toString() || null
|
|
28
|
+
var trustKey = (loaderConfig.trustKey || '').toString() || null
|
|
33
29
|
|
|
34
30
|
if (!accountId || !agentId) {
|
|
35
31
|
return null
|
|
@@ -40,9 +36,9 @@ export class DT {
|
|
|
40
36
|
var timestamp = Date.now()
|
|
41
37
|
|
|
42
38
|
var payload = {
|
|
43
|
-
spanId
|
|
44
|
-
traceId
|
|
45
|
-
timestamp
|
|
39
|
+
spanId,
|
|
40
|
+
traceId,
|
|
41
|
+
timestamp
|
|
46
42
|
}
|
|
47
43
|
|
|
48
44
|
if (parsedOrigin.sameOrigin ||
|