@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,6 @@ exports.activateFeatures = activateFeatures;
|
|
|
7
7
|
exports.activatedFeatures = void 0;
|
|
8
8
|
var _contextualEe = require("../event-emitter/contextual-ee");
|
|
9
9
|
var _handle = require("../event-emitter/handle");
|
|
10
|
-
var _drain = require("../drain/drain");
|
|
11
10
|
var _features = require("../../loaders/features/features");
|
|
12
11
|
/*
|
|
13
12
|
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
@@ -21,24 +20,24 @@ const bucketMap = {
|
|
|
21
20
|
spa: [_features.FEATURE_NAMES.spa],
|
|
22
21
|
sr: [_features.FEATURE_NAMES.sessionReplay, _features.FEATURE_NAMES.sessionTrace]
|
|
23
22
|
};
|
|
23
|
+
const sentIds = new Set();
|
|
24
24
|
|
|
25
25
|
/** Note that this function only processes each unique flag ONCE, with the first occurrence of each flag and numeric value determining its switch on/off setting. */
|
|
26
26
|
function activateFeatures(flags, agentIdentifier) {
|
|
27
27
|
const sharedEE = _contextualEe.ee.get(agentIdentifier);
|
|
28
28
|
if (!(flags && typeof flags === 'object')) return;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
});
|
|
29
|
+
if (!sentIds.has(agentIdentifier)) {
|
|
30
|
+
Object.entries(flags).forEach(_ref => {
|
|
31
|
+
let [flag, num] = _ref;
|
|
32
|
+
if (bucketMap[flag]) {
|
|
33
|
+
bucketMap[flag].forEach(feat => {
|
|
34
|
+
if (!num) (0, _handle.handle)('block-' + flag, [], undefined, feat, sharedEE);else (0, _handle.handle)('feat-' + flag, [], undefined, feat, sharedEE);
|
|
35
|
+
(0, _handle.handle)('rumresp-' + flag, [Boolean(num)], undefined, feat, sharedEE); // this is a duplicate of feat-/block- but makes awaiting for 1 event easier than 2
|
|
36
|
+
});
|
|
37
|
+
} else if (num) (0, _handle.handle)('feat-' + flag, [], undefined, undefined, sharedEE); // not sure what other flags are overlooked, but there's a test for ones not in the map --
|
|
38
|
+
activatedFeatures[flag] = Boolean(num);
|
|
39
|
+
});
|
|
40
|
+
}
|
|
42
41
|
|
|
43
42
|
// Let the features waiting on their respective flags know that RUM response was received and that any missing flags are interpreted as bad entitlement / "off".
|
|
44
43
|
// Hence, those features will not be hanging forever if their flags aren't included in the response.
|
|
@@ -48,7 +47,7 @@ function activateFeatures(flags, agentIdentifier) {
|
|
|
48
47
|
activatedFeatures[flag] = false;
|
|
49
48
|
}
|
|
50
49
|
});
|
|
51
|
-
|
|
50
|
+
sentIds.add(agentIdentifier);
|
|
52
51
|
}
|
|
53
52
|
const activatedFeatures = {};
|
|
54
53
|
exports.activatedFeatures = activatedFeatures;
|
|
@@ -39,7 +39,9 @@ function debounce(func) {
|
|
|
39
39
|
}
|
|
40
40
|
if (leading && timer === undefined) {
|
|
41
41
|
func.apply(_this, args);
|
|
42
|
-
timer = setTimeout(() =>
|
|
42
|
+
timer = setTimeout(() => {
|
|
43
|
+
timer = clearTimeout(timer);
|
|
44
|
+
}, timeout);
|
|
43
45
|
}
|
|
44
46
|
if (!leading) {
|
|
45
47
|
clearTimeout(timer);
|
|
@@ -61,11 +61,9 @@ function validateRules(rules) {
|
|
|
61
61
|
invalidRegexDetected = true;
|
|
62
62
|
}
|
|
63
63
|
var replacement = rules[i].replacement;
|
|
64
|
-
if (replacement) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
invalidReplacementDetected = true;
|
|
68
|
-
}
|
|
64
|
+
if (replacement && typeof replacement !== 'string') {
|
|
65
|
+
(0, _console.warn)('An obfuscation replacement rule contains a "replacement" value with an invalid type (must be a string)');
|
|
66
|
+
invalidReplacementDetected = true;
|
|
69
67
|
}
|
|
70
68
|
}
|
|
71
69
|
return !invalidReplacementDetected && !invalidRegexDetected;
|
|
@@ -26,6 +26,7 @@ function applyFnToProps(obj, fn) {
|
|
|
26
26
|
if (typeof obj[property] === 'object') {
|
|
27
27
|
applyFnToProps(obj[property], fn, type, ignoreKeys);
|
|
28
28
|
} else {
|
|
29
|
+
// eslint-disable-next-line valid-typeof
|
|
29
30
|
if (typeof obj[property] === type && !ignoreKeys.includes(property)) obj[property] = fn(obj[property]);
|
|
30
31
|
}
|
|
31
32
|
});
|
|
@@ -20,11 +20,10 @@ function subscribeToVisibilityChange(cb) {
|
|
|
20
20
|
let capture = arguments.length > 2 ? arguments[2] : undefined;
|
|
21
21
|
let abortSignal = arguments.length > 3 ? arguments[3] : undefined;
|
|
22
22
|
(0, _eventListenerOpts.documentAddEventListener)('visibilitychange', handleVisibilityChange, capture, abortSignal);
|
|
23
|
-
return;
|
|
24
23
|
function handleVisibilityChange() {
|
|
25
24
|
if (toHiddenOnly) {
|
|
26
25
|
// trigger cb on change to hidden state only
|
|
27
|
-
if (document.visibilityState
|
|
26
|
+
if (document.visibilityState === 'hidden') cb();
|
|
28
27
|
return;
|
|
29
28
|
}
|
|
30
29
|
cb(document.visibilityState);
|
|
@@ -20,9 +20,10 @@ var _runtime = require("../constants/runtime");
|
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
22
|
const wrapped = {};
|
|
23
|
-
const XHR = XMLHttpRequest;
|
|
23
|
+
const XHR = _runtime.globalScope.XMLHttpRequest;
|
|
24
24
|
const ADD_EVENT_LISTENER = 'addEventListener';
|
|
25
25
|
const REMOVE_EVENT_LISTENER = 'removeEventListener';
|
|
26
|
+
const flag = "nr@wrapped:".concat(_contextualEe.contextId);
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
29
|
* Wraps `addEventListener` and `removeEventListener` on: global scope; the prototype of `XMLHttpRequest`, and
|
|
@@ -51,7 +52,7 @@ function wrapEvents(sharedEE) {
|
|
|
51
52
|
if (originalListener === null || typeof originalListener !== 'function' && typeof originalListener !== 'object') {
|
|
52
53
|
return;
|
|
53
54
|
}
|
|
54
|
-
var wrapped = (0, _getOrSet.getOrSet)(originalListener,
|
|
55
|
+
var wrapped = (0, _getOrSet.getOrSet)(originalListener, flag, function () {
|
|
55
56
|
var listener = {
|
|
56
57
|
object: wrapHandleEvent,
|
|
57
58
|
function: originalListener
|
|
@@ -7,7 +7,6 @@ exports.scopedEE = scopedEE;
|
|
|
7
7
|
exports.wrapFetch = wrapFetch;
|
|
8
8
|
var _contextualEe = require("../event-emitter/contextual-ee");
|
|
9
9
|
var _runtime = require("../constants/runtime");
|
|
10
|
-
var _wrapFunction = require("./wrap-function");
|
|
11
10
|
/*
|
|
12
11
|
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
13
12
|
* SPDX-License-Identifier: Apache-2.0
|
|
@@ -23,7 +22,6 @@ var bodyMethods = ['arrayBuffer', 'blob', 'json', 'text', 'formData'];
|
|
|
23
22
|
var Req = _runtime.globalScope.Request;
|
|
24
23
|
var Res = _runtime.globalScope.Response;
|
|
25
24
|
var proto = 'prototype';
|
|
26
|
-
var ctxId = 'nr@context';
|
|
27
25
|
const wrapped = {};
|
|
28
26
|
|
|
29
27
|
/**
|
|
@@ -80,7 +78,7 @@ function wrapFetch(sharedEE) {
|
|
|
80
78
|
// we are wrapping args in an array so we can preserve the reference
|
|
81
79
|
ee.emit(prefix + 'before-start', [args], ctx);
|
|
82
80
|
var dtPayload;
|
|
83
|
-
if (ctx[
|
|
81
|
+
if (ctx[_contextualEe.contextId] && ctx[_contextualEe.contextId].dt) dtPayload = ctx[_contextualEe.contextId].dt;
|
|
84
82
|
var origPromiseFromFetch = fn.apply(this, args);
|
|
85
83
|
ee.emit(prefix + 'start', [args, dtPayload], origPromiseFromFetch);
|
|
86
84
|
|
|
@@ -5,9 +5,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.createWrapperWithEmitter = createWrapperWithEmitter;
|
|
7
7
|
exports.flag = exports.default = void 0;
|
|
8
|
-
exports.wrapFunction = wrapFunction;
|
|
9
|
-
exports.wrapInPlace = wrapInPlace;
|
|
10
8
|
var _contextualEe = require("../event-emitter/contextual-ee");
|
|
9
|
+
var _bundleId = require("../ids/bundle-id");
|
|
11
10
|
/*
|
|
12
11
|
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
13
12
|
* SPDX-License-Identifier: Apache-2.0
|
|
@@ -16,7 +15,7 @@ var _contextualEe = require("../event-emitter/contextual-ee");
|
|
|
16
15
|
* @file Provides helper functions for wrapping functions in various scenarios.
|
|
17
16
|
*/
|
|
18
17
|
|
|
19
|
-
const flag =
|
|
18
|
+
const flag = "nr@original:".concat(_bundleId.bundleId);
|
|
20
19
|
|
|
21
20
|
/**
|
|
22
21
|
* A convenience alias of `hasOwnProperty`.
|
|
@@ -110,25 +109,23 @@ function createWrapperWithEmitter(emitter, always) {
|
|
|
110
109
|
|
|
111
110
|
/**
|
|
112
111
|
* Creates wrapper functions around each of an array of methods on a specified object.
|
|
113
|
-
* @param {Object} obj
|
|
114
|
-
* @param {string[]} methods
|
|
115
|
-
* @param {string} [prefix='']
|
|
116
|
-
*
|
|
117
|
-
* @param {function|object} [getContext]
|
|
118
|
-
*
|
|
119
|
-
* @param {boolean} [bubble=false]
|
|
120
|
-
*
|
|
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).
|
|
121
120
|
*/
|
|
122
121
|
function inPlace(obj, methods, prefix, getContext, bubble) {
|
|
123
122
|
if (!prefix) prefix = '';
|
|
123
|
+
|
|
124
124
|
// If prefix starts with '-' set this boolean to add the method name to the prefix before passing each one to wrap.
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
for (i = 0; i < methods.length; i++) {
|
|
130
|
-
method = methods[i];
|
|
131
|
-
fn = obj[method];
|
|
125
|
+
const prependMethodPrefix = prefix.charAt(0) === '-';
|
|
126
|
+
for (let i = 0; i < methods.length; i++) {
|
|
127
|
+
const method = methods[i];
|
|
128
|
+
const fn = obj[method];
|
|
132
129
|
|
|
133
130
|
// Unless fn is both wrappable and unwrapped, bail so we don't add extra properties with undefined values.
|
|
134
131
|
if (notWrappable(fn)) continue;
|
|
@@ -222,32 +219,4 @@ function copy(from, to, emitter) {
|
|
|
222
219
|
*/
|
|
223
220
|
function notWrappable(fn) {
|
|
224
221
|
return !(fn && fn instanceof Function && fn.apply && !fn[flag]);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
/**
|
|
228
|
-
* Creates a wrapped version of a function using a specified wrapper function. The new wrapped function references the
|
|
229
|
-
* original function. Also copies the properties of the original function to the wrapped function.
|
|
230
|
-
* @param {function} fn - A function to be wrapped.
|
|
231
|
-
* @param {function} wrapper - A higher order function that returns a new function, which executes the function passed
|
|
232
|
-
* to the higher order function as an argument.
|
|
233
|
-
* @returns {function} A wrapped function with an internal reference to the original function.
|
|
234
|
-
*/
|
|
235
|
-
function wrapFunction(fn, wrapper) {
|
|
236
|
-
var wrapped = wrapper(fn);
|
|
237
|
-
wrapped[flag] = fn;
|
|
238
|
-
copy(fn, wrapped, _contextualEe.ee);
|
|
239
|
-
return wrapped;
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
/**
|
|
243
|
-
* Replaces a function with a wrapped version of itself. To preserve object references, rather than taking the function
|
|
244
|
-
* itself as an argument, takes the object on which the particular named function is a property.
|
|
245
|
-
* @param {Object} obj - The object on which the named function is a property.
|
|
246
|
-
* @param {string} fnName - The name of the function to be wrapped.
|
|
247
|
-
* @param {function} wrapper - A higher order function that returns a new function, which executes the function passed
|
|
248
|
-
* to the higher order function as an argument.
|
|
249
|
-
*/
|
|
250
|
-
function wrapInPlace(obj, fnName, wrapper) {
|
|
251
|
-
var fn = obj[fnName];
|
|
252
|
-
obj[fnName] = wrapFunction(fn, wrapper);
|
|
253
222
|
}
|
|
@@ -7,7 +7,6 @@ exports.scopedEE = scopedEE;
|
|
|
7
7
|
exports.wrapMutation = wrapMutation;
|
|
8
8
|
var _contextualEe = require("../event-emitter/contextual-ee");
|
|
9
9
|
var _wrapFunction = require("./wrap-function");
|
|
10
|
-
var _config = require("../config/config");
|
|
11
10
|
var _runtime = require("../constants/runtime");
|
|
12
11
|
/*
|
|
13
12
|
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
@@ -36,7 +35,7 @@ function wrapMutation(sharedEE) {
|
|
|
36
35
|
wrapped[ee.debugId] = true; // otherwise, first feature to wrap mutations
|
|
37
36
|
|
|
38
37
|
var wrapFn = (0, _wrapFunction.createWrapperWithEmitter)(ee);
|
|
39
|
-
var OriginalObserver =
|
|
38
|
+
var OriginalObserver = _runtime.globalScope.MutationObserver;
|
|
40
39
|
if (OriginalObserver) {
|
|
41
40
|
window.MutationObserver = function WrappedMutationObserver(cb) {
|
|
42
41
|
if (this instanceof OriginalObserver) {
|
|
@@ -7,7 +7,6 @@ exports.scopedEE = scopedEE;
|
|
|
7
7
|
exports.wrapPromise = wrapPromise;
|
|
8
8
|
var _wrapFunction = require("./wrap-function");
|
|
9
9
|
var _contextualEe = require("../event-emitter/contextual-ee");
|
|
10
|
-
var _config = require("../config/config");
|
|
11
10
|
var _runtime = require("../constants/runtime");
|
|
12
11
|
/*
|
|
13
12
|
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
@@ -35,9 +34,9 @@ function wrapPromise(sharedEE) {
|
|
|
35
34
|
if (wrapped[promiseEE.debugId]) return promiseEE;
|
|
36
35
|
wrapped[promiseEE.debugId] = true; // otherwise, first feature to wrap promise
|
|
37
36
|
|
|
38
|
-
var getContext =
|
|
37
|
+
var getContext = promiseEE.context;
|
|
39
38
|
var promiseWrapper = (0, _wrapFunction.createWrapperWithEmitter)(promiseEE);
|
|
40
|
-
var prevPromiseObj =
|
|
39
|
+
var prevPromiseObj = _runtime.globalScope.Promise;
|
|
41
40
|
if (prevPromiseObj) {
|
|
42
41
|
// ensure there's a Promise API (native or otherwise) to even wrap
|
|
43
42
|
wrap();
|
|
@@ -9,7 +9,6 @@ var _wrapEvents = require("./wrap-events");
|
|
|
9
9
|
var _contextualEe = require("../event-emitter/contextual-ee");
|
|
10
10
|
var _eventListenerOpts = require("../event-listener/event-listener-opts");
|
|
11
11
|
var _wrapFunction = require("./wrap-function");
|
|
12
|
-
var _config = require("../config/config");
|
|
13
12
|
var _runtime = require("../constants/runtime");
|
|
14
13
|
var _console = require("../util/console");
|
|
15
14
|
/*
|
|
@@ -42,32 +41,28 @@ function wrapXhr(sharedEE) {
|
|
|
42
41
|
|
|
43
42
|
(0, _wrapEvents.wrapEvents)(baseEE); // wrap-events patches XMLHttpRequest.prototype.addEventListener for us
|
|
44
43
|
var wrapFn = (0, _wrapFunction.createWrapperWithEmitter)(ee);
|
|
45
|
-
var OrigXHR =
|
|
46
|
-
var MutationObserver =
|
|
47
|
-
var Promise =
|
|
48
|
-
var setImmediate =
|
|
44
|
+
var OrigXHR = _runtime.globalScope.XMLHttpRequest;
|
|
45
|
+
var MutationObserver = _runtime.globalScope.MutationObserver;
|
|
46
|
+
var Promise = _runtime.globalScope.Promise;
|
|
47
|
+
var setImmediate = _runtime.globalScope.setInterval;
|
|
49
48
|
var READY_STATE_CHANGE = 'readystatechange';
|
|
50
49
|
var handlers = ['onload', 'onerror', 'onabort', 'onloadstart', 'onloadend', 'onprogress', 'ontimeout'];
|
|
51
50
|
var pendingXhrs = [];
|
|
52
|
-
var activeListeners = _runtime.globalScope.XMLHttpRequest.listeners;
|
|
53
51
|
var XHR = _runtime.globalScope.XMLHttpRequest = newXHR;
|
|
54
52
|
function newXHR(opts) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
53
|
+
const xhr = new OrigXHR(opts);
|
|
54
|
+
const context = ee.context(xhr);
|
|
55
|
+
try {
|
|
56
|
+
ee.emit('new-xhr', [xhr], context);
|
|
57
|
+
xhr.addEventListener(READY_STATE_CHANGE, wrapXHR(context), (0, _eventListenerOpts.eventListenerOpts)(false));
|
|
58
|
+
} catch (e) {
|
|
59
|
+
(0, _console.warn)('An error occurred while intercepting XHR', e);
|
|
58
60
|
try {
|
|
59
|
-
ee.emit('
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
(0, _console.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
|
copy(OrigXHR, XHR);
|
|
@@ -81,14 +76,15 @@ function wrapXhr(sharedEE) {
|
|
|
81
76
|
function wrapOnreadystatechange(args, xhr) {
|
|
82
77
|
wrapFn.inPlace(xhr, ['onreadystatechange'], 'fn-', getObject);
|
|
83
78
|
}
|
|
84
|
-
function wrapXHR() {
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
79
|
+
function wrapXHR(ctx) {
|
|
80
|
+
return function () {
|
|
81
|
+
var xhr = this;
|
|
82
|
+
if (xhr.readyState > 3 && !ctx.resolved) {
|
|
83
|
+
ctx.resolved = true;
|
|
84
|
+
ee.emit('xhr-resolved', [], xhr);
|
|
85
|
+
}
|
|
86
|
+
wrapFn.inPlace(xhr, handlers, 'fn-', getObject);
|
|
87
|
+
};
|
|
92
88
|
}
|
|
93
89
|
|
|
94
90
|
// Wrapping the onreadystatechange property of XHRs takes some special tricks.
|
|
@@ -12,7 +12,6 @@ var _config = require("../../../common/config/config");
|
|
|
12
12
|
var _harvestScheduler = require("../../../common/harvest/harvest-scheduler");
|
|
13
13
|
var _denyList = require("../../../common/deny-list/deny-list");
|
|
14
14
|
var _constants = require("../constants");
|
|
15
|
-
var _drain = require("../../../common/drain/drain");
|
|
16
15
|
var _features = require("../../../loaders/features/features");
|
|
17
16
|
var _constants2 = require("../../metrics/constants");
|
|
18
17
|
var _aggregateBase = require("../../utils/aggregate-base");
|
|
@@ -29,7 +28,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
|
|
|
29
28
|
const allAjaxIsEnabled = agentInit.ajax.enabled !== false;
|
|
30
29
|
(0, _registerHandler.registerHandler)('xhr', storeXhr, this.featureName, this.ee);
|
|
31
30
|
if (!allAjaxIsEnabled) {
|
|
32
|
-
|
|
31
|
+
this.drain();
|
|
33
32
|
return; // feature will only collect timeslice metrics & ajax trace nodes if it's not fully enabled
|
|
34
33
|
}
|
|
35
34
|
|
|
@@ -71,8 +70,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
|
|
|
71
70
|
ee.on("drain-".concat(this.featureName), () => {
|
|
72
71
|
scheduler.startTimer(harvestTimeSeconds);
|
|
73
72
|
});
|
|
74
|
-
|
|
75
|
-
return;
|
|
73
|
+
this.drain();
|
|
76
74
|
function storeXhr(params, metrics, startTime, endTime, type) {
|
|
77
75
|
metrics.time = startTime;
|
|
78
76
|
|
|
@@ -104,9 +102,9 @@ class Aggregate extends _aggregateBase.AggregateBase {
|
|
|
104
102
|
path: params.pathname,
|
|
105
103
|
requestSize: metrics.txSize,
|
|
106
104
|
responseSize: metrics.rxSize,
|
|
107
|
-
type
|
|
108
|
-
startTime
|
|
109
|
-
endTime
|
|
105
|
+
type,
|
|
106
|
+
startTime,
|
|
107
|
+
endTime,
|
|
110
108
|
callbackDuration: metrics.cbTime
|
|
111
109
|
};
|
|
112
110
|
if (xhrContext.dt) {
|
|
@@ -17,22 +17,18 @@ var _stringify = require("../../../common/util/stringify");
|
|
|
17
17
|
class DT {
|
|
18
18
|
constructor(agentIdentifier) {
|
|
19
19
|
this.agentIdentifier = agentIdentifier;
|
|
20
|
-
// Binds this class instance context to the following fn used in an external module (exported);
|
|
21
|
-
// Alternatively, can make them class field arrow functions, but requires experimental features/plugin for eslint.
|
|
22
|
-
this.generateTracePayload = this.generateTracePayload.bind(this);
|
|
23
|
-
this.shouldGenerateTrace = this.shouldGenerateTrace.bind(this);
|
|
24
20
|
}
|
|
25
21
|
generateTracePayload(parsedOrigin) {
|
|
26
22
|
if (!this.shouldGenerateTrace(parsedOrigin)) {
|
|
27
23
|
return null;
|
|
28
24
|
}
|
|
29
|
-
var
|
|
30
|
-
if (!
|
|
25
|
+
var loaderConfig = (0, _config.getLoaderConfig)(this.agentIdentifier);
|
|
26
|
+
if (!loaderConfig) {
|
|
31
27
|
return null;
|
|
32
28
|
}
|
|
33
|
-
var accountId = (
|
|
34
|
-
var agentId = (
|
|
35
|
-
var trustKey = (
|
|
29
|
+
var accountId = (loaderConfig.accountID || '').toString() || null;
|
|
30
|
+
var agentId = (loaderConfig.agentID || '').toString() || null;
|
|
31
|
+
var trustKey = (loaderConfig.trustKey || '').toString() || null;
|
|
36
32
|
if (!accountId || !agentId) {
|
|
37
33
|
return null;
|
|
38
34
|
}
|
|
@@ -40,9 +36,9 @@ class DT {
|
|
|
40
36
|
var traceId = (0, _uniqueId.generateTraceId)();
|
|
41
37
|
var timestamp = Date.now();
|
|
42
38
|
var payload = {
|
|
43
|
-
spanId
|
|
44
|
-
traceId
|
|
45
|
-
timestamp
|
|
39
|
+
spanId,
|
|
40
|
+
traceId,
|
|
41
|
+
timestamp
|
|
46
42
|
};
|
|
47
43
|
if (parsedOrigin.sameOrigin || this.isAllowedOrigin(parsedOrigin) && this.useTraceContextHeadersForCors()) {
|
|
48
44
|
payload.traceContextParentHeader = this.generateTraceContextParentHeader(spanId, traceId);
|
|
@@ -26,7 +26,7 @@ var _features = require("../../../loaders/features/features");
|
|
|
26
26
|
var handlers = ['load', 'error', 'abort', 'timeout'];
|
|
27
27
|
var handlersLen = handlers.length;
|
|
28
28
|
var origRequest = _config.originals.REQ;
|
|
29
|
-
var origXHR =
|
|
29
|
+
var origXHR = _config.originals.XHR;
|
|
30
30
|
class Instrument extends _instrumentBase.InstrumentBase {
|
|
31
31
|
static featureName = _constants.FEATURE_NAME;
|
|
32
32
|
constructor(agentIdentifier, aggregator) {
|
|
@@ -37,6 +37,38 @@ class Instrument extends _instrumentBase.InstrumentBase {
|
|
|
37
37
|
if (!(0, _config.getRuntime)(agentIdentifier).xhrWrappable) return;
|
|
38
38
|
this.dt = new _distributedTracing.DT(agentIdentifier);
|
|
39
39
|
this.handler = (type, args, ctx, group) => (0, _handle.handle)(type, args, ctx, group, this.ee);
|
|
40
|
+
|
|
41
|
+
// this is a best (but imperfect) effort at capturing AJAX calls that may have fired before the agent was instantiated
|
|
42
|
+
// this could happen because the agent was "improperly" set up (ie, not at the top of the head) or
|
|
43
|
+
// because it was deferred from loading in some way -- e.g. 'deferred' script loading tags or other lazy-loading techniques
|
|
44
|
+
//
|
|
45
|
+
// it is "imperfect" because we cannot capture the following with the API vs wrapping the events directly:
|
|
46
|
+
// * requestBodySize - (txSize -- request body size)
|
|
47
|
+
// * method - request type (GET, POST, etc)
|
|
48
|
+
// * callbackDuration - (cbTime -- sum of resulting callback time)
|
|
49
|
+
try {
|
|
50
|
+
const initiators = {
|
|
51
|
+
xmlhttprequest: 'xhr',
|
|
52
|
+
fetch: 'fetch',
|
|
53
|
+
beacon: 'beacon'
|
|
54
|
+
};
|
|
55
|
+
_runtime.globalScope?.performance?.getEntriesByType('resource').forEach(resource => {
|
|
56
|
+
if (resource.initiatorType in initiators && resource.responseStatus !== 0) {
|
|
57
|
+
const params = {
|
|
58
|
+
status: resource.responseStatus
|
|
59
|
+
};
|
|
60
|
+
const metrics = {
|
|
61
|
+
rxSize: resource.transferSize,
|
|
62
|
+
duration: Math.floor(resource.duration),
|
|
63
|
+
cbTime: 0
|
|
64
|
+
};
|
|
65
|
+
addUrl(params, resource.name);
|
|
66
|
+
this.handler('xhr', [params, metrics, resource.startTime, resource.responseEnd, initiators[resource.initiatorType]], undefined, _features.FEATURE_NAMES.ajax);
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
} catch (err) {
|
|
70
|
+
// do nothing
|
|
71
|
+
}
|
|
40
72
|
(0, _wrap.wrapFetch)(this.ee);
|
|
41
73
|
(0, _wrap.wrapXhr)(this.ee);
|
|
42
74
|
subscribeToEvents(agentIdentifier, this.ee, this.handler, this.dt);
|
|
@@ -97,9 +129,9 @@ function subscribeToEvents(agentIdentifier, ee, handler, dt) {
|
|
|
97
129
|
this.metrics = {};
|
|
98
130
|
}
|
|
99
131
|
function onOpenXhrEnd(args, xhr) {
|
|
100
|
-
var
|
|
101
|
-
if (
|
|
102
|
-
xhr.setRequestHeader('X-NewRelic-ID',
|
|
132
|
+
var loaderConfig = (0, _config.getLoaderConfig)(agentIdentifier);
|
|
133
|
+
if (loaderConfig.xpid && this.sameOrigin) {
|
|
134
|
+
xhr.setRequestHeader('X-NewRelic-ID', loaderConfig.xpid);
|
|
103
135
|
}
|
|
104
136
|
var payload = dt.generateTracePayload(this.parsedOrigin);
|
|
105
137
|
if (payload) {
|
|
@@ -193,15 +225,25 @@ function subscribeToEvents(agentIdentifier, ee, handler, dt) {
|
|
|
193
225
|
function onFetchBeforeStart(args) {
|
|
194
226
|
var opts = args[1] || {};
|
|
195
227
|
var url;
|
|
196
|
-
// argument is USVString
|
|
197
228
|
if (typeof args[0] === 'string') {
|
|
229
|
+
// argument is USVString
|
|
198
230
|
url = args[0];
|
|
199
|
-
|
|
231
|
+
if (url.length === 0 && _runtime.isBrowserScope) {
|
|
232
|
+
url = '' + _runtime.globalScope.location.href;
|
|
233
|
+
}
|
|
200
234
|
} else if (args[0] && args[0].url) {
|
|
235
|
+
// argument is Request object
|
|
201
236
|
url = args[0].url;
|
|
202
|
-
// argument is URL object
|
|
203
237
|
} else if (_runtime.globalScope?.URL && args[0] && args[0] instanceof URL) {
|
|
238
|
+
// argument is URL object
|
|
204
239
|
url = args[0].href;
|
|
240
|
+
} else if (typeof args[0].toString === 'function') {
|
|
241
|
+
url = args[0].toString();
|
|
242
|
+
}
|
|
243
|
+
if (typeof url !== 'string' || url.length === 0) {
|
|
244
|
+
// Short-circuit DT since we could not determine the URL of the fetch call
|
|
245
|
+
// this is very unlikely to happen
|
|
246
|
+
return;
|
|
205
247
|
}
|
|
206
248
|
if (url) {
|
|
207
249
|
this.parsedOrigin = (0, _parseUrl.parseUrl)(url);
|
|
@@ -211,7 +253,11 @@ function subscribeToEvents(agentIdentifier, ee, handler, dt) {
|
|
|
211
253
|
if (!payload || !payload.newrelicHeader && !payload.traceContextParentHeader) {
|
|
212
254
|
return;
|
|
213
255
|
}
|
|
214
|
-
if (
|
|
256
|
+
if (args[0] && args[0].headers) {
|
|
257
|
+
if (addHeaders(args[0].headers, payload)) {
|
|
258
|
+
this.dt = payload;
|
|
259
|
+
}
|
|
260
|
+
} else {
|
|
215
261
|
var clone = {};
|
|
216
262
|
for (var key in opts) {
|
|
217
263
|
clone[key] = opts[key];
|
|
@@ -225,10 +271,6 @@ function subscribeToEvents(agentIdentifier, ee, handler, dt) {
|
|
|
225
271
|
} else {
|
|
226
272
|
args.push(clone);
|
|
227
273
|
}
|
|
228
|
-
} else if (args[0] && args[0].headers) {
|
|
229
|
-
if (addHeaders(args[0].headers, payload)) {
|
|
230
|
-
this.dt = payload;
|
|
231
|
-
}
|
|
232
274
|
}
|
|
233
275
|
function addHeaders(headersObj, payload) {
|
|
234
276
|
var added = false;
|
|
@@ -271,7 +313,7 @@ function subscribeToEvents(agentIdentifier, ee, handler, dt) {
|
|
|
271
313
|
|
|
272
314
|
// we capture failed call as status 0, the actual error is ignored
|
|
273
315
|
// eslint-disable-next-line handle-callback-err
|
|
274
|
-
function onFetchDone(
|
|
316
|
+
function onFetchDone(_, res) {
|
|
275
317
|
this.endTime = (0, _now.now)();
|
|
276
318
|
if (!this.params) {
|
|
277
319
|
this.params = {};
|
|
@@ -312,17 +354,6 @@ function subscribeToEvents(agentIdentifier, ee, handler, dt) {
|
|
|
312
354
|
metrics.cbTime = this.cbTime;
|
|
313
355
|
handler('xhr', [params, metrics, this.startTime, this.endTime, 'xhr'], this, _features.FEATURE_NAMES.ajax);
|
|
314
356
|
}
|
|
315
|
-
function addUrl(ctx, url) {
|
|
316
|
-
var parsed = (0, _parseUrl.parseUrl)(url);
|
|
317
|
-
var params = ctx.params;
|
|
318
|
-
params.hostname = parsed.hostname;
|
|
319
|
-
params.port = parsed.port;
|
|
320
|
-
params.protocol = parsed.protocol;
|
|
321
|
-
params.host = parsed.hostname + ':' + parsed.port;
|
|
322
|
-
params.pathname = parsed.pathname;
|
|
323
|
-
ctx.parsedOrigin = parsed;
|
|
324
|
-
ctx.sameOrigin = parsed.sameOrigin;
|
|
325
|
-
}
|
|
326
357
|
function captureXhrData(ctx, xhr) {
|
|
327
358
|
ctx.params.status = xhr.status;
|
|
328
359
|
var size = (0, _responseSize.responseSizeFromXhr)(xhr, ctx.lastSize);
|
|
@@ -335,4 +366,15 @@ function subscribeToEvents(agentIdentifier, ee, handler, dt) {
|
|
|
335
366
|
}
|
|
336
367
|
ctx.loadCaptureCalled = true;
|
|
337
368
|
}
|
|
369
|
+
}
|
|
370
|
+
function addUrl(ctx, url) {
|
|
371
|
+
var parsed = (0, _parseUrl.parseUrl)(url);
|
|
372
|
+
var params = ctx.params || ctx;
|
|
373
|
+
params.hostname = parsed.hostname;
|
|
374
|
+
params.port = parsed.port;
|
|
375
|
+
params.protocol = parsed.protocol;
|
|
376
|
+
params.host = parsed.hostname + ':' + parsed.port;
|
|
377
|
+
params.pathname = parsed.pathname;
|
|
378
|
+
ctx.parsedOrigin = parsed;
|
|
379
|
+
ctx.sameOrigin = parsed.sameOrigin;
|
|
338
380
|
}
|
|
@@ -69,8 +69,8 @@ var debug = false;
|
|
|
69
69
|
var classNameRegex = /function (.+?)\s*\(/;
|
|
70
70
|
var chrome = /^\s*at (?:((?:\[object object\])?(?:[^(]*\([^)]*\))*[^()]*(?: \[as \S+\])?) )?\(?((?:file|http|https|chrome-extension):.*?)?:(\d+)(?::(\d+))?\)?\s*$/i;
|
|
71
71
|
var gecko = /^\s*(?:(\S*|global code)(?:\(.*?\))?@)?((?:file|http|https|chrome|safari-extension).*?):(\d+)(?::(\d+))?\s*$/i;
|
|
72
|
-
var
|
|
73
|
-
var
|
|
72
|
+
var chromeEval = /^\s*at .+ \(eval at \S+ \((?:(?:file|http|https):[^)]+)?\)(?:, [^:]*:\d+:\d+)?\)$/i;
|
|
73
|
+
var ieEval = /^\s*at Function code \(Function code:\d+:\d+\)\s*/i;
|
|
74
74
|
|
|
75
75
|
/**
|
|
76
76
|
* Represents an error with a stack trace.
|
|
@@ -204,7 +204,7 @@ function getStackElement(line) {
|
|
|
204
204
|
column: parts[4] ? +parts[4] : null
|
|
205
205
|
};
|
|
206
206
|
}
|
|
207
|
-
if (line.match(
|
|
207
|
+
if (line.match(chromeEval) || line.match(ieEval) || line === 'anonymous') {
|
|
208
208
|
return {
|
|
209
209
|
func: 'evaluated code'
|
|
210
210
|
};
|
|
@@ -249,7 +249,7 @@ function computeStackTraceBySourceAndLine(ex) {
|
|
|
249
249
|
mode: 'sourceline',
|
|
250
250
|
name: className,
|
|
251
251
|
message: ex.message,
|
|
252
|
-
stackString
|
|
252
|
+
stackString,
|
|
253
253
|
frames: [{
|
|
254
254
|
url: canonicalUrl,
|
|
255
255
|
line: ex.line,
|