@newrelic/browser-agent 1.232.1 → 1.233.1
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/cdn/experimental.js +27 -0
- package/dist/cjs/cdn/polyfills.js +5 -2
- package/dist/cjs/common/config/state/configurable.js +15 -26
- package/dist/cjs/common/config/state/info.js +1 -1
- package/dist/cjs/common/config/state/init.js +101 -56
- package/dist/cjs/common/config/state/loader-config.js +1 -1
- package/dist/cjs/common/config/state/runtime.js +1 -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/drain/drain.js +1 -1
- package/dist/cjs/common/harvest/harvest-scheduler.js +43 -8
- package/dist/cjs/common/harvest/harvest-scheduler.test.js +39 -0
- package/dist/cjs/common/harvest/harvest.js +106 -55
- package/dist/cjs/common/session/session-entity.js +35 -22
- package/dist/cjs/common/session/session-entity.test.js +73 -49
- package/dist/cjs/common/timer/interaction-timer.js +9 -12
- package/dist/cjs/common/url/protocol.test.js +0 -1
- package/dist/cjs/common/util/feature-flags.js +2 -1
- package/dist/cjs/common/util/submit-data.js +57 -18
- package/dist/cjs/common/wrap/wrap-fetch.js +1 -1
- package/dist/cjs/common/wrap/wrap-function.js +1 -1
- package/dist/cjs/common/wrap/wrap-promise.js +1 -1
- package/dist/cjs/features/ajax/aggregate/index.js +2 -2
- package/dist/cjs/features/jserrors/aggregate/index.js +7 -5
- package/dist/cjs/features/metrics/aggregate/framework-detection.js +67 -0
- package/dist/cjs/features/metrics/aggregate/framework-detection.test.js +137 -0
- package/dist/cjs/features/metrics/aggregate/index.js +7 -3
- package/dist/cjs/features/metrics/aggregate/polyfill-detection.es5.js +14 -0
- package/dist/cjs/features/metrics/aggregate/polyfill-detection.es5.test.js +17 -0
- package/dist/cjs/features/metrics/aggregate/polyfill-detection.js +53 -0
- package/dist/cjs/features/metrics/aggregate/polyfill-detection.test.js +165 -0
- package/dist/cjs/features/page_action/aggregate/index.js +2 -2
- package/dist/cjs/features/page_view_event/aggregate/index.js +6 -3
- package/dist/cjs/features/page_view_timing/aggregate/index.js +2 -2
- package/dist/cjs/features/session_replay/aggregate/index.js +336 -0
- package/dist/cjs/features/session_replay/constants.js +9 -0
- package/dist/cjs/features/session_replay/index.js +12 -0
- package/dist/cjs/features/session_replay/instrument/index.js +29 -0
- package/dist/cjs/features/session_trace/aggregate/index.js +163 -162
- package/dist/cjs/features/session_trace/constants.js +2 -9
- package/dist/cjs/features/session_trace/instrument/index.js +24 -66
- package/dist/cjs/features/spa/aggregate/index.js +2 -2
- package/dist/cjs/features/utils/agent-session.js +1 -2
- package/dist/cjs/features/utils/aggregate-base.js +64 -0
- package/dist/cjs/features/utils/feature-base.js +0 -31
- package/dist/cjs/features/utils/handler-cache.js +3 -4
- package/dist/cjs/features/utils/instrument-base.js +42 -10
- package/dist/cjs/features/utils/{lazy-loader.js → lazy-feature-loader.js} +4 -2
- package/dist/cjs/loaders/agent.js +1 -1
- package/dist/cjs/loaders/api/apiAsync.js +3 -1
- package/dist/cjs/loaders/configure/configure.js +3 -3
- package/dist/cjs/loaders/features/featureDependencies.js +0 -12
- package/dist/cjs/loaders/features/features.js +3 -1
- package/dist/cjs/loaders/micro-agent.js +6 -6
- package/dist/esm/cdn/experimental.js +24 -0
- package/dist/esm/cdn/polyfills.js +5 -2
- package/dist/esm/common/config/state/configurable.js +14 -24
- package/dist/esm/common/config/state/info.js +2 -2
- package/dist/esm/common/config/state/init.js +102 -57
- package/dist/esm/common/config/state/loader-config.js +2 -2
- package/dist/esm/common/config/state/runtime.js +2 -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/drain/drain.js +1 -1
- package/dist/esm/common/harvest/harvest-scheduler.js +43 -8
- package/dist/esm/common/harvest/harvest-scheduler.test.js +37 -0
- package/dist/esm/common/harvest/harvest.js +108 -56
- package/dist/esm/common/session/session-entity.js +35 -22
- package/dist/esm/common/session/session-entity.test.js +73 -49
- package/dist/esm/common/timer/interaction-timer.js +9 -12
- package/dist/esm/common/url/protocol.test.js +0 -1
- package/dist/esm/common/util/feature-flags.js +2 -1
- package/dist/esm/common/util/submit-data.js +57 -18
- package/dist/esm/common/wrap/wrap-fetch.js +1 -1
- package/dist/esm/common/wrap/wrap-function.js +1 -1
- package/dist/esm/common/wrap/wrap-promise.js +1 -1
- package/dist/esm/features/ajax/aggregate/index.js +2 -2
- package/dist/esm/features/jserrors/aggregate/index.js +7 -5
- package/dist/esm/features/metrics/aggregate/framework-detection.js +61 -0
- package/dist/esm/features/metrics/aggregate/framework-detection.test.js +133 -0
- package/dist/esm/features/metrics/aggregate/index.js +7 -3
- package/dist/esm/features/metrics/aggregate/polyfill-detection.es5.js +8 -0
- package/dist/esm/features/metrics/aggregate/polyfill-detection.es5.test.js +15 -0
- package/dist/esm/features/metrics/aggregate/polyfill-detection.js +47 -0
- package/dist/esm/features/metrics/aggregate/polyfill-detection.test.js +163 -0
- package/dist/esm/features/page_action/aggregate/index.js +2 -2
- package/dist/esm/features/page_view_event/aggregate/index.js +6 -3
- package/dist/esm/features/page_view_timing/aggregate/index.js +2 -2
- package/dist/esm/features/session_replay/aggregate/index.js +330 -0
- package/dist/esm/features/session_replay/constants.js +2 -0
- package/dist/esm/features/session_replay/index.js +12 -0
- package/dist/esm/features/session_replay/instrument/index.js +21 -0
- package/dist/esm/features/session_trace/aggregate/index.js +163 -162
- package/dist/esm/features/session_trace/constants.js +1 -5
- package/dist/esm/features/session_trace/instrument/index.js +24 -66
- package/dist/esm/features/spa/aggregate/index.js +2 -2
- package/dist/esm/features/utils/agent-session.js +1 -2
- package/dist/esm/features/utils/aggregate-base.js +57 -0
- package/dist/esm/features/utils/feature-base.js +1 -32
- package/dist/esm/features/utils/handler-cache.js +3 -4
- package/dist/esm/features/utils/instrument-base.js +42 -10
- package/dist/esm/features/utils/{lazy-loader.js → lazy-feature-loader.js} +3 -1
- package/dist/esm/loaders/agent.js +1 -1
- package/dist/esm/loaders/api/apiAsync.js +3 -1
- package/dist/esm/loaders/configure/configure.js +3 -3
- package/dist/esm/loaders/features/featureDependencies.js +0 -11
- package/dist/esm/loaders/features/features.js +3 -1
- package/dist/esm/loaders/micro-agent.js +6 -6
- package/dist/types/cdn/experimental.d.ts +2 -0
- package/dist/types/cdn/experimental.d.ts.map +1 -0
- package/dist/types/common/config/state/configurable.d.ts +1 -3
- package/dist/types/common/config/state/configurable.d.ts.map +1 -1
- 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/harvest/harvest-scheduler.d.ts +26 -3
- package/dist/types/common/harvest/harvest-scheduler.d.ts.map +1 -1
- package/dist/types/common/harvest/harvest.d.ts +37 -34
- package/dist/types/common/harvest/harvest.d.ts.map +1 -1
- package/dist/types/common/session/session-entity.d.ts +6 -3
- package/dist/types/common/session/session-entity.d.ts.map +1 -1
- package/dist/types/common/timer/interaction-timer.d.ts +2 -1
- package/dist/types/common/timer/interaction-timer.d.ts.map +1 -1
- package/dist/types/common/util/feature-flags.d.ts.map +1 -1
- package/dist/types/common/util/submit-data.d.ts +40 -14
- package/dist/types/common/util/submit-data.d.ts.map +1 -1
- package/dist/types/features/ajax/aggregate/index.d.ts +2 -2
- package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/jserrors/aggregate/index.d.ts +2 -2
- package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/metrics/aggregate/framework-detection.d.ts.map +1 -0
- package/dist/types/features/metrics/aggregate/index.d.ts +2 -2
- package/dist/types/features/metrics/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/metrics/aggregate/polyfill-detection.d.ts +6 -0
- package/dist/types/features/metrics/aggregate/polyfill-detection.d.ts.map +1 -0
- package/dist/types/features/metrics/aggregate/polyfill-detection.es5.d.ts +7 -0
- package/dist/types/features/metrics/aggregate/polyfill-detection.es5.d.ts.map +1 -0
- 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 +2 -2
- 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 +2 -2
- package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/session_replay/aggregate/index.d.ts +100 -0
- package/dist/types/features/session_replay/aggregate/index.d.ts.map +1 -0
- package/dist/types/features/session_replay/constants.d.ts +2 -0
- package/dist/types/features/session_replay/constants.d.ts.map +1 -0
- package/dist/types/features/session_replay/index.d.ts +2 -0
- package/dist/types/features/session_replay/index.d.ts.map +1 -0
- package/dist/types/features/session_replay/instrument/index.d.ts +6 -0
- package/dist/types/features/session_replay/instrument/index.d.ts.map +1 -0
- package/dist/types/features/session_trace/aggregate/index.d.ts +8 -57
- package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/session_trace/constants.d.ts +0 -3
- package/dist/types/features/session_trace/constants.d.ts.map +1 -1
- package/dist/types/features/session_trace/instrument/index.d.ts +1 -3
- package/dist/types/features/session_trace/instrument/index.d.ts.map +1 -1
- package/dist/types/features/spa/aggregate/index.d.ts +2 -2
- package/dist/types/features/spa/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/utils/agent-session.d.ts.map +1 -1
- package/dist/types/features/utils/aggregate-base.d.ts +11 -0
- package/dist/types/features/utils/aggregate-base.d.ts.map +1 -0
- package/dist/types/features/utils/feature-base.d.ts +0 -5
- package/dist/types/features/utils/feature-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 +3 -1
- package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
- package/dist/types/features/utils/{lazy-loader.d.ts → lazy-feature-loader.d.ts} +2 -2
- package/dist/types/features/utils/lazy-feature-loader.d.ts.map +1 -0
- package/dist/types/loaders/configure/configure.d.ts.map +1 -1
- package/dist/types/loaders/features/featureDependencies.d.ts +0 -1
- package/dist/types/loaders/features/featureDependencies.d.ts.map +1 -1
- package/dist/types/loaders/features/features.d.ts +1 -0
- package/dist/types/loaders/features/features.d.ts.map +1 -1
- package/package.json +30 -20
- package/src/cdn/experimental.js +36 -0
- package/src/cdn/polyfills.js +4 -1
- package/src/common/config/state/configurable.js +18 -24
- package/src/common/config/state/info.js +2 -2
- package/src/common/config/state/init.js +62 -28
- package/src/common/config/state/loader-config.js +2 -2
- package/src/common/config/state/runtime.js +2 -4
- package/src/common/drain/drain.js +1 -1
- package/src/common/harvest/harvest-scheduler.js +48 -8
- package/src/common/harvest/harvest-scheduler.test.js +25 -0
- package/src/common/harvest/harvest.js +72 -50
- package/src/common/session/session-entity.js +34 -23
- package/src/common/session/session-entity.test.js +57 -51
- package/src/common/timer/interaction-timer.js +9 -12
- package/src/common/url/protocol.test.js +0 -1
- package/src/common/util/feature-flags.js +2 -2
- package/src/common/util/submit-data.js +28 -17
- package/src/common/wrap/wrap-fetch.js +1 -1
- package/src/common/wrap/wrap-function.js +1 -1
- package/src/common/wrap/wrap-promise.js +1 -1
- package/src/features/ajax/aggregate/index.js +2 -2
- package/src/features/jserrors/aggregate/index.js +7 -5
- package/src/features/metrics/aggregate/framework-detection.js +73 -0
- package/src/features/metrics/aggregate/framework-detection.test.js +201 -0
- package/src/features/metrics/aggregate/index.js +8 -3
- package/src/features/metrics/aggregate/polyfill-detection.es5.js +9 -0
- package/src/features/metrics/aggregate/polyfill-detection.es5.test.js +16 -0
- package/src/features/metrics/aggregate/polyfill-detection.js +48 -0
- package/src/features/metrics/aggregate/polyfill-detection.test.js +163 -0
- package/src/features/page_action/aggregate/index.js +2 -2
- package/src/features/page_view_event/aggregate/index.js +5 -5
- package/src/features/page_view_timing/aggregate/index.js +2 -2
- package/src/features/session_replay/aggregate/index.js +319 -0
- package/src/features/session_replay/constants.js +3 -0
- package/src/features/session_replay/index.js +12 -0
- package/src/features/session_replay/instrument/index.js +22 -0
- package/src/features/session_trace/aggregate/index.js +148 -187
- package/src/features/session_trace/constants.js +0 -4
- package/src/features/session_trace/instrument/index.js +17 -69
- package/src/features/spa/aggregate/index.js +2 -2
- package/src/features/utils/agent-session.js +1 -2
- package/src/features/utils/aggregate-base.js +51 -0
- package/src/features/utils/feature-base.js +1 -31
- package/src/features/utils/handler-cache.js +3 -4
- package/src/features/utils/instrument-base.js +40 -8
- package/src/features/utils/{lazy-loader.js → lazy-feature-loader.js} +3 -1
- package/src/loaders/agent.js +1 -1
- package/src/loaders/api/apiAsync.js +1 -1
- package/src/loaders/configure/configure.js +4 -3
- package/src/loaders/features/featureDependencies.js +0 -12
- package/src/loaders/features/features.js +3 -1
- package/src/loaders/micro-agent.js +4 -4
- package/dist/cjs/common/metrics/framework-detection.js +0 -72
- package/dist/cjs/common/util/user-agent.js +0 -57
- package/dist/cjs/common/window/supports-performance-observer.js +0 -15
- package/dist/esm/common/metrics/framework-detection.js +0 -66
- package/dist/esm/common/util/user-agent.js +0 -48
- package/dist/esm/common/window/supports-performance-observer.js +0 -9
- package/dist/types/common/metrics/framework-detection.d.ts.map +0 -1
- package/dist/types/common/util/user-agent.d.ts +0 -5
- package/dist/types/common/util/user-agent.d.ts.map +0 -1
- package/dist/types/common/window/supports-performance-observer.d.ts +0 -2
- package/dist/types/common/window/supports-performance-observer.d.ts.map +0 -1
- package/dist/types/features/utils/lazy-loader.d.ts.map +0 -1
- package/src/common/metrics/framework-detection.js +0 -71
- package/src/common/util/user-agent.js +0 -56
- package/src/common/window/supports-performance-observer.js +0 -10
- /package/dist/types/{common/metrics → features/metrics/aggregate}/framework-detection.d.ts +0 -0
|
@@ -24,6 +24,23 @@ var _globalScope = require("../util/global-scope");
|
|
|
24
24
|
* SPDX-License-Identifier: Apache-2.0
|
|
25
25
|
*/
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* @typedef {object} NetworkSendSpec
|
|
29
|
+
* @param {string} endpoint The endpoint to use (jserrors, events, resources etc.)
|
|
30
|
+
* @param {object} payload Object representing payload.
|
|
31
|
+
* @param {object} payload.qs Map of values that should be sent as part of the request query string.
|
|
32
|
+
* @param {string} payload.body String that should be sent as the body of the request.
|
|
33
|
+
* @param {string} payload.body.e Special case of body used for browser interactions.
|
|
34
|
+
* @param {object} opts Additional options for sending data
|
|
35
|
+
* @param {boolean} opts.needResponse Specify whether the caller expects a response data.
|
|
36
|
+
* @param {boolean} opts.unload Specify whether the call is a final harvest during page unload.
|
|
37
|
+
* @param {boolean} opts.sendEmptyBody Specify whether the call should be made even if the body is empty. Useful for rum calls.
|
|
38
|
+
* @param {function} submitMethod The submit method to use {@link ../util/submit-data}
|
|
39
|
+
* @param {string} customUrl Override the beacon url the data is sent to; must include protocol if defined
|
|
40
|
+
* @param {boolean} gzip Enabled gzip compression on the body of the request before it is sent
|
|
41
|
+
* @param {boolean} includeBaseParams Enables the use of base query parameters in the beacon url {@see Harvest.baseQueryString}
|
|
42
|
+
*/
|
|
43
|
+
|
|
27
44
|
const haveSendBeacon = !!navigator.sendBeacon; // only the web window obj has sendBeacon at this time, so 'false' for other envs
|
|
28
45
|
|
|
29
46
|
class Harvest extends _sharedContext.SharedContext {
|
|
@@ -39,62 +56,78 @@ class Harvest extends _sharedContext.SharedContext {
|
|
|
39
56
|
/**
|
|
40
57
|
* Initiate a harvest from multiple sources. An event that corresponds to the endpoint
|
|
41
58
|
* name is emitted, which gives any listeners the opportunity to provide payload data.
|
|
42
|
-
*
|
|
43
|
-
* @param {string} endpoint - The endpoint of the harvest (jserrors, events, resources etc.)
|
|
44
|
-
*
|
|
45
|
-
* @param {object} opts
|
|
46
|
-
* @param {bool} opts.needResponse - Specify whether the caller expects a response data.
|
|
47
|
-
* @param {bool} opts.unload - Specify whether the call is a final harvest during page unload.
|
|
59
|
+
* @param {NetworkSendSpec} spec Specification for sending data
|
|
48
60
|
*/
|
|
49
|
-
sendX(
|
|
61
|
+
sendX(spec) {
|
|
62
|
+
const {
|
|
63
|
+
endpoint,
|
|
64
|
+
opts
|
|
65
|
+
} = spec;
|
|
50
66
|
var submitMethod = getSubmitMethod(endpoint, opts);
|
|
51
67
|
if (!submitMethod) return false;
|
|
52
68
|
var options = {
|
|
53
69
|
retry: submitMethod.method === _submitData.submitData.xhr
|
|
54
70
|
};
|
|
55
|
-
|
|
71
|
+
const payload = this.createPayload(endpoint, options);
|
|
72
|
+
var caller = this.obfuscator.shouldObfuscate() ? this.obfuscateAndSend.bind(this) : this._send.bind(this);
|
|
73
|
+
return caller({
|
|
74
|
+
...spec,
|
|
75
|
+
payload,
|
|
76
|
+
submitMethod
|
|
77
|
+
});
|
|
56
78
|
}
|
|
57
79
|
|
|
58
80
|
/**
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
* @param {string} singlePayload.body - String that should be sent as the body of the request.
|
|
67
|
-
* @param {string} singlePayload.body.e - Special case of body used for browser interactions.
|
|
68
|
-
*
|
|
69
|
-
* @param {object} opts
|
|
70
|
-
* @param {bool} opts.needResponse - Specify whether the caller expects a response data.
|
|
71
|
-
* @param {bool} opts.unload - Specify whether the call is a final harvest during page unload.
|
|
72
|
-
*/
|
|
73
|
-
send(endpoint, singlePayload, opts, submitMethod, cbFinished) {
|
|
74
|
-
var _this = this;
|
|
81
|
+
* Initiate a harvest call.
|
|
82
|
+
* @param {NetworkSendSpec} spec Specification for sending data
|
|
83
|
+
*/
|
|
84
|
+
send(spec) {
|
|
85
|
+
const {
|
|
86
|
+
payload = {}
|
|
87
|
+
} = spec;
|
|
75
88
|
var makeBody = createAccumulator();
|
|
76
89
|
var makeQueryString = createAccumulator();
|
|
77
|
-
if (
|
|
78
|
-
if (
|
|
79
|
-
var
|
|
90
|
+
if (payload.body) (0, _mapOwn.mapOwn)(payload.body, makeBody);
|
|
91
|
+
if (payload.qs) (0, _mapOwn.mapOwn)(payload.qs, makeQueryString);
|
|
92
|
+
var newPayload = {
|
|
80
93
|
body: makeBody(),
|
|
81
94
|
qs: makeQueryString()
|
|
82
95
|
};
|
|
83
|
-
var caller = this.obfuscator.shouldObfuscate() ?
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
};
|
|
88
|
-
return caller(endpoint, payload, opts, submitMethod, cbFinished);
|
|
96
|
+
var caller = this.obfuscator.shouldObfuscate() ? this.obfuscateAndSend.bind(this) : this._send.bind(this);
|
|
97
|
+
return caller({
|
|
98
|
+
...spec,
|
|
99
|
+
payload: newPayload
|
|
100
|
+
});
|
|
89
101
|
}
|
|
90
|
-
|
|
91
|
-
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* Apply obfuscation rules to the payload and then initial the harvest network call.
|
|
105
|
+
* @param {NetworkSendSpec} spec Specification for sending data
|
|
106
|
+
*/
|
|
107
|
+
obfuscateAndSend(spec) {
|
|
108
|
+
var _this = this;
|
|
109
|
+
const {
|
|
110
|
+
payload = {}
|
|
111
|
+
} = spec;
|
|
92
112
|
(0, _traverse.applyFnToProps)(payload, function () {
|
|
93
|
-
return
|
|
113
|
+
return _this.obfuscator.obfuscateString(...arguments);
|
|
94
114
|
}, 'string', ['e']);
|
|
95
|
-
return this._send(
|
|
115
|
+
return this._send({
|
|
116
|
+
...spec,
|
|
117
|
+
payload
|
|
118
|
+
});
|
|
96
119
|
}
|
|
97
|
-
_send(
|
|
120
|
+
_send(_ref) {
|
|
121
|
+
let {
|
|
122
|
+
endpoint,
|
|
123
|
+
payload = {},
|
|
124
|
+
opts = {},
|
|
125
|
+
submitMethod,
|
|
126
|
+
cbFinished,
|
|
127
|
+
customUrl,
|
|
128
|
+
raw,
|
|
129
|
+
includeBaseParams = true
|
|
130
|
+
} = _ref;
|
|
98
131
|
var info = (0, _config.getInfo)(this.sharedContext.agentIdentifier);
|
|
99
132
|
if (!info.errorBeacon) return false;
|
|
100
133
|
var agentRuntime = (0, _config.getRuntime)(this.sharedContext.agentIdentifier);
|
|
@@ -107,38 +140,54 @@ class Harvest extends _sharedContext.SharedContext {
|
|
|
107
140
|
}
|
|
108
141
|
return false;
|
|
109
142
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
143
|
+
let url = '';
|
|
144
|
+
if (customUrl) url = customUrl;else if (raw) url = "".concat(this.getScheme(), "://").concat(info.errorBeacon, "/").concat(endpoint);else url = "".concat(this.getScheme(), "://").concat(info.errorBeacon, "/").concat(endpoint, "/1/").concat(info.licenseKey);
|
|
145
|
+
var baseParams = !raw && includeBaseParams ? this.baseQueryString() : '';
|
|
146
|
+
var payloadParams = payload.qs ? (0, _encode.obj)(payload.qs, agentRuntime.maxBytes) : '';
|
|
113
147
|
if (!submitMethod) {
|
|
114
148
|
submitMethod = getSubmitMethod(endpoint, opts);
|
|
115
149
|
}
|
|
116
150
|
var method = submitMethod.method;
|
|
117
151
|
var useBody = submitMethod.useBody;
|
|
118
152
|
var body;
|
|
119
|
-
var fullUrl = url;
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
153
|
+
var fullUrl = "".concat(url, "?").concat(baseParams).concat(payloadParams);
|
|
154
|
+
const gzip = payload?.qs?.content_encoding === 'gzip';
|
|
155
|
+
if (!gzip) {
|
|
156
|
+
if (useBody && endpoint === 'events') {
|
|
157
|
+
body = payload.body.e;
|
|
158
|
+
} else if (useBody) {
|
|
159
|
+
body = (0, _stringify.stringify)(payload.body);
|
|
160
|
+
} else {
|
|
161
|
+
fullUrl = fullUrl + (0, _encode.obj)(payload.body, agentRuntime.maxBytes);
|
|
162
|
+
}
|
|
163
|
+
} else body = payload.body;
|
|
127
164
|
|
|
128
165
|
// Get bytes harvested per endpoint as a supportability metric. See metrics aggregator (on unload).
|
|
129
166
|
agentRuntime.bytesSent[endpoint] = (agentRuntime.bytesSent[endpoint] || 0) + body?.length || 0;
|
|
130
167
|
// Get query bytes harvested per endpoint as a supportability metric. See metrics aggregator (on unload).
|
|
131
168
|
agentRuntime.queryBytesSent[endpoint] = (agentRuntime.queryBytesSent[endpoint] || 0) + fullUrl.split('?').slice(-1)[0]?.length || 0;
|
|
169
|
+
const headers = [];
|
|
170
|
+
headers.push({
|
|
171
|
+
key: 'content-type',
|
|
172
|
+
value: 'text/plain'
|
|
173
|
+
});
|
|
132
174
|
|
|
133
175
|
/* Since workers don't support sendBeacon right now, or Image(), they can only use XHR method.
|
|
134
176
|
Because they still do permit synch XHR, the idea is that at final harvest time (worker is closing),
|
|
135
177
|
we just make a BLOCKING request--trivial impact--with the remaining data as a temp fill-in for sendBeacon. */
|
|
136
|
-
|
|
178
|
+
|
|
179
|
+
var result = method({
|
|
180
|
+
url: fullUrl,
|
|
181
|
+
body,
|
|
182
|
+
sync: opts.unload && _globalScope.isWorkerScope,
|
|
183
|
+
headers
|
|
184
|
+
});
|
|
137
185
|
if (cbFinished && method === _submitData.submitData.xhr) {
|
|
138
186
|
var xhr = result;
|
|
139
187
|
xhr.addEventListener('load', function () {
|
|
140
188
|
var result = {
|
|
141
|
-
sent: true
|
|
189
|
+
sent: true,
|
|
190
|
+
status: this.status
|
|
142
191
|
};
|
|
143
192
|
if (this.status === 429) {
|
|
144
193
|
result.retry = true;
|
|
@@ -156,7 +205,9 @@ class Harvest extends _sharedContext.SharedContext {
|
|
|
156
205
|
// if beacon request failed, retry with an alternative method -- will not happen for workers
|
|
157
206
|
if (!result && method === _submitData.submitData.beacon) {
|
|
158
207
|
method = _submitData.submitData.img;
|
|
159
|
-
result = method(
|
|
208
|
+
result = method({
|
|
209
|
+
url: fullUrl + (0, _encode.obj)(payload.body, agentRuntime.maxBytes)
|
|
210
|
+
});
|
|
160
211
|
}
|
|
161
212
|
return result;
|
|
162
213
|
}
|
|
@@ -167,9 +218,9 @@ class Harvest extends _sharedContext.SharedContext {
|
|
|
167
218
|
var info = (0, _config.getInfo)(this.sharedContext.agentIdentifier);
|
|
168
219
|
var location = (0, _cleanUrl.cleanURL)((0, _location.getLocation)());
|
|
169
220
|
var ref = this.obfuscator.shouldObfuscate() ? this.obfuscator.obfuscateString(location) : location;
|
|
170
|
-
return ['
|
|
221
|
+
return ['a=' + info.applicationID, (0, _encode.param)('sa', info.sa ? '' + info.sa : ''), (0, _encode.param)('v', _env.VERSION), transactionNameParam(info), (0, _encode.param)('ct', runtime.customTransaction), '&rst=' + (0, _now.now)(), '&ck=0',
|
|
171
222
|
// ck param DEPRECATED - still expected by backend
|
|
172
|
-
'&s=' + (runtime.session?.value || '0'),
|
|
223
|
+
'&s=' + (runtime.session?.state.value || '0'),
|
|
173
224
|
// the 0 id encaps all untrackable and default traffic
|
|
174
225
|
(0, _encode.param)('ref', ref), (0, _encode.param)('ptid', runtime.ptid ? '' + runtime.ptid : '')].join('');
|
|
175
226
|
}
|
|
@@ -240,7 +291,7 @@ function createAccumulator() {
|
|
|
240
291
|
var accumulator = {};
|
|
241
292
|
var hasData = false;
|
|
242
293
|
return function (key, val) {
|
|
243
|
-
if (val && val.length) {
|
|
294
|
+
if (val !== null && val !== undefined && val.length) {
|
|
244
295
|
accumulator[key] = val;
|
|
245
296
|
hasData = true;
|
|
246
297
|
}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.SessionEntity = void 0;
|
|
6
|
+
exports.SessionEntity = exports.SESSION_EVENTS = void 0;
|
|
7
7
|
var _uniqueId = require("../ids/unique-id");
|
|
8
8
|
var _console = require("../util/console");
|
|
9
9
|
var _stringify = require("../util/stringify");
|
|
@@ -18,15 +18,23 @@ var _configurable = require("../config/state/configurable");
|
|
|
18
18
|
var _handle = require("../event-emitter/handle");
|
|
19
19
|
var _constants2 = require("../../features/metrics/constants");
|
|
20
20
|
var _features = require("../../loaders/features/features");
|
|
21
|
+
// this is what can be stored in local storage (not enforced but probably should be)
|
|
22
|
+
// these values should sync between local storage and the parent class props
|
|
21
23
|
const model = {
|
|
22
24
|
value: '',
|
|
23
25
|
inactiveAt: 0,
|
|
24
26
|
expiresAt: 0,
|
|
25
27
|
updatedAt: Date.now(),
|
|
26
|
-
|
|
28
|
+
sessionReplay: 0,
|
|
27
29
|
sessionTraceActive: false,
|
|
28
30
|
custom: {}
|
|
29
31
|
};
|
|
32
|
+
const SESSION_EVENTS = {
|
|
33
|
+
PAUSE: 'session-pause',
|
|
34
|
+
RESET: 'session-reset',
|
|
35
|
+
RESUME: 'session-resume'
|
|
36
|
+
};
|
|
37
|
+
exports.SESSION_EVENTS = SESSION_EVENTS;
|
|
30
38
|
class SessionEntity {
|
|
31
39
|
/**
|
|
32
40
|
* Create a self-managing Session Entity. This entity is scoped to the agent identifier which triggered it, allowing for multiple simultaneous session objects to exist.
|
|
@@ -48,13 +56,13 @@ class SessionEntity {
|
|
|
48
56
|
} = _ref;
|
|
49
57
|
if (!agentIdentifier || !key) throw new Error('Missing Required Fields');
|
|
50
58
|
if (!_globalScope.isBrowserScope) this.storage = new _localMemory.LocalMemory();else this.storage = storageAPI;
|
|
59
|
+
this.state = {};
|
|
51
60
|
this.sync(model);
|
|
52
61
|
this.agentIdentifier = agentIdentifier;
|
|
53
|
-
|
|
54
62
|
// key is intended to act as the k=v pair
|
|
55
63
|
this.key = key;
|
|
56
64
|
// value is intended to act as the primary value of the k=v pair
|
|
57
|
-
this.value = value;
|
|
65
|
+
this.state.value = value;
|
|
58
66
|
this.expiresMs = expiresMs;
|
|
59
67
|
this.inactiveMs = inactiveMs;
|
|
60
68
|
this.ee = _contextualEe.ee.get(agentIdentifier);
|
|
@@ -71,7 +79,7 @@ class SessionEntity {
|
|
|
71
79
|
// the set-up of the timer used to expire the session "naturally" at a certain time
|
|
72
80
|
// this gets ignored if the value is falsy, allowing for session entities that do not expire
|
|
73
81
|
if (expiresMs) {
|
|
74
|
-
this.expiresAt = initialRead?.expiresAt || this.getFutureTimestamp(expiresMs);
|
|
82
|
+
this.state.expiresAt = initialRead?.expiresAt || this.getFutureTimestamp(expiresMs);
|
|
75
83
|
this.expiresTimer = new _timer.Timer({
|
|
76
84
|
// When the inactive timer ends, collect a SM and reset the session
|
|
77
85
|
onEnd: () => {
|
|
@@ -79,16 +87,16 @@ class SessionEntity {
|
|
|
79
87
|
this.collectSM('duration', this);
|
|
80
88
|
this.reset();
|
|
81
89
|
}
|
|
82
|
-
}, this.expiresAt - Date.now());
|
|
90
|
+
}, this.state.expiresAt - Date.now());
|
|
83
91
|
} else {
|
|
84
|
-
this.expiresAt = Infinity;
|
|
92
|
+
this.state.expiresAt = Infinity;
|
|
85
93
|
}
|
|
86
94
|
|
|
87
95
|
// the set-up of the timer used to expire the session due to "inactivity" at a certain time
|
|
88
96
|
// this gets ignored if the value is falsy, allowing for session entities that do not expire
|
|
89
97
|
// this gets "refreshed" when "activity" is observed
|
|
90
98
|
if (inactiveMs) {
|
|
91
|
-
this.inactiveAt = initialRead?.inactiveAt || this.getFutureTimestamp(inactiveMs);
|
|
99
|
+
this.state.inactiveAt = initialRead?.inactiveAt || this.getFutureTimestamp(inactiveMs);
|
|
92
100
|
this.inactiveTimer = new _interactionTimer.InteractionTimer({
|
|
93
101
|
// When the inactive timer ends, collect a SM and reset the session
|
|
94
102
|
onEnd: () => {
|
|
@@ -98,21 +106,27 @@ class SessionEntity {
|
|
|
98
106
|
},
|
|
99
107
|
// When the inactive timer refreshes, it will update the storage values with an update timestamp
|
|
100
108
|
onRefresh: this.refresh.bind(this),
|
|
109
|
+
onResume: () => {
|
|
110
|
+
this.ee.emit(SESSION_EVENTS.RESUME);
|
|
111
|
+
},
|
|
101
112
|
// When the inactive timer pauses, update the storage values with an update timestamp
|
|
102
|
-
onPause: () =>
|
|
113
|
+
onPause: () => {
|
|
114
|
+
if (this.initialized) this.ee.emit(SESSION_EVENTS.PAUSE);
|
|
115
|
+
this.write((0, _configurable.getModeledObject)(this.state, model));
|
|
116
|
+
},
|
|
103
117
|
ee: this.ee,
|
|
104
118
|
refreshEvents: ['click', 'keydown', 'scroll']
|
|
105
|
-
}, this.inactiveAt - Date.now());
|
|
119
|
+
}, this.state.inactiveAt - Date.now());
|
|
106
120
|
} else {
|
|
107
|
-
this.inactiveAt = Infinity;
|
|
121
|
+
this.state.inactiveAt = Infinity;
|
|
108
122
|
}
|
|
109
123
|
|
|
110
124
|
// The fact that the session is "new" or pre-existing is used in some places in the agent. Session Replay and Trace
|
|
111
125
|
// can use this info to inform whether to trust a new sampling decision vs continue a previous tracking effort.
|
|
112
|
-
this.isNew = !Object.keys(initialRead).length;
|
|
126
|
+
if (this.isNew === undefined) this.isNew = !Object.keys(initialRead).length;
|
|
113
127
|
// if its a "new" session, we write to storage API with the default values. These values may change over the lifespan of the agent run.
|
|
114
|
-
// we can use
|
|
115
|
-
if (this.isNew) this.write(
|
|
128
|
+
// we can use a modeled object here to help us know and manage what values are being used. -- see "model" above
|
|
129
|
+
if (this.isNew) this.write((0, _configurable.getModeledObject)(this.state, model), true);else this.sync(initialRead);
|
|
116
130
|
this.initialized = true;
|
|
117
131
|
}
|
|
118
132
|
|
|
@@ -121,7 +135,7 @@ class SessionEntity {
|
|
|
121
135
|
return "".concat(_constants.PREFIX, "_").concat(this.key);
|
|
122
136
|
}
|
|
123
137
|
sync(data) {
|
|
124
|
-
Object.assign(this, data);
|
|
138
|
+
Object.assign(this.state, data);
|
|
125
139
|
}
|
|
126
140
|
|
|
127
141
|
/**
|
|
@@ -168,7 +182,8 @@ class SessionEntity {
|
|
|
168
182
|
if (!data || typeof data !== 'object') return;
|
|
169
183
|
// everytime we update, we can update a timestamp for sanity
|
|
170
184
|
data.updatedAt = Date.now();
|
|
171
|
-
this.sync(data);
|
|
185
|
+
this.sync(data); // update the parent class "state" properties with the local storage values
|
|
186
|
+
//
|
|
172
187
|
// TODO - compression would need happen here if we decide to do it
|
|
173
188
|
this.storage.set(this.lookupKey, (0, _stringify.stringify)(data));
|
|
174
189
|
return data;
|
|
@@ -184,12 +199,11 @@ class SessionEntity {
|
|
|
184
199
|
// * stop recording (stn and sr)...
|
|
185
200
|
// * delete the session and start over
|
|
186
201
|
try {
|
|
187
|
-
if (this.initialized) this.ee.emit(
|
|
202
|
+
if (this.initialized) this.ee.emit(SESSION_EVENTS.RESET);
|
|
188
203
|
this.storage.remove(this.lookupKey);
|
|
189
204
|
this.inactiveTimer?.abort?.();
|
|
190
205
|
this.expiresTimer?.clear?.();
|
|
191
|
-
delete this.
|
|
192
|
-
delete this.value;
|
|
206
|
+
delete this.isNew;
|
|
193
207
|
this.setup({
|
|
194
208
|
agentIdentifier: this.agentIdentifier,
|
|
195
209
|
key: this.key,
|
|
@@ -209,10 +223,9 @@ class SessionEntity {
|
|
|
209
223
|
refresh() {
|
|
210
224
|
// read here & invalidate
|
|
211
225
|
const existingData = this.read();
|
|
212
|
-
this.inactiveAt = this.getFutureTimestamp(this.inactiveMs);
|
|
213
226
|
this.write({
|
|
214
227
|
...existingData,
|
|
215
|
-
inactiveAt: this.
|
|
228
|
+
inactiveAt: this.getFutureTimestamp(this.inactiveMs)
|
|
216
229
|
});
|
|
217
230
|
}
|
|
218
231
|
|
|
@@ -229,7 +242,7 @@ class SessionEntity {
|
|
|
229
242
|
* @returns {boolean}
|
|
230
243
|
*/
|
|
231
244
|
isInvalid(data) {
|
|
232
|
-
const requiredKeys =
|
|
245
|
+
const requiredKeys = Object.keys(model);
|
|
233
246
|
return !requiredKeys.every(x => Object.keys(data).includes(x));
|
|
234
247
|
}
|
|
235
248
|
collectSM(type, data, useUpdatedAt) {
|