@newrelic/browser-agent 0.0.9 → 0.1.229
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/README.md +84 -207
- package/dist/cjs/cdn/lite.js +14 -0
- package/dist/cjs/cdn/polyfills/lite.js +4 -0
- package/dist/cjs/cdn/polyfills/pro.js +4 -0
- package/dist/cjs/cdn/polyfills/spa.js +4 -0
- package/dist/cjs/cdn/polyfills.js +14 -0
- package/dist/cjs/cdn/pro.js +19 -0
- package/dist/cjs/cdn/spa.js +19 -0
- package/dist/cjs/cdn/worker.js +16 -0
- package/dist/cjs/common/aggregate/aggregator.js +168 -0
- package/dist/cjs/common/browser-version/firefox-version.js +17 -0
- package/dist/cjs/common/browser-version/ios-version.js +18 -0
- package/dist/cjs/common/config/config.js +76 -0
- package/dist/cjs/common/config/state/configurable.js +32 -0
- package/dist/cjs/common/config/state/info.js +50 -0
- package/dist/cjs/common/config/state/init.js +86 -0
- package/dist/cjs/common/config/state/loader-config.js +28 -0
- package/dist/cjs/common/config/state/originals.js +9 -0
- package/dist/cjs/common/config/state/runtime.js +50 -0
- package/dist/cjs/common/constants/environment-variables.js +20 -0
- package/dist/cjs/common/context/shared-context.js +25 -0
- package/dist/cjs/common/deny-list/deny-list.js +108 -0
- package/dist/cjs/common/drain/drain.js +126 -0
- package/dist/cjs/common/event-emitter/contextual-ee.js +149 -0
- package/dist/cjs/common/event-emitter/handle.js +24 -0
- package/dist/cjs/common/event-emitter/register-handler.js +24 -0
- package/dist/cjs/common/event-listener/event-listener-opts.js +46 -0
- package/dist/cjs/common/harvest/harvest-scheduler.js +111 -0
- package/dist/cjs/common/harvest/harvest.js +236 -0
- package/dist/cjs/common/ids/id.js +30 -0
- package/dist/cjs/common/ids/unique-id.js +84 -0
- package/dist/cjs/common/metrics/framework-detection.js +72 -0
- package/dist/cjs/common/metrics/paint-metrics.js +13 -0
- package/dist/cjs/common/serialize/bel-serializer.js +89 -0
- package/dist/cjs/common/timing/nav-timing.js +77 -0
- package/dist/cjs/common/timing/now.js +15 -0
- package/dist/cjs/common/unload/eol.js +69 -0
- package/dist/cjs/common/url/clean-url.js +16 -0
- package/dist/cjs/common/url/encode.js +79 -0
- package/dist/cjs/common/url/location.js +14 -0
- package/dist/cjs/common/url/parse-url.js +66 -0
- package/dist/cjs/common/url/protocol.js +25 -0
- package/dist/cjs/common/util/console.js +17 -0
- package/dist/cjs/common/util/data-size.js +25 -0
- package/dist/cjs/common/util/feature-flags.js +42 -0
- package/dist/cjs/common/util/get-or-set.js +39 -0
- package/dist/cjs/common/util/global-scope.js +56 -0
- package/dist/cjs/common/util/map-own.js +24 -0
- package/dist/cjs/common/util/obfuscate.js +76 -0
- package/dist/cjs/common/util/reduce.js +22 -0
- package/dist/cjs/common/util/s-hash.js +19 -0
- package/dist/cjs/common/util/single.js +23 -0
- package/dist/cjs/common/util/stringify.js +47 -0
- package/dist/cjs/common/util/submit-data.js +99 -0
- package/dist/cjs/common/util/traverse.js +41 -0
- package/dist/cjs/common/util/user-agent.js +57 -0
- package/dist/cjs/common/window/load.js +19 -0
- package/dist/cjs/common/window/nreum.js +107 -0
- package/dist/cjs/common/window/page-visibility.js +28 -0
- package/dist/cjs/common/window/session-storage.js +42 -0
- package/dist/cjs/common/window/supports-performance-observer.js +15 -0
- package/dist/cjs/common/window/top-level-callers.js +23 -0
- package/dist/cjs/common/wrap/index.js +68 -0
- package/dist/cjs/common/wrap/wrap-events.js +105 -0
- package/dist/cjs/common/wrap/wrap-fetch.js +114 -0
- package/dist/cjs/common/wrap/wrap-function.js +269 -0
- package/dist/cjs/common/wrap/wrap-history.js +56 -0
- package/dist/cjs/common/wrap/wrap-jsonp.js +129 -0
- package/dist/cjs/common/wrap/wrap-mutation.js +61 -0
- package/dist/cjs/common/wrap/wrap-promise.js +160 -0
- package/dist/cjs/common/wrap/wrap-raf.js +55 -0
- package/dist/cjs/common/wrap/wrap-timer.js +70 -0
- package/dist/cjs/common/wrap/wrap-xhr.js +206 -0
- package/dist/cjs/features/ajax/aggregate/index.js +226 -0
- package/dist/cjs/features/ajax/constants.js +9 -0
- package/dist/cjs/features/ajax/index.js +12 -0
- package/dist/cjs/features/ajax/instrument/distributed-tracing.js +145 -0
- package/dist/cjs/features/ajax/instrument/index.js +338 -0
- package/dist/cjs/features/ajax/instrument/response-size.js +26 -0
- package/dist/cjs/features/jserrors/aggregate/canonical-function-name.js +18 -0
- package/dist/cjs/features/jserrors/aggregate/canonical-function-name.test.js +30 -0
- package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.js +216 -0
- package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.test.js +257 -0
- package/dist/cjs/features/jserrors/aggregate/format-stack-trace.js +36 -0
- package/dist/cjs/features/jserrors/aggregate/format-stack-trace.test.js +39 -0
- package/dist/cjs/features/jserrors/aggregate/index.js +267 -0
- package/dist/cjs/features/jserrors/aggregate/string-hash-code.js +23 -0
- package/dist/cjs/features/jserrors/aggregate/string-hash-code.test.js +26 -0
- package/dist/cjs/features/jserrors/constants.js +11 -0
- package/dist/cjs/features/jserrors/index.js +12 -0
- package/dist/cjs/features/jserrors/instrument/debug.js +40 -0
- package/dist/cjs/features/jserrors/instrument/index.js +158 -0
- package/dist/cjs/features/metrics/aggregate/index.js +136 -0
- package/dist/cjs/features/metrics/constants.js +17 -0
- package/dist/cjs/features/metrics/index.js +12 -0
- package/dist/cjs/features/metrics/instrument/index.js +20 -0
- package/dist/cjs/features/metrics/instrument/workers-helper.js +121 -0
- package/dist/cjs/features/page_action/aggregate/index.js +112 -0
- package/dist/cjs/features/page_action/constants.js +9 -0
- package/dist/cjs/features/page_action/index.js +12 -0
- package/dist/cjs/features/page_action/instrument/index.js +21 -0
- package/dist/cjs/features/page_view_event/aggregate/index.js +133 -0
- package/dist/cjs/features/page_view_event/aggregate/initialized-features.js +39 -0
- package/dist/cjs/features/page_view_event/constants.js +15 -0
- package/dist/cjs/features/page_view_event/index.js +12 -0
- package/dist/cjs/features/page_view_event/instrument/index.js +38 -0
- package/dist/cjs/features/page_view_timing/aggregate/index.js +265 -0
- package/dist/cjs/features/page_view_timing/constants.js +9 -0
- package/dist/cjs/features/page_view_timing/first-paint.js +50 -0
- package/dist/cjs/features/page_view_timing/index.js +12 -0
- package/dist/cjs/features/page_view_timing/instrument/index.js +36 -0
- package/dist/cjs/features/page_view_timing/long-tasks.js +75 -0
- package/dist/cjs/features/session_trace/aggregate/index.js +375 -0
- package/dist/cjs/features/session_trace/constants.js +32 -0
- package/dist/cjs/features/session_trace/index.js +12 -0
- package/dist/cjs/features/session_trace/instrument/index.js +133 -0
- package/dist/cjs/features/spa/aggregate/index.js +684 -0
- package/dist/cjs/features/spa/aggregate/interaction-node.js +84 -0
- package/dist/cjs/features/spa/aggregate/interaction-node.test.js +16 -0
- package/dist/cjs/features/spa/aggregate/interaction.js +98 -0
- package/dist/cjs/features/spa/aggregate/serializer.js +147 -0
- package/dist/cjs/features/spa/constants.js +53 -0
- package/dist/cjs/features/spa/index.js +12 -0
- package/dist/cjs/features/spa/instrument/index.js +114 -0
- package/dist/cjs/features/utils/aggregate-base.js +13 -0
- package/dist/cjs/features/utils/feature-base.js +58 -0
- package/dist/cjs/features/utils/handler-cache.js +64 -0
- package/dist/cjs/features/utils/instrument-base.js +71 -0
- package/dist/cjs/features/utils/lazy-loader.js +44 -0
- package/dist/cjs/index.js +81 -58
- package/dist/cjs/loaders/agent.js +86 -0
- package/dist/cjs/loaders/api/api.js +109 -0
- package/dist/cjs/loaders/api/apiAsync.js +94 -0
- package/dist/cjs/loaders/browser-agent.js +29 -0
- package/dist/cjs/loaders/configure/configure.js +47 -0
- package/dist/cjs/loaders/features/enabled-features.js +19 -0
- package/dist/cjs/loaders/features/featureDependencies.js +32 -0
- package/dist/cjs/loaders/features/features.js +33 -0
- package/dist/cjs/loaders/micro-agent.js +93 -0
- package/dist/cjs/loaders/worker-agent.js +24 -0
- package/dist/esm/cdn/lite.js +12 -0
- package/dist/esm/cdn/polyfills/lite.js +7 -0
- package/dist/esm/cdn/polyfills/pro.js +7 -0
- package/dist/esm/cdn/polyfills/spa.js +7 -0
- package/dist/esm/cdn/polyfills.js +17 -0
- package/dist/esm/cdn/pro.js +17 -0
- package/dist/esm/cdn/spa.js +17 -0
- package/dist/esm/cdn/worker.js +14 -0
- package/dist/esm/common/aggregate/aggregator.js +161 -0
- package/dist/esm/common/browser-version/firefox-version.js +10 -0
- package/dist/esm/common/browser-version/ios-version.js +10 -0
- package/dist/esm/common/config/config.js +11 -0
- package/dist/esm/common/config/state/configurable.js +25 -0
- package/dist/esm/common/config/state/info.js +42 -0
- package/dist/esm/common/config/state/init.js +78 -0
- package/dist/esm/common/config/state/loader-config.js +21 -0
- package/dist/esm/common/config/state/originals.js +2 -0
- package/dist/esm/common/config/state/runtime.js +41 -0
- package/dist/esm/common/constants/environment-variables.js +11 -0
- package/dist/esm/common/context/shared-context.js +18 -0
- package/dist/esm/common/deny-list/deny-list.js +101 -0
- package/dist/esm/common/drain/drain.js +119 -0
- package/dist/esm/common/event-emitter/contextual-ee.js +142 -0
- package/dist/esm/common/event-emitter/handle.js +16 -0
- package/dist/esm/common/event-emitter/register-handler.js +19 -0
- package/dist/esm/common/event-listener/event-listener-opts.js +39 -0
- package/dist/esm/common/harvest/harvest-scheduler.js +105 -0
- package/dist/esm/common/harvest/harvest.js +228 -0
- package/dist/esm/common/ids/id.js +23 -0
- package/dist/esm/common/ids/unique-id.js +75 -0
- package/dist/esm/common/metrics/framework-detection.js +66 -0
- package/dist/esm/common/metrics/paint-metrics.js +6 -0
- package/dist/esm/common/serialize/bel-serializer.js +80 -0
- package/dist/esm/common/timing/nav-timing.js +67 -0
- package/dist/esm/common/timing/now.js +9 -0
- package/dist/esm/common/unload/eol.js +62 -0
- package/dist/esm/common/url/clean-url.js +10 -0
- package/dist/esm/common/url/encode.js +71 -0
- package/dist/esm/common/url/location.js +8 -0
- package/dist/esm/common/url/parse-url.js +60 -0
- package/dist/esm/common/url/protocol.js +17 -0
- package/dist/esm/common/util/console.js +11 -0
- package/dist/esm/common/util/data-size.js +19 -0
- package/dist/esm/common/util/feature-flags.js +33 -0
- package/dist/esm/common/util/get-or-set.js +33 -0
- package/dist/esm/common/util/global-scope.js +44 -0
- package/dist/esm/common/util/map-own.js +18 -0
- package/dist/esm/common/util/obfuscate.js +67 -0
- package/dist/esm/common/util/reduce.js +16 -0
- package/dist/esm/common/util/s-hash.js +13 -0
- package/dist/esm/common/util/single.js +16 -0
- package/dist/esm/common/util/stringify.js +42 -0
- package/dist/esm/common/util/submit-data.js +91 -0
- package/dist/esm/common/util/traverse.js +35 -0
- package/dist/esm/common/util/user-agent.js +48 -0
- package/dist/esm/common/window/load.js +12 -0
- package/dist/esm/common/window/nreum.js +91 -0
- package/dist/esm/common/window/page-visibility.js +23 -0
- package/dist/esm/common/window/session-storage.js +36 -0
- package/dist/esm/common/window/supports-performance-observer.js +9 -0
- package/dist/esm/common/window/top-level-callers.js +17 -0
- package/dist/esm/common/wrap/index.js +14 -0
- package/dist/esm/common/wrap/wrap-events.js +97 -0
- package/dist/esm/common/wrap/wrap-fetch.js +105 -0
- package/dist/esm/common/wrap/wrap-function.js +257 -0
- package/dist/esm/common/wrap/wrap-history.js +48 -0
- package/dist/esm/common/wrap/wrap-jsonp.js +122 -0
- package/dist/esm/common/wrap/wrap-mutation.js +54 -0
- package/dist/esm/common/wrap/wrap-promise.js +153 -0
- package/dist/esm/common/wrap/wrap-raf.js +48 -0
- package/dist/esm/common/wrap/wrap-timer.js +63 -0
- package/dist/esm/common/wrap/wrap-xhr.js +199 -0
- package/dist/esm/features/ajax/aggregate/index.js +218 -0
- package/dist/esm/features/ajax/constants.js +2 -0
- package/dist/esm/features/ajax/index.js +1 -0
- package/dist/esm/features/ajax/instrument/distributed-tracing.js +137 -0
- package/dist/esm/features/ajax/instrument/index.js +330 -0
- package/dist/esm/features/ajax/instrument/response-size.js +19 -0
- package/dist/esm/features/jserrors/aggregate/canonical-function-name.js +12 -0
- package/dist/esm/features/jserrors/aggregate/canonical-function-name.test.js +28 -0
- package/dist/esm/features/jserrors/aggregate/compute-stack-trace.js +209 -0
- package/dist/esm/features/jserrors/aggregate/compute-stack-trace.test.js +255 -0
- package/dist/esm/features/jserrors/aggregate/format-stack-trace.js +29 -0
- package/dist/esm/features/jserrors/aggregate/format-stack-trace.test.js +37 -0
- package/dist/esm/features/jserrors/aggregate/index.js +260 -0
- package/dist/esm/features/jserrors/aggregate/string-hash-code.js +17 -0
- package/dist/esm/features/jserrors/aggregate/string-hash-code.test.js +24 -0
- package/dist/esm/features/jserrors/constants.js +3 -0
- package/dist/esm/features/jserrors/index.js +1 -0
- package/dist/esm/features/jserrors/instrument/debug.js +38 -0
- package/dist/esm/features/jserrors/instrument/index.js +150 -0
- package/dist/esm/features/metrics/aggregate/index.js +129 -0
- package/dist/esm/features/metrics/constants.js +6 -0
- package/dist/esm/features/metrics/index.js +1 -0
- package/dist/esm/features/metrics/instrument/index.js +13 -0
- package/dist/esm/features/metrics/instrument/workers-helper.js +116 -0
- package/dist/esm/features/page_action/aggregate/index.js +105 -0
- package/dist/esm/features/page_action/constants.js +2 -0
- package/dist/esm/features/page_action/index.js +1 -0
- package/dist/esm/features/page_action/instrument/index.js +14 -0
- package/dist/esm/features/page_view_event/aggregate/index.js +124 -0
- package/dist/esm/features/page_view_event/aggregate/initialized-features.js +34 -0
- package/dist/esm/features/page_view_event/constants.js +5 -0
- package/dist/esm/features/page_view_event/index.js +1 -0
- package/dist/esm/features/page_view_event/instrument/index.js +29 -0
- package/dist/esm/features/page_view_timing/aggregate/index.js +258 -0
- package/dist/esm/features/page_view_timing/constants.js +2 -0
- package/dist/esm/features/page_view_timing/first-paint.js +43 -0
- package/dist/esm/features/page_view_timing/index.js +1 -0
- package/dist/esm/features/page_view_timing/instrument/index.js +28 -0
- package/dist/esm/features/page_view_timing/long-tasks.js +69 -0
- package/dist/esm/features/session_trace/aggregate/index.js +366 -0
- package/dist/esm/features/session_trace/constants.js +14 -0
- package/dist/esm/features/session_trace/index.js +1 -0
- package/dist/esm/features/session_trace/instrument/index.js +123 -0
- package/dist/esm/features/spa/aggregate/index.js +674 -0
- package/dist/esm/features/spa/aggregate/interaction-node.js +78 -0
- package/dist/esm/features/spa/aggregate/interaction-node.test.js +14 -0
- package/dist/esm/features/spa/aggregate/interaction.js +92 -0
- package/dist/esm/features/spa/aggregate/serializer.js +139 -0
- package/dist/esm/features/spa/constants.js +25 -0
- package/dist/esm/features/spa/index.js +1 -0
- package/dist/esm/features/spa/instrument/index.js +104 -0
- package/dist/esm/features/utils/aggregate-base.js +6 -0
- package/dist/esm/features/utils/feature-base.js +51 -0
- package/dist/esm/features/utils/handler-cache.js +57 -0
- package/dist/esm/features/utils/instrument-base.js +69 -0
- package/dist/esm/features/utils/lazy-loader.js +37 -0
- package/dist/esm/index.js +15 -0
- package/dist/esm/loaders/agent.js +77 -0
- package/dist/esm/loaders/api/api.js +104 -0
- package/dist/esm/loaders/api/apiAsync.js +88 -0
- package/dist/esm/loaders/browser-agent.js +23 -0
- package/dist/esm/loaders/configure/configure.js +41 -0
- package/dist/esm/loaders/features/enabled-features.js +13 -0
- package/dist/esm/loaders/features/featureDependencies.js +25 -0
- package/dist/esm/loaders/features/features.js +25 -0
- package/dist/esm/loaders/micro-agent.js +86 -0
- package/dist/esm/loaders/worker-agent.js +18 -0
- package/package.json +204 -71
- package/types.ts +221 -0
- package/dist/bundled/es5/index.js +0 -2
- package/dist/bundled/es5/index.js.map +0 -1
- package/dist/bundled/es6/index.js +0 -2
- package/dist/bundled/es6/index.js.map +0 -1
- package/dist/cjs/index.d.ts +0 -19
- package/dist/cjs/index.js.map +0 -1
- package/dist/cjs/types.d.ts +0 -94
- package/dist/cjs/types.js +0 -28
- package/dist/cjs/types.js.map +0 -1
- package/dist/cjs/utils/api/api.d.ts +0 -10
- package/dist/cjs/utils/api/api.js +0 -40
- package/dist/cjs/utils/api/api.js.map +0 -1
- package/dist/cjs/utils/config/build-configs.d.ts +0 -6
- package/dist/cjs/utils/config/build-configs.js +0 -68
- package/dist/cjs/utils/config/build-configs.js.map +0 -1
- package/dist/cjs/utils/features/features.d.ts +0 -5
- package/dist/cjs/utils/features/features.js +0 -14
- package/dist/cjs/utils/features/features.js.map +0 -1
- package/dist/cjs/utils/features/initialize.d.ts +0 -5
- package/dist/cjs/utils/features/initialize.js +0 -51
- package/dist/cjs/utils/features/initialize.js.map +0 -1
- package/dist/es/index.d.ts +0 -19
- package/dist/es/index.js +0 -55
- package/dist/es/index.js.map +0 -1
- package/dist/es/types.d.ts +0 -94
- package/dist/es/types.js +0 -24
- package/dist/es/types.js.map +0 -1
- package/dist/es/utils/api/api.d.ts +0 -10
- package/dist/es/utils/api/api.js +0 -36
- package/dist/es/utils/api/api.js.map +0 -1
- package/dist/es/utils/config/build-configs.d.ts +0 -6
- package/dist/es/utils/config/build-configs.js +0 -64
- package/dist/es/utils/config/build-configs.js.map +0 -1
- package/dist/es/utils/features/features.d.ts +0 -5
- package/dist/es/utils/features/features.js +0 -10
- package/dist/es/utils/features/features.js.map +0 -1
- package/dist/es/utils/features/initialize.d.ts +0 -5
- package/dist/es/utils/features/initialize.js +0 -24
- package/dist/es/utils/features/initialize.js.map +0 -1
- package/dist/umd/index.d.ts +0 -19
- package/dist/umd/index.js +0 -69
- package/dist/umd/index.js.map +0 -1
- package/dist/umd/types.d.ts +0 -94
- package/dist/umd/types.js +0 -38
- package/dist/umd/types.js.map +0 -1
- package/dist/umd/utils/api/api.d.ts +0 -10
- package/dist/umd/utils/api/api.js +0 -50
- package/dist/umd/utils/api/api.js.map +0 -1
- package/dist/umd/utils/config/build-configs.d.ts +0 -6
- package/dist/umd/utils/config/build-configs.js +0 -78
- package/dist/umd/utils/config/build-configs.js.map +0 -1
- package/dist/umd/utils/features/features.d.ts +0 -5
- package/dist/umd/utils/features/features.js +0 -24
- package/dist/umd/utils/features/features.js.map +0 -1
- package/dist/umd/utils/features/initialize.d.ts +0 -5
- package/dist/umd/utils/features/initialize.js +0 -63
- package/dist/umd/utils/features/initialize.js.map +0 -1
- package/dist/webpack-analysis.html +0 -38
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _contextualEe = require("../../../common/event-emitter/contextual-ee");
|
|
4
|
+
var _mapOwn = require("../../../common/util/map-own");
|
|
5
|
+
/*
|
|
6
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
7
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
var flags = {};
|
|
11
|
+
var flagArr;
|
|
12
|
+
try {
|
|
13
|
+
flagArr = localStorage.getItem('__nr_flags').split(',');
|
|
14
|
+
if (console && typeof console.log === 'function') {
|
|
15
|
+
flags.console = true;
|
|
16
|
+
if (flagArr.indexOf('dev') !== -1) flags.dev = true;
|
|
17
|
+
if (flagArr.indexOf('nr_dev') !== -1) flags.nrDev = true;
|
|
18
|
+
}
|
|
19
|
+
} catch (err) {
|
|
20
|
+
// no op
|
|
21
|
+
}
|
|
22
|
+
if (flags.nrDev) _contextualEe.ee.on('internal-error', function (err) {
|
|
23
|
+
log(err.stack);
|
|
24
|
+
});
|
|
25
|
+
if (flags.dev) _contextualEe.ee.on('fn-err', function (args, origThis, err) {
|
|
26
|
+
log(err.stack);
|
|
27
|
+
});
|
|
28
|
+
if (flags.dev) {
|
|
29
|
+
log('NR AGENT IN DEVELOPMENT MODE');
|
|
30
|
+
log('flags: ' + (0, _mapOwn.mapOwn)(flags, function (key, val) {
|
|
31
|
+
return key;
|
|
32
|
+
}).join(', '));
|
|
33
|
+
}
|
|
34
|
+
function log(message) {
|
|
35
|
+
try {
|
|
36
|
+
if (flags.console) log(message);
|
|
37
|
+
} catch (err) {
|
|
38
|
+
// no op
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Instrument = void 0;
|
|
7
|
+
var _handle = require("../../../common/event-emitter/handle");
|
|
8
|
+
var _now = require("../../../common/timing/now");
|
|
9
|
+
var _getOrSet = require("../../../common/util/get-or-set");
|
|
10
|
+
var _wrap = require("../../../common/wrap");
|
|
11
|
+
var _lodash = _interopRequireDefault(require("lodash._slice"));
|
|
12
|
+
require("./debug");
|
|
13
|
+
var _instrumentBase = require("../../utils/instrument-base");
|
|
14
|
+
var _constants = require("../constants");
|
|
15
|
+
var _features = require("../../../loaders/features/features");
|
|
16
|
+
var _globalScope = require("../../../common/util/global-scope");
|
|
17
|
+
var _eventListenerOpts = require("../../../common/event-listener/event-listener-opts");
|
|
18
|
+
var _config = require("../../../common/config/config");
|
|
19
|
+
var _stringify = require("../../../common/util/stringify");
|
|
20
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
+
/*
|
|
22
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
23
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
24
|
+
*/
|
|
25
|
+
|
|
26
|
+
class Instrument extends _instrumentBase.InstrumentBase {
|
|
27
|
+
static featureName = _constants.FEATURE_NAME;
|
|
28
|
+
constructor(agentIdentifier, aggregator, auto = true) {
|
|
29
|
+
super(agentIdentifier, aggregator, _constants.FEATURE_NAME, auto);
|
|
30
|
+
// skipNext counter to keep track of uncaught
|
|
31
|
+
// errors that will be the same as caught errors.
|
|
32
|
+
this.skipNext = 0;
|
|
33
|
+
this.origOnerror = _globalScope.globalScope.onerror;
|
|
34
|
+
try {
|
|
35
|
+
this.removeOnAbort = new AbortController();
|
|
36
|
+
} // this try-catch can be removed when IE11 is completely unsupported & gone
|
|
37
|
+
catch (e) {}
|
|
38
|
+
const thisInstrument = this;
|
|
39
|
+
thisInstrument.ee.on('fn-start', function (args, obj, methodName) {
|
|
40
|
+
if (thisInstrument.abortHandler) thisInstrument.skipNext += 1;
|
|
41
|
+
});
|
|
42
|
+
thisInstrument.ee.on('fn-err', function (args, obj, err) {
|
|
43
|
+
if (thisInstrument.abortHandler && !err[_constants.NR_ERR_PROP]) {
|
|
44
|
+
(0, _getOrSet.getOrSet)(err, _constants.NR_ERR_PROP, function getVal() {
|
|
45
|
+
return true;
|
|
46
|
+
});
|
|
47
|
+
this.thrown = true;
|
|
48
|
+
notice(err, undefined, thisInstrument.ee);
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
thisInstrument.ee.on('fn-end', function () {
|
|
52
|
+
if (!thisInstrument.abortHandler) return;
|
|
53
|
+
if (!this.thrown && thisInstrument.skipNext > 0) thisInstrument.skipNext -= 1;
|
|
54
|
+
});
|
|
55
|
+
thisInstrument.ee.on('internal-error', function (e) {
|
|
56
|
+
(0, _handle.handle)('ierr', [e, (0, _now.now)(), true], undefined, _features.FEATURE_NAMES.jserrors, thisInstrument.ee);
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// Tack on our error handler onto the existing global one.
|
|
60
|
+
_globalScope.globalScope.onerror = (...args) => {
|
|
61
|
+
if (this.origOnerror) this.origOnerror(...args);
|
|
62
|
+
this.onerrorHandler(...args);
|
|
63
|
+
return false;
|
|
64
|
+
};
|
|
65
|
+
_globalScope.globalScope.addEventListener('unhandledrejection', e => {
|
|
66
|
+
/** rejections can contain data of any type -- this is an effort to keep the message human readable */
|
|
67
|
+
const err = castReasonToError(e.reason);
|
|
68
|
+
(0, _handle.handle)('err', [err, (0, _now.now)(), false, {
|
|
69
|
+
unhandledPromiseRejection: 1
|
|
70
|
+
}], undefined, _features.FEATURE_NAMES.jserrors, this.ee);
|
|
71
|
+
}, (0, _eventListenerOpts.eventListenerOpts)(false, this.removeOnAbort?.signal));
|
|
72
|
+
(0, _wrap.wrapRaf)(this.ee);
|
|
73
|
+
(0, _wrap.wrapTimer)(this.ee);
|
|
74
|
+
(0, _wrap.wrapEvents)(this.ee);
|
|
75
|
+
if ((0, _config.getRuntime)(agentIdentifier).xhrWrappable) (0, _wrap.wrapXhr)(this.ee);
|
|
76
|
+
this.abortHandler = this.#abort; // we also use this as a flag to denote that the feature is active or on and handling errors
|
|
77
|
+
this.importAggregator();
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** Restoration and resource release tasks to be done if JS error loader is being aborted. Unwind changes to globals. */
|
|
81
|
+
#abort() {
|
|
82
|
+
this.removeOnAbort?.abort();
|
|
83
|
+
this.abortHandler = undefined; // weakly allow this abort op to run only once
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* FF and Android browsers do not provide error info to the 'error' event callback,
|
|
88
|
+
* so we must use window.onerror
|
|
89
|
+
* @param {string} message
|
|
90
|
+
* @param {string} filename
|
|
91
|
+
* @param {number} lineno
|
|
92
|
+
* @param {number} column
|
|
93
|
+
* @param {Error | *} errorObj
|
|
94
|
+
* @returns
|
|
95
|
+
*/
|
|
96
|
+
onerrorHandler(message, filename, lineno, column, errorObj) {
|
|
97
|
+
try {
|
|
98
|
+
if (this.skipNext) this.skipNext -= 1;else notice(errorObj || new UncaughtException(message, filename, lineno), true, this.ee);
|
|
99
|
+
} catch (e) {
|
|
100
|
+
try {
|
|
101
|
+
(0, _handle.handle)('ierr', [e, (0, _now.now)(), true], undefined, _features.FEATURE_NAMES.jserrors, this.ee);
|
|
102
|
+
} catch (err) {
|
|
103
|
+
// do nothing
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
if (typeof this.origOnerror === 'function') return this.origOnerror.apply(this, (0, _lodash.default)(arguments));
|
|
107
|
+
return false;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
*
|
|
113
|
+
* @param {string} message
|
|
114
|
+
* @param {string} filename
|
|
115
|
+
* @param {number} lineno
|
|
116
|
+
*/
|
|
117
|
+
exports.Instrument = Instrument;
|
|
118
|
+
function UncaughtException(message, filename, lineno) {
|
|
119
|
+
this.message = message || 'Uncaught error with no additional information';
|
|
120
|
+
this.sourceURL = filename;
|
|
121
|
+
this.line = lineno;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Adds a timestamp and emits the 'err' event, which the error aggregator listens for
|
|
126
|
+
* @param {Error} err
|
|
127
|
+
* @param {boolean} doNotStamp
|
|
128
|
+
* @param {ContextualEE} ee
|
|
129
|
+
*/
|
|
130
|
+
function notice(err, doNotStamp, ee) {
|
|
131
|
+
// by default add timestamp, unless specifically told not to
|
|
132
|
+
// this is to preserve existing behavior
|
|
133
|
+
var time = !doNotStamp ? (0, _now.now)() : null;
|
|
134
|
+
(0, _handle.handle)('err', [err, time], undefined, _features.FEATURE_NAMES.jserrors, ee);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Attempts to cast an unhandledPromiseRejection reason (reject(...)) to an Error object
|
|
139
|
+
* @param {*} reason - The reason property from an unhandled promise rejection
|
|
140
|
+
* @returns {Error} - An Error object with the message as the casted reason
|
|
141
|
+
*/
|
|
142
|
+
function castReasonToError(reason) {
|
|
143
|
+
let prefix = 'Unhandled Promise Rejection: ';
|
|
144
|
+
if (reason instanceof Error) {
|
|
145
|
+
try {
|
|
146
|
+
reason.message = prefix + reason.message;
|
|
147
|
+
return reason;
|
|
148
|
+
} catch (e) {
|
|
149
|
+
return reason;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
if (typeof reason === 'undefined') return new Error(prefix);
|
|
153
|
+
try {
|
|
154
|
+
return new Error(prefix + (0, _stringify.stringify)(reason));
|
|
155
|
+
} catch (err) {
|
|
156
|
+
return new Error(prefix);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Aggregate = void 0;
|
|
7
|
+
var _config = require("../../../common/config/config");
|
|
8
|
+
var _registerHandler = require("../../../common/event-emitter/register-handler");
|
|
9
|
+
var _harvestScheduler = require("../../../common/harvest/harvest-scheduler");
|
|
10
|
+
var _aggregateBase = require("../../utils/aggregate-base");
|
|
11
|
+
var _constants = require("../constants");
|
|
12
|
+
var _drain = require("../../../common/drain/drain");
|
|
13
|
+
var _frameworkDetection = require("../../../common/metrics/framework-detection");
|
|
14
|
+
var _protocol = require("../../../common/url/protocol");
|
|
15
|
+
var _obfuscate = require("../../../common/util/obfuscate");
|
|
16
|
+
var _environmentVariables = require("../../../common/constants/environment-variables");
|
|
17
|
+
var _load = require("../../../common/window/load");
|
|
18
|
+
var _eventListenerOpts = require("../../../common/event-listener/event-listener-opts");
|
|
19
|
+
var _globalScope = require("../../../common/util/global-scope");
|
|
20
|
+
class Aggregate extends _aggregateBase.AggregateBase {
|
|
21
|
+
static featureName = _constants.FEATURE_NAME;
|
|
22
|
+
constructor(agentIdentifier, aggregator) {
|
|
23
|
+
super(agentIdentifier, aggregator, _constants.FEATURE_NAME);
|
|
24
|
+
let scheduler;
|
|
25
|
+
|
|
26
|
+
// If RUM-call's response determines that customer lacks entitlements for the /jserror ingest endpoint, don't harvest at all.
|
|
27
|
+
(0, _registerHandler.registerHandler)('block-err', () => {
|
|
28
|
+
this.blocked = true;
|
|
29
|
+
if (scheduler) scheduler.aborted = true; // RUM response may or may not have happened already before scheduler initialization below
|
|
30
|
+
}, this.featureName, this.ee);
|
|
31
|
+
|
|
32
|
+
// Allow features external to the metrics feature to capture SMs and CMs through the event emitter
|
|
33
|
+
(0, _registerHandler.registerHandler)(_constants.SUPPORTABILITY_METRIC_CHANNEL, this.storeSupportabilityMetrics.bind(this), this.featureName, this.ee);
|
|
34
|
+
(0, _registerHandler.registerHandler)(_constants.CUSTOM_METRIC_CHANNEL, this.storeEventMetrics.bind(this), this.featureName, this.ee);
|
|
35
|
+
this.singleChecks(); // checks that are run only one time, at script load
|
|
36
|
+
this.eachSessionChecks(); // the start of every time user engages with page
|
|
37
|
+
|
|
38
|
+
// *cli, Mar 23 - Per NR-94597, this feature should only harvest ONCE at the (potential) EoL time of the page.
|
|
39
|
+
scheduler = new _harvestScheduler.HarvestScheduler('jserrors', {
|
|
40
|
+
onUnload: () => this.unload()
|
|
41
|
+
}, this);
|
|
42
|
+
scheduler.harvest.on('jserrors', () => ({
|
|
43
|
+
body: this.aggregator.take(['cm', 'sm'])
|
|
44
|
+
}));
|
|
45
|
+
(0, _drain.drain)(this.agentIdentifier, this.featureName); // regardless if this is blocked or not, drain is needed to unblock other features from harvesting (counteract registerDrain)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
storeSupportabilityMetrics(name, value) {
|
|
49
|
+
if (this.blocked) return;
|
|
50
|
+
const type = _constants.SUPPORTABILITY_METRIC;
|
|
51
|
+
const params = {
|
|
52
|
+
name
|
|
53
|
+
};
|
|
54
|
+
this.aggregator.storeMetric(type, name, params, value);
|
|
55
|
+
}
|
|
56
|
+
storeEventMetrics(name, metrics) {
|
|
57
|
+
if (this.blocked) return;
|
|
58
|
+
const type = _constants.CUSTOM_METRIC;
|
|
59
|
+
const params = {
|
|
60
|
+
name
|
|
61
|
+
};
|
|
62
|
+
this.aggregator.store(type, name, params, metrics);
|
|
63
|
+
}
|
|
64
|
+
singleChecks() {
|
|
65
|
+
// report generic info about the agent itself
|
|
66
|
+
// note the browser agent version
|
|
67
|
+
this.storeSupportabilityMetrics(`Generic/Version/${_environmentVariables.VERSION}/Detected`);
|
|
68
|
+
// report loaderType
|
|
69
|
+
const {
|
|
70
|
+
distMethod,
|
|
71
|
+
loaderType
|
|
72
|
+
} = (0, _config.getRuntime)(this.agentIdentifier);
|
|
73
|
+
if (loaderType) this.storeSupportabilityMetrics(`Generic/LoaderType/${loaderType}/Detected`);
|
|
74
|
+
if (distMethod) this.storeSupportabilityMetrics(`Generic/DistMethod/${distMethod}/Detected`);
|
|
75
|
+
|
|
76
|
+
// frameworks on page
|
|
77
|
+
if (_globalScope.isBrowserScope) {
|
|
78
|
+
(0, _load.onDOMContentLoaded)(() => {
|
|
79
|
+
(0, _frameworkDetection.getFrameworks)().forEach(framework => {
|
|
80
|
+
this.storeSupportabilityMetrics('Framework/' + framework + '/Detected');
|
|
81
|
+
});
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// file protocol detection
|
|
86
|
+
if (_protocol.protocol.isFileProtocol()) {
|
|
87
|
+
this.storeSupportabilityMetrics('Generic/FileProtocol/Detected');
|
|
88
|
+
_protocol.protocol.supportabilityMetricSent = true;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// obfuscation rules detection
|
|
92
|
+
const rules = (0, _obfuscate.getRules)(this.agentIdentifier);
|
|
93
|
+
if (rules.length > 0) this.storeSupportabilityMetrics('Generic/Obfuscate/Detected');
|
|
94
|
+
if (rules.length > 0 && !(0, _obfuscate.validateRules)(rules)) this.storeSupportabilityMetrics('Generic/Obfuscate/Invalid');
|
|
95
|
+
}
|
|
96
|
+
eachSessionChecks() {
|
|
97
|
+
if (!_globalScope.isBrowserScope) return;
|
|
98
|
+
|
|
99
|
+
// [Temporary] Report restores from BFCache to NR1 while feature flag is in place in lieu of sending pageshow events.
|
|
100
|
+
(0, _eventListenerOpts.windowAddEventListener)('pageshow', evt => {
|
|
101
|
+
if (evt.persisted) {
|
|
102
|
+
this.storeSupportabilityMetrics('Generic/BFCache/PageRestored');
|
|
103
|
+
}
|
|
104
|
+
return;
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
unload() {
|
|
108
|
+
// Page Resources detection for estimations with resources feature work
|
|
109
|
+
// TODO - these SMs are to be removed when we implement the actual resources feature
|
|
110
|
+
try {
|
|
111
|
+
if (this.resourcesSent) return;
|
|
112
|
+
// make sure this only gets sent once
|
|
113
|
+
this.resourcesSent = true;
|
|
114
|
+
// differentiate between internal+external and ajax+non-ajax
|
|
115
|
+
const ajaxResources = ['beacon', 'fetch', 'xmlhttprequest'];
|
|
116
|
+
const internalUrls = ['nr-data.net', 'newrelic.com', 'nr-local.net', 'localhost'];
|
|
117
|
+
function isInternal(x) {
|
|
118
|
+
return internalUrls.some(y => x.name.indexOf(y) >= 0);
|
|
119
|
+
}
|
|
120
|
+
function isAjax(x) {
|
|
121
|
+
return ajaxResources.includes(x.initiatorType);
|
|
122
|
+
}
|
|
123
|
+
const allResources = performance?.getEntriesByType('resource') || [];
|
|
124
|
+
allResources.forEach(entry => {
|
|
125
|
+
if (isInternal(entry)) {
|
|
126
|
+
if (isAjax(entry)) this.storeSupportabilityMetrics('Generic/Resources/Ajax/Internal');else this.storeSupportabilityMetrics('Generic/Resources/Non-Ajax/Internal');
|
|
127
|
+
} else {
|
|
128
|
+
if (isAjax(entry)) this.storeSupportabilityMetrics('Generic/Resources/Ajax/External');else this.storeSupportabilityMetrics('Generic/Resources/Non-Ajax/External');
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
} catch (e) {
|
|
132
|
+
// do nothing
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
exports.Aggregate = Aggregate;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.SUPPORTABILITY_METRIC_CHANNEL = exports.SUPPORTABILITY_METRIC = exports.FEATURE_NAME = exports.CUSTOM_METRIC_CHANNEL = exports.CUSTOM_METRIC = void 0;
|
|
7
|
+
var _features = require("../../loaders/features/features");
|
|
8
|
+
const FEATURE_NAME = _features.FEATURE_NAMES.metrics;
|
|
9
|
+
exports.FEATURE_NAME = FEATURE_NAME;
|
|
10
|
+
const SUPPORTABILITY_METRIC = 'sm';
|
|
11
|
+
exports.SUPPORTABILITY_METRIC = SUPPORTABILITY_METRIC;
|
|
12
|
+
const CUSTOM_METRIC = 'cm';
|
|
13
|
+
exports.CUSTOM_METRIC = CUSTOM_METRIC;
|
|
14
|
+
const SUPPORTABILITY_METRIC_CHANNEL = 'storeSupportabilityMetrics';
|
|
15
|
+
exports.SUPPORTABILITY_METRIC_CHANNEL = SUPPORTABILITY_METRIC_CHANNEL;
|
|
16
|
+
const CUSTOM_METRIC_CHANNEL = 'storeEventMetrics';
|
|
17
|
+
exports.CUSTOM_METRIC_CHANNEL = CUSTOM_METRIC_CHANNEL;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "Metrics", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _index.Instrument;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _index = require("./instrument/index");
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Instrument = void 0;
|
|
7
|
+
var _instrumentBase = require("../../utils/instrument-base");
|
|
8
|
+
var _workersHelper = require("./workers-helper");
|
|
9
|
+
var _constants = require("../constants");
|
|
10
|
+
var _handle = require("../../../common/event-emitter/handle");
|
|
11
|
+
var _features = require("../../../loaders/features/features");
|
|
12
|
+
class Instrument extends _instrumentBase.InstrumentBase {
|
|
13
|
+
static featureName = _constants.FEATURE_NAME;
|
|
14
|
+
constructor(agentIdentifier, aggregator, auto = true) {
|
|
15
|
+
super(agentIdentifier, aggregator, _constants.FEATURE_NAME, auto);
|
|
16
|
+
(0, _workersHelper.insertSupportMetrics)(tag => (0, _handle.handle)(_constants.SUPPORTABILITY_METRIC_CHANNEL, [tag], undefined, _features.FEATURE_NAMES.metrics, this.ee));
|
|
17
|
+
this.importAggregator();
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
exports.Instrument = Instrument;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.insertSupportMetrics = insertSupportMetrics;
|
|
7
|
+
var _globalScope = require("../../../common/util/global-scope");
|
|
8
|
+
var _console = require("../../../common/util/console");
|
|
9
|
+
/**
|
|
10
|
+
* True for each Worker type supported in browser's execution context. Not all browser versions may support certain Workers or options however.
|
|
11
|
+
* - Warning: service workers are not available on unsecured HTTP sites
|
|
12
|
+
*/
|
|
13
|
+
const workersApiIsSupported = {
|
|
14
|
+
dedicated: Boolean(_globalScope.globalScope?.Worker),
|
|
15
|
+
shared: Boolean(_globalScope.globalScope?.SharedWorker),
|
|
16
|
+
service: Boolean(_globalScope.globalScope?.navigator?.serviceWorker)
|
|
17
|
+
};
|
|
18
|
+
let origWorker, origSharedWorker, origServiceWorkerCreate;
|
|
19
|
+
/**
|
|
20
|
+
* Un-instrument support metrics for Workers.
|
|
21
|
+
* @returns void
|
|
22
|
+
*/
|
|
23
|
+
function resetSupportability() {
|
|
24
|
+
if (origWorker) _globalScope.globalScope.Worker = origWorker; // Worker was changed by this module
|
|
25
|
+
if (origSharedWorker) _globalScope.globalScope.SharedWorker = origSharedWorker;
|
|
26
|
+
if (origServiceWorkerCreate) _globalScope.globalScope.navigator.serviceWorker.register = origServiceWorkerCreate;
|
|
27
|
+
origWorker = origSharedWorker = origServiceWorkerCreate = undefined;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Injects code to report Web Workers supportability and usage as metrics, replacing the native API in global scope as a side effect.
|
|
32
|
+
* @param {Function} report - a cb used to report data
|
|
33
|
+
* @returns void
|
|
34
|
+
*/
|
|
35
|
+
function insertSupportMetrics(report) {
|
|
36
|
+
// Of the 3, the normal worker is the most widely supported, so we can be sure metric was already inserted w/o checking other 2.
|
|
37
|
+
if (origWorker) return;
|
|
38
|
+
if (!workersApiIsSupported.dedicated) {
|
|
39
|
+
reportUnavailable('All');
|
|
40
|
+
return; // similarly, if dedicated is n/a, none of them are supported so quit
|
|
41
|
+
} else {
|
|
42
|
+
origWorker = Worker;
|
|
43
|
+
try {
|
|
44
|
+
_globalScope.globalScope.Worker = extendWorkerConstructor(origWorker, 'Dedicated');
|
|
45
|
+
} catch (e) {
|
|
46
|
+
handleInsertionError(e, 'Dedicated');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (!workersApiIsSupported.shared) {
|
|
50
|
+
reportUnavailable('Shared');
|
|
51
|
+
} else {
|
|
52
|
+
origSharedWorker = SharedWorker;
|
|
53
|
+
try {
|
|
54
|
+
_globalScope.globalScope.SharedWorker = extendWorkerConstructor(origSharedWorker, 'Shared');
|
|
55
|
+
} catch (e) {
|
|
56
|
+
handleInsertionError(e, 'Shared');
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
if (!workersApiIsSupported.service) {
|
|
60
|
+
reportUnavailable('Service');
|
|
61
|
+
} else {
|
|
62
|
+
origServiceWorkerCreate = navigator.serviceWorker.register;
|
|
63
|
+
try {
|
|
64
|
+
_globalScope.globalScope.navigator.serviceWorker.register = extendServiceCreation(origServiceWorkerCreate);
|
|
65
|
+
} catch (e) {
|
|
66
|
+
handleInsertionError(e, 'Service');
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return;
|
|
70
|
+
|
|
71
|
+
// Internal helpers - Core
|
|
72
|
+
/**
|
|
73
|
+
* Report each time a Worker or SharedWorker is created in page execution. Note the current trap is set for only "new" and Reflect.construct operations.
|
|
74
|
+
* @param {func obj} origClass - Worker() or SharedWorker()
|
|
75
|
+
* @param {string} workerType - 'Dedicated' or 'Shared'
|
|
76
|
+
* @returns Proxy worker that intercepts the original constructor
|
|
77
|
+
*/
|
|
78
|
+
function extendWorkerConstructor(origClass, workerType) {
|
|
79
|
+
if (typeof Proxy === 'undefined') {
|
|
80
|
+
return origClass;
|
|
81
|
+
}
|
|
82
|
+
const newHandler = {
|
|
83
|
+
construct(oConstructor, args) {
|
|
84
|
+
reportWorkerCreationAttempt(workerType, args[1]?.type);
|
|
85
|
+
return new oConstructor(...args);
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
// eslint-disable-next-line
|
|
89
|
+
return new Proxy(origClass, newHandler);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Report each time a ServiceWorkerRegistration is created or updated in page execution.
|
|
93
|
+
* @param {func} origFunc - method responsible for creating a ServiceWorker
|
|
94
|
+
* @returns Refer to ServiceWorkerContainer.register()
|
|
95
|
+
*/
|
|
96
|
+
function extendServiceCreation(origFunc) {
|
|
97
|
+
return (...args) => {
|
|
98
|
+
reportWorkerCreationAttempt('Service', args[1]?.type);
|
|
99
|
+
return origFunc.apply(navigator.serviceWorker, args); // register() has to be rebound to the ServiceWorkerContainer object
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Internal helpers - Reporting & logging
|
|
104
|
+
function reportUnavailable(workerType) {
|
|
105
|
+
if (_globalScope.isWorkerScope) return; // assume that the main browser window has already reported unsupported worker APIs (once per page life);
|
|
106
|
+
// on top of that, not all workers are available inside a certain worker per se--e.g. no sharedWorker() inside Worker
|
|
107
|
+
report(`Workers/${workerType}/Unavailable`);
|
|
108
|
+
}
|
|
109
|
+
function reportWorkerCreationAttempt(workerType, optionType) {
|
|
110
|
+
if (optionType === 'module') {
|
|
111
|
+
report(`Workers/${workerType}/Module`);
|
|
112
|
+
} else {
|
|
113
|
+
report(`Workers/${workerType}/Classic`);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
function handleInsertionError(e, workerType) {
|
|
117
|
+
// indicates the browser version doesn't support how code is injected, such as Proxy API
|
|
118
|
+
report(`Workers/${workerType}/SM/Unsupported`); // expected to be niche & for older borderline-ES6 browser versions
|
|
119
|
+
(0, _console.warn)(`NR Agent: Unable to capture ${workerType} workers.`, e);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Aggregate = void 0;
|
|
7
|
+
var _mapOwn = require("../../../common/util/map-own");
|
|
8
|
+
var _stringify = require("../../../common/util/stringify");
|
|
9
|
+
var _registerHandler = require("../../../common/event-emitter/register-handler");
|
|
10
|
+
var _harvestScheduler = require("../../../common/harvest/harvest-scheduler");
|
|
11
|
+
var _cleanUrl = require("../../../common/url/clean-url");
|
|
12
|
+
var _config = require("../../../common/config/config");
|
|
13
|
+
var _aggregateBase = require("../../utils/aggregate-base");
|
|
14
|
+
var _constants = require("../constants");
|
|
15
|
+
var _drain = require("../../../common/drain/drain");
|
|
16
|
+
var _globalScope = require("../../../common/util/global-scope");
|
|
17
|
+
/*
|
|
18
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
19
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
class Aggregate extends _aggregateBase.AggregateBase {
|
|
23
|
+
static featureName = _constants.FEATURE_NAME;
|
|
24
|
+
constructor(agentIdentifier, aggregator) {
|
|
25
|
+
super(agentIdentifier, aggregator, _constants.FEATURE_NAME);
|
|
26
|
+
this.eventsPerMinute = 240;
|
|
27
|
+
this.harvestTimeSeconds = (0, _config.getConfigurationValue)(this.agentIdentifier, 'page_action.harvestTimeSeconds') || (0, _config.getConfigurationValue)(this.agentIdentifier, 'ins.harvestTimeSeconds') || 30;
|
|
28
|
+
this.eventsPerHarvest = this.eventsPerMinute * this.harvestTimeSeconds / 60;
|
|
29
|
+
this.referrerUrl;
|
|
30
|
+
this.currentEvents;
|
|
31
|
+
this.events = [];
|
|
32
|
+
this.att = (0, _config.getInfo)(this.agentIdentifier).jsAttributes; // per-agent, aggregators-shared info context
|
|
33
|
+
|
|
34
|
+
if (_globalScope.isBrowserScope && document.referrer) this.referrerUrl = (0, _cleanUrl.cleanURL)(document.referrer);
|
|
35
|
+
(0, _registerHandler.registerHandler)('api-addPageAction', (...args) => this.addPageAction(...args), this.featureName, this.ee);
|
|
36
|
+
var scheduler = new _harvestScheduler.HarvestScheduler('ins', {
|
|
37
|
+
onFinished: (...args) => this.onHarvestFinished(...args)
|
|
38
|
+
}, this);
|
|
39
|
+
scheduler.harvest.on('ins', (...args) => this.onHarvestStarted(...args));
|
|
40
|
+
this.ee.on(`drain-${this.featureName}`, () => {
|
|
41
|
+
if (!this.blocked) scheduler.startTimer(this.harvestTimeSeconds, 0);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
// if rum response determines that customer lacks entitlements for ins endpoint, block it
|
|
45
|
+
(0, _registerHandler.registerHandler)('block-ins', () => {
|
|
46
|
+
this.blocked = true;
|
|
47
|
+
scheduler.stopTimer(true);
|
|
48
|
+
}, this.featureName, this.ee);
|
|
49
|
+
(0, _drain.drain)(this.agentIdentifier, this.featureName);
|
|
50
|
+
}
|
|
51
|
+
onHarvestStarted(options) {
|
|
52
|
+
const {
|
|
53
|
+
userAttributes,
|
|
54
|
+
atts
|
|
55
|
+
} = (0, _config.getInfo)(this.agentIdentifier);
|
|
56
|
+
var payload = {
|
|
57
|
+
qs: {
|
|
58
|
+
ua: userAttributes,
|
|
59
|
+
at: atts
|
|
60
|
+
},
|
|
61
|
+
body: {
|
|
62
|
+
ins: this.events
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
if (options.retry) {
|
|
66
|
+
this.currentEvents = this.events;
|
|
67
|
+
}
|
|
68
|
+
this.events = [];
|
|
69
|
+
return payload;
|
|
70
|
+
}
|
|
71
|
+
onHarvestFinished(result) {
|
|
72
|
+
if (result && result.sent && result.retry && this.currentEvents) {
|
|
73
|
+
this.events = this.events.concat(this.currentEvents);
|
|
74
|
+
this.currentEvents = null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// WARNING: Insights times are in seconds. EXCEPT timestamp, which is in ms.
|
|
79
|
+
addPageAction(t, name, attributes) {
|
|
80
|
+
if (this.events.length >= this.eventsPerHarvest || this.blocked) return;
|
|
81
|
+
var width;
|
|
82
|
+
var height;
|
|
83
|
+
var eventAttributes = {};
|
|
84
|
+
if (_globalScope.isBrowserScope && window.document.documentElement) {
|
|
85
|
+
// Doesn't include the nav bar when it disappears in mobile safari
|
|
86
|
+
// https://github.com/jquery/jquery/blob/10399ddcf8a239acc27bdec9231b996b178224d3/src/dimensions.js#L23
|
|
87
|
+
width = window.document.documentElement.clientWidth;
|
|
88
|
+
height = window.document.documentElement.clientHeight;
|
|
89
|
+
}
|
|
90
|
+
var defaults = {
|
|
91
|
+
timestamp: t + (0, _config.getRuntime)(this.agentIdentifier).offset,
|
|
92
|
+
timeSinceLoad: t / 1000,
|
|
93
|
+
browserWidth: width,
|
|
94
|
+
browserHeight: height,
|
|
95
|
+
referrerUrl: this.referrerUrl,
|
|
96
|
+
currentUrl: (0, _cleanUrl.cleanURL)('' + location),
|
|
97
|
+
pageUrl: (0, _cleanUrl.cleanURL)((0, _config.getRuntime)(this.agentIdentifier).origin),
|
|
98
|
+
eventType: 'PageAction'
|
|
99
|
+
};
|
|
100
|
+
(0, _mapOwn.mapOwn)(defaults, set);
|
|
101
|
+
(0, _mapOwn.mapOwn)((0, _config.getInfo)(this.agentIdentifier).jsAttributes, set);
|
|
102
|
+
if (attributes && typeof attributes === 'object') {
|
|
103
|
+
(0, _mapOwn.mapOwn)(attributes, set);
|
|
104
|
+
}
|
|
105
|
+
eventAttributes.actionName = name || '';
|
|
106
|
+
this.events.push(eventAttributes);
|
|
107
|
+
function set(key, val) {
|
|
108
|
+
eventAttributes[key] = val && typeof val === 'object' ? (0, _stringify.stringify)(val) : val;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
exports.Aggregate = Aggregate;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.FEATURE_NAME = void 0;
|
|
7
|
+
var _features = require("../../loaders/features/features");
|
|
8
|
+
const FEATURE_NAME = _features.FEATURE_NAMES.pageAction;
|
|
9
|
+
exports.FEATURE_NAME = FEATURE_NAME;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "PageAction", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _index.Instrument;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _index = require("./instrument/index");
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Instrument = void 0;
|
|
7
|
+
var _instrumentBase = require("../../utils/instrument-base");
|
|
8
|
+
var _constants = require("../constants");
|
|
9
|
+
/*
|
|
10
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
11
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
class Instrument extends _instrumentBase.InstrumentBase {
|
|
15
|
+
static featureName = _constants.FEATURE_NAME;
|
|
16
|
+
constructor(agentIdentifier, aggregator, auto = true) {
|
|
17
|
+
super(agentIdentifier, aggregator, _constants.FEATURE_NAME, auto);
|
|
18
|
+
this.importAggregator();
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.Instrument = Instrument;
|