@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,41 @@
|
|
|
1
|
+
import * as userAgent from '../../util/user-agent';
|
|
2
|
+
import { Configurable } from './configurable';
|
|
3
|
+
import { gosNREUMInitializedAgents } from '../../window/nreum';
|
|
4
|
+
import { getCurrentSessionIdOrMakeNew } from '../../window/session-storage';
|
|
5
|
+
import { getConfigurationValue } from '../config';
|
|
6
|
+
import { globalScope } from '../../util/global-scope';
|
|
7
|
+
import { BUILD_ENV, DIST_METHOD, VERSION } from '../../constants/environment-variables';
|
|
8
|
+
const model = agentId => {
|
|
9
|
+
return {
|
|
10
|
+
buildEnv: BUILD_ENV,
|
|
11
|
+
customTransaction: undefined,
|
|
12
|
+
disabled: false,
|
|
13
|
+
distMethod: DIST_METHOD,
|
|
14
|
+
isolatedBacklog: false,
|
|
15
|
+
loaderType: undefined,
|
|
16
|
+
maxBytes: 30000,
|
|
17
|
+
// The "timeOrigin" property is the new standard timestamp property shared across main frame and workers, but is not supported in some early Safari browsers (safari<15) + IE
|
|
18
|
+
// ingest expects an integer value, and timeOrigin can return a float.
|
|
19
|
+
offset: Math.floor(globalScope?.performance?.timeOrigin || globalScope?.performance?.timing?.navigationStart || Date.now()),
|
|
20
|
+
onerror: undefined,
|
|
21
|
+
origin: '' + globalScope.location,
|
|
22
|
+
ptid: undefined,
|
|
23
|
+
releaseIds: {},
|
|
24
|
+
sessionId: getConfigurationValue(agentId, 'privacy.cookies_enabled') == true ? getCurrentSessionIdOrMakeNew() : null,
|
|
25
|
+
// if cookies (now session tracking) is turned off or can't get session ID, this is null
|
|
26
|
+
xhrWrappable: typeof globalScope.XMLHttpRequest?.prototype?.addEventListener === 'function',
|
|
27
|
+
userAgent,
|
|
28
|
+
version: VERSION
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
const _cache = {};
|
|
32
|
+
export function getRuntime(id) {
|
|
33
|
+
if (!id) throw new Error('All runtime objects require an agent identifier!');
|
|
34
|
+
if (!_cache[id]) throw new Error(`Runtime for ${id} was never set`);
|
|
35
|
+
return _cache[id];
|
|
36
|
+
}
|
|
37
|
+
export function setRuntime(id, obj) {
|
|
38
|
+
if (!id) throw new Error('All runtime objects require an agent identifier!');
|
|
39
|
+
_cache[id] = new Configurable(obj, model(id));
|
|
40
|
+
gosNREUMInitializedAgents(id, _cache[id], 'runtime');
|
|
41
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// Webpack and NPM builds define `process.env.BUILD_VERSION` at build time based on variables supplied at build time.
|
|
2
|
+
// VERSION as defined here ends up decorating: agent runtime configuration, harvest, and supportability metrics.
|
|
3
|
+
export const VERSION = typeof "0.1.229" !== 'undefined' && "0.1.229" || '';
|
|
4
|
+
|
|
5
|
+
// process.env.BUILD_ENV is replaced during webpack -or- npm build with environment vars supplied at build time
|
|
6
|
+
// LOCAL, PROD, DEV, etc
|
|
7
|
+
export const BUILD_ENV = typeof "NPM" !== 'undefined' && "NPM" || '';
|
|
8
|
+
|
|
9
|
+
// process.env.DIST_METHOD is replaced during webpack -or- npm build with environment vars supplied at build time
|
|
10
|
+
// CDN, NPM etc
|
|
11
|
+
export const DIST_METHOD = typeof "NPM" !== 'undefined' && "NPM" || '';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { warn } from '../util/console';
|
|
2
|
+
const model = {
|
|
3
|
+
agentIdentifier: ''
|
|
4
|
+
};
|
|
5
|
+
export class SharedContext {
|
|
6
|
+
constructor(context) {
|
|
7
|
+
try {
|
|
8
|
+
if (typeof context !== 'object') return warn('shared context requires an object as input');
|
|
9
|
+
this.sharedContext = {};
|
|
10
|
+
Object.assign(this.sharedContext, model);
|
|
11
|
+
Object.entries(context).forEach(([key, value]) => {
|
|
12
|
+
if (Object.keys(model).includes(key)) this.sharedContext[key] = value;
|
|
13
|
+
});
|
|
14
|
+
} catch (err) {
|
|
15
|
+
warn('An error occured while setting SharedContext', err);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/** An array of filter objects {hostname, pathname} for identifying XHR events to be excluded from collection.
|
|
2
|
+
* @see {@link https://docs.newrelic.com/docs/browser/new-relic-browser/configuration/filter-ajax-request-events/ Filter AjaxRequest events}
|
|
3
|
+
* @type {Array.<{hostname: string, pathname: string}>}
|
|
4
|
+
*/
|
|
5
|
+
var denyList = [];
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Evaluates whether an XHR event should be included for collection based on the {@link denyList|AjaxRequest deny list}.
|
|
9
|
+
* @param {Object} params - object with properties of the XHR event
|
|
10
|
+
* @returns {boolean} `true` if request does not match any entries of {@link denyList|deny list}; else `false`
|
|
11
|
+
*/
|
|
12
|
+
export function shouldCollectEvent(params) {
|
|
13
|
+
if (denyList.length === 0) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// XHR requests with an undefined hostname (e.g., data URLs) should not be collected.
|
|
18
|
+
if (params.hostname === undefined) {
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
for (var i = 0; i < denyList.length; i++) {
|
|
22
|
+
var parsed = denyList[i];
|
|
23
|
+
if (parsed.hostname === '*') {
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
if (domainMatchesPattern(parsed.hostname, params.hostname) && comparePath(parsed.pathname, params.pathname)) {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Initializes the {@link denyList|XHR deny list} by extracting hostname and pathname from an array of filter strings.
|
|
35
|
+
* @param {string[]} denyListConfig - array of URL filters to identify XHR requests to be excluded from collection
|
|
36
|
+
*/
|
|
37
|
+
export function setDenyList(denyListConfig) {
|
|
38
|
+
denyList = [];
|
|
39
|
+
if (!denyListConfig || !denyListConfig.length) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
for (var i = 0; i < denyListConfig.length; i++) {
|
|
43
|
+
var url = denyListConfig[i];
|
|
44
|
+
if (url.indexOf('http://') === 0) {
|
|
45
|
+
url = url.substring(7);
|
|
46
|
+
} else if (url.indexOf('https://') === 0) {
|
|
47
|
+
url = url.substring(8);
|
|
48
|
+
}
|
|
49
|
+
var firstSlash = url.indexOf('/');
|
|
50
|
+
if (firstSlash > 0) {
|
|
51
|
+
denyList.push({
|
|
52
|
+
hostname: url.substring(0, firstSlash),
|
|
53
|
+
pathname: url.substring(firstSlash)
|
|
54
|
+
});
|
|
55
|
+
} else {
|
|
56
|
+
denyList.push({
|
|
57
|
+
hostname: url,
|
|
58
|
+
pathname: ''
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Returns true if the right side of `domain` (end of string) matches `pattern`.
|
|
65
|
+
* @param {string} pattern - a string to be matched against the end of `domain` string
|
|
66
|
+
* @param {string} domain - a domain string with no protocol or path (e.g., app1.example.com)
|
|
67
|
+
* @returns {boolean} `true` if domain matches pattern; else `false`
|
|
68
|
+
*/
|
|
69
|
+
function domainMatchesPattern(pattern, domain) {
|
|
70
|
+
if (pattern.length > domain.length) {
|
|
71
|
+
return false;
|
|
72
|
+
}
|
|
73
|
+
if (domain.indexOf(pattern) === domain.length - pattern.length) {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Returns true if a URL path matches a pattern string, disregarding leading slashes.
|
|
81
|
+
* @param {string} pattern - a string to compare with path (e.g., api/v1)
|
|
82
|
+
* @param {string} path - a string representing a URL path (e.g., /api/v1)
|
|
83
|
+
* @returns {boolean} `true` if path and pattern are an exact string match (except for leading slashes); else `false`
|
|
84
|
+
*/
|
|
85
|
+
function comparePath(pattern, path) {
|
|
86
|
+
if (pattern.indexOf('/') === 0) {
|
|
87
|
+
pattern = pattern.substring(1);
|
|
88
|
+
}
|
|
89
|
+
if (path.indexOf('/') === 0) {
|
|
90
|
+
path = path.substring(1);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// No path in pattern means match all paths.
|
|
94
|
+
if (pattern === '') {
|
|
95
|
+
return true;
|
|
96
|
+
}
|
|
97
|
+
if (pattern === path) {
|
|
98
|
+
return true;
|
|
99
|
+
}
|
|
100
|
+
return false;
|
|
101
|
+
}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { ee } from '../event-emitter/contextual-ee';
|
|
7
|
+
import { mapOwn } from '../util/map-own';
|
|
8
|
+
import { registerHandler as defaultRegister } from '../event-emitter/register-handler';
|
|
9
|
+
import { featurePriority } from '../../loaders/features/features';
|
|
10
|
+
const registry = {};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Adds an entry to the centralized drain registry specifying that a particular agent has events of a particular named
|
|
14
|
+
* event-group "bucket" that should be drained at the time the agent drains all its buffered events. Buffered events
|
|
15
|
+
* accumulate because instrumentation begins as soon as possible, before the agent has finished lazy-loading the code
|
|
16
|
+
* responsible for aggregating and reporting captured data.
|
|
17
|
+
* @param {string} agentIdentifier - A 16 character string uniquely identifying the agent.
|
|
18
|
+
* @param {string} group - The named "bucket" for the events this feature will be bucketing for later collection.
|
|
19
|
+
*/
|
|
20
|
+
export function registerDrain(agentIdentifier, group) {
|
|
21
|
+
// Here `item` captures the registered properties of a feature-group: whether it is ready for its buffered events
|
|
22
|
+
// to be drained (`staged`) and the `priority` order in which it should be drained relative to other feature groups.
|
|
23
|
+
const item = {
|
|
24
|
+
staged: false,
|
|
25
|
+
priority: featurePriority[group] || 0
|
|
26
|
+
};
|
|
27
|
+
curateRegistry(agentIdentifier);
|
|
28
|
+
if (!registry[agentIdentifier].get(group)) registry[agentIdentifier].set(group, item);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Registers the specified agent with the centralized event buffer registry if it is not already registered.
|
|
33
|
+
* Agents without an identifier (as in the case of some tests) will be excluded from the registry.
|
|
34
|
+
* @param {string} agentIdentifier - A 16 character string uniquely identifying an agent.
|
|
35
|
+
*/
|
|
36
|
+
function curateRegistry(agentIdentifier) {
|
|
37
|
+
if (!agentIdentifier) return;
|
|
38
|
+
if (!registry[agentIdentifier]) registry[agentIdentifier] = new Map();
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* Drain buffered events out of the event emitter. Each feature should have its events bucketed by "group" and drain
|
|
43
|
+
* its own named group explicitly, when ready.
|
|
44
|
+
* @param {string} agentIdentifier - A unique 16 character ID corresponding to an instantiated agent.
|
|
45
|
+
* @param {string} featureName - A named group into which the feature's buffered events are bucketed.
|
|
46
|
+
*/
|
|
47
|
+
export function drain(agentIdentifier = '', featureName = 'feature') {
|
|
48
|
+
curateRegistry(agentIdentifier);
|
|
49
|
+
|
|
50
|
+
// If the feature for the specified agent is not in the registry, that means the instrument file was bypassed.
|
|
51
|
+
// This could happen in tests, or loaders that directly import the aggregator. In these cases it is safe to
|
|
52
|
+
// drain the feature group immediately rather than waiting to drain all at once.
|
|
53
|
+
if (!agentIdentifier || !registry[agentIdentifier].get(featureName)) return drainGroup(featureName);
|
|
54
|
+
|
|
55
|
+
// When `drain` is called, this feature is ready to drain (staged).
|
|
56
|
+
registry[agentIdentifier].get(featureName).staged = true;
|
|
57
|
+
|
|
58
|
+
// Only when the event-groups for all features are ready to drain (staged) do we execute the drain. This has the effect
|
|
59
|
+
// that the last feature to call drain triggers drain for all features.
|
|
60
|
+
const items = Array.from(registry[agentIdentifier]);
|
|
61
|
+
if (items.every(([key, values]) => values.staged)) {
|
|
62
|
+
items.sort((a, b) => a[1].priority - b[1].priority);
|
|
63
|
+
items.forEach(([group]) => {
|
|
64
|
+
drainGroup(group);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Drains all the buffered (backlog) events for a particular feature's event-group by emitting each event to each of
|
|
70
|
+
* the subscribed handlers for the group.
|
|
71
|
+
* @param {*} group - The name of a particular feature's event "bucket".
|
|
72
|
+
*/
|
|
73
|
+
function drainGroup(group) {
|
|
74
|
+
const baseEE = agentIdentifier ? ee.get(agentIdentifier) : ee;
|
|
75
|
+
const handlers = defaultRegister.handlers;
|
|
76
|
+
if (!baseEE.backlog || !handlers) return;
|
|
77
|
+
var bufferedEventsInGroup = baseEE.backlog[group];
|
|
78
|
+
var groupHandlers = handlers[group];
|
|
79
|
+
if (groupHandlers) {
|
|
80
|
+
// We don't cache the length of the buffer while looping because events might still be added while processing.
|
|
81
|
+
for (var i = 0; bufferedEventsInGroup && i < bufferedEventsInGroup.length; ++i) {
|
|
82
|
+
// eslint-disable-line no-unmodified-loop-condition
|
|
83
|
+
emitEvent(bufferedEventsInGroup[i], groupHandlers);
|
|
84
|
+
}
|
|
85
|
+
mapOwn(groupHandlers, function (eventType, handlerRegistrationList) {
|
|
86
|
+
mapOwn(handlerRegistrationList, function (i, registration) {
|
|
87
|
+
// registration is an array of: [targetEE, eventHandler]
|
|
88
|
+
registration[0].on(eventType, registration[1]);
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
delete handlers[group];
|
|
93
|
+
|
|
94
|
+
// Keep the feature's event-group as a property of the event emitter so we know it was already created and drained.
|
|
95
|
+
baseEE.backlog[group] = null;
|
|
96
|
+
baseEE.emit('drain-' + group, []);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Processes the specified event using all relevant handler functions associated with a particular feature, based on
|
|
102
|
+
* whether the the handler is meant to apply to events of this type. (Event type is a descriptive string set at the
|
|
103
|
+
* time an event is originally created by instrumentation, as with calls to the `handle` method.)
|
|
104
|
+
* @param {*} evt - A single event to be emitted to (processed by) eligible handler functions.
|
|
105
|
+
* @param {*} groupHandlers - A set of handler functions associated with a particular feature's event-group.
|
|
106
|
+
*/
|
|
107
|
+
function emitEvent(evt, groupHandlers) {
|
|
108
|
+
var type = evt[1];
|
|
109
|
+
mapOwn(groupHandlers[type], function (i, registration) {
|
|
110
|
+
var sourceEE = evt[0];
|
|
111
|
+
var ee = registration[0];
|
|
112
|
+
if (ee === sourceEE) {
|
|
113
|
+
var handler = registration[1];
|
|
114
|
+
var ctx = evt[3];
|
|
115
|
+
var args = evt[2];
|
|
116
|
+
handler.apply(ctx, args);
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { gosNREUM } from '../window/nreum';
|
|
7
|
+
import { getOrSet } from '../util/get-or-set';
|
|
8
|
+
import { mapOwn } from '../util/map-own';
|
|
9
|
+
import { getRuntime } from '../config/config';
|
|
10
|
+
var ctxId = 'nr@context';
|
|
11
|
+
|
|
12
|
+
// create global emitter instance that can be shared among bundles
|
|
13
|
+
let nr = gosNREUM();
|
|
14
|
+
var globalInstance;
|
|
15
|
+
if (nr.ee) {
|
|
16
|
+
globalInstance = nr.ee;
|
|
17
|
+
} else {
|
|
18
|
+
globalInstance = ee(undefined, 'globalEE');
|
|
19
|
+
nr.ee = globalInstance;
|
|
20
|
+
}
|
|
21
|
+
export { globalInstance as ee };
|
|
22
|
+
function EventContext() {}
|
|
23
|
+
function ee(old, debugId) {
|
|
24
|
+
var handlers = {};
|
|
25
|
+
var bufferGroupMap = {};
|
|
26
|
+
var emitters = {};
|
|
27
|
+
// In cases where multiple agents can run on a page, the event backlogs of feature event emitters must be isolated
|
|
28
|
+
// to prevent event emitter context and buffers from "bubbling up" to other agents operating in the scope.
|
|
29
|
+
// An example of this is our MicroAgent loader package, which sets this property to true to prevent overlap.
|
|
30
|
+
var isolatedBacklog = false;
|
|
31
|
+
try {
|
|
32
|
+
// We only want to check the runtime configuration for `isolatedBacklog` if the event emitter belongs to a feature.
|
|
33
|
+
// For feature event emitters, the debugId will be an agentIdentifier with a length of 16. In contrast, some of our
|
|
34
|
+
// tests do not namespace the event emitter with an agentID and just use the parent (which has no ID).
|
|
35
|
+
isolatedBacklog = debugId.length !== 16 ? false : getRuntime(debugId).isolatedBacklog;
|
|
36
|
+
} catch (err) {
|
|
37
|
+
// Do nothing for now.
|
|
38
|
+
}
|
|
39
|
+
var emitter = {
|
|
40
|
+
on: addEventListener,
|
|
41
|
+
addEventListener: addEventListener,
|
|
42
|
+
removeEventListener: removeEventListener,
|
|
43
|
+
emit: emit,
|
|
44
|
+
get: getOrCreate,
|
|
45
|
+
listeners: listeners,
|
|
46
|
+
context: context,
|
|
47
|
+
buffer: bufferEventsByGroup,
|
|
48
|
+
abort,
|
|
49
|
+
aborted: false,
|
|
50
|
+
isBuffering: isBuffering,
|
|
51
|
+
debugId,
|
|
52
|
+
backlog: isolatedBacklog ? {} : old && typeof old.backlog === 'object' ? old.backlog : {}
|
|
53
|
+
};
|
|
54
|
+
return emitter;
|
|
55
|
+
function context(contextOrStore) {
|
|
56
|
+
if (contextOrStore && contextOrStore instanceof EventContext) {
|
|
57
|
+
return contextOrStore;
|
|
58
|
+
} else if (contextOrStore) {
|
|
59
|
+
return getOrSet(contextOrStore, ctxId, getNewContext);
|
|
60
|
+
} else {
|
|
61
|
+
return getNewContext();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
function emit(type, args, contextOrStore, force, bubble) {
|
|
65
|
+
if (bubble !== false) bubble = true;
|
|
66
|
+
if (globalInstance.aborted && !force) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (old && bubble) old.emit(type, args, contextOrStore);
|
|
70
|
+
var ctx = context(contextOrStore);
|
|
71
|
+
var handlersArray = listeners(type);
|
|
72
|
+
var len = handlersArray.length;
|
|
73
|
+
|
|
74
|
+
// Apply each handler function in the order they were added
|
|
75
|
+
// to the context with the arguments
|
|
76
|
+
|
|
77
|
+
for (var i = 0; i < len; i++) handlersArray[i].apply(ctx, args);
|
|
78
|
+
|
|
79
|
+
// Buffer after emitting for consistent ordering
|
|
80
|
+
var bufferGroup = getBuffer()[bufferGroupMap[type]];
|
|
81
|
+
if (bufferGroup) {
|
|
82
|
+
bufferGroup.push([emitter, type, args, ctx]);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
// Return the context so that the module that emitted can see what was done.
|
|
86
|
+
return ctx;
|
|
87
|
+
}
|
|
88
|
+
function addEventListener(type, fn) {
|
|
89
|
+
// Retrieve type from handlers, if it doesn't exist assign the default and retrieve it.
|
|
90
|
+
handlers[type] = listeners(type).concat(fn);
|
|
91
|
+
}
|
|
92
|
+
function removeEventListener(type, fn) {
|
|
93
|
+
var listeners = handlers[type];
|
|
94
|
+
if (!listeners) return;
|
|
95
|
+
for (var i = 0; i < listeners.length; i++) {
|
|
96
|
+
if (listeners[i] === fn) {
|
|
97
|
+
listeners.splice(i, 1);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
function listeners(type) {
|
|
102
|
+
return handlers[type] || [];
|
|
103
|
+
}
|
|
104
|
+
function getOrCreate(name) {
|
|
105
|
+
return emitters[name] = emitters[name] || ee(emitter, name);
|
|
106
|
+
}
|
|
107
|
+
function bufferEventsByGroup(types, group) {
|
|
108
|
+
var eventBuffer = getBuffer();
|
|
109
|
+
|
|
110
|
+
// do not buffer events if agent has been aborted
|
|
111
|
+
if (emitter.aborted) return;
|
|
112
|
+
mapOwn(types, function (i, type) {
|
|
113
|
+
group = group || 'feature';
|
|
114
|
+
bufferGroupMap[type] = group;
|
|
115
|
+
if (!(group in eventBuffer)) {
|
|
116
|
+
eventBuffer[group] = [];
|
|
117
|
+
}
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
function isBuffering(type) {
|
|
121
|
+
var bufferGroup = getBuffer()[bufferGroupMap[type]];
|
|
122
|
+
return !!bufferGroup;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// buffer is associated with a base emitter, since there are two
|
|
126
|
+
// (global and scoped to the current bundle), it is now part of the emitter
|
|
127
|
+
function getBuffer() {
|
|
128
|
+
return emitter.backlog;
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// get context object from store object, or create if does not exist
|
|
133
|
+
export function getOrSetContext(obj) {
|
|
134
|
+
return getOrSet(obj, ctxId, getNewContext);
|
|
135
|
+
}
|
|
136
|
+
function getNewContext() {
|
|
137
|
+
return new EventContext();
|
|
138
|
+
}
|
|
139
|
+
function abort() {
|
|
140
|
+
globalInstance.aborted = true;
|
|
141
|
+
globalInstance.backlog = {};
|
|
142
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { ee as globalInstance } from './contextual-ee';
|
|
7
|
+
export var handleEE = globalInstance.get('handle');
|
|
8
|
+
export function handle(type, args, ctx, group, ee) {
|
|
9
|
+
if (ee) {
|
|
10
|
+
ee.buffer([type], group);
|
|
11
|
+
ee.emit(type, args, ctx);
|
|
12
|
+
} else {
|
|
13
|
+
handleEE.buffer([type], group);
|
|
14
|
+
handleEE.emit(type, args, ctx);
|
|
15
|
+
}
|
|
16
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { handleEE } from './handle';
|
|
7
|
+
export { defaultRegister as registerHandler };
|
|
8
|
+
defaultRegister.on = registerWithSpecificEmitter;
|
|
9
|
+
var handlers = defaultRegister.handlers = {};
|
|
10
|
+
export function defaultRegister(type, handler, group, ee) {
|
|
11
|
+
registerWithSpecificEmitter(ee || handleEE, handlers, type, handler, group);
|
|
12
|
+
}
|
|
13
|
+
function registerWithSpecificEmitter(ee, handlers, type, handler, group) {
|
|
14
|
+
if (!group) group = 'feature';
|
|
15
|
+
if (!ee) ee = handleEE;
|
|
16
|
+
var groupHandlers = handlers[group] = handlers[group] || {};
|
|
17
|
+
var list = groupHandlers[type] = groupHandlers[type] || [];
|
|
18
|
+
list.push([ee, handler]);
|
|
19
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { globalScope } from '../util/global-scope';
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* See https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#safely_detecting_option_support
|
|
5
|
+
*/
|
|
6
|
+
let passiveSupported = false;
|
|
7
|
+
let signalSupported = false;
|
|
8
|
+
try {
|
|
9
|
+
const options = {
|
|
10
|
+
get passive() {
|
|
11
|
+
// this function will be called when the browser attempts to access the passive property
|
|
12
|
+
passiveSupported = true;
|
|
13
|
+
return false;
|
|
14
|
+
},
|
|
15
|
+
get signal() {
|
|
16
|
+
signalSupported = true;
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
globalScope.addEventListener('test', null, options);
|
|
21
|
+
globalScope.removeEventListener('test', null, options);
|
|
22
|
+
} catch (err) {}
|
|
23
|
+
export function eventListenerOpts(useCapture, abortSignal) {
|
|
24
|
+
return passiveSupported || signalSupported ? {
|
|
25
|
+
capture: !!useCapture,
|
|
26
|
+
passive: passiveSupported,
|
|
27
|
+
// passive defaults to false
|
|
28
|
+
signal: abortSignal
|
|
29
|
+
} : !!useCapture; // mainly just IE11 doesn't support third param options under EventTarget API
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Do not use this within the worker context. */
|
|
33
|
+
export function windowAddEventListener(event, listener, capture = false) {
|
|
34
|
+
window.addEventListener(event, listener, eventListenerOpts(capture));
|
|
35
|
+
}
|
|
36
|
+
/** Do not use this within the worker context. */
|
|
37
|
+
export function documentAddEventListener(event, listener, capture = false) {
|
|
38
|
+
document.addEventListener(event, listener, eventListenerOpts(capture));
|
|
39
|
+
}
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { submitData } from '../util/submit-data';
|
|
7
|
+
import { SharedContext } from '../context/shared-context';
|
|
8
|
+
import { Harvest, getSubmitMethod } from './harvest';
|
|
9
|
+
import { subscribeToEOL } from '../unload/eol';
|
|
10
|
+
import { getConfigurationValue } from '../config/config';
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Periodically invokes harvest calls and handles retries
|
|
14
|
+
*/
|
|
15
|
+
export class HarvestScheduler extends SharedContext {
|
|
16
|
+
constructor(endpoint, opts, parent) {
|
|
17
|
+
super(parent); // gets any allowed properties from the parent and stores them in `sharedContext`
|
|
18
|
+
this.endpoint = endpoint;
|
|
19
|
+
this.opts = opts || {};
|
|
20
|
+
this.started = false;
|
|
21
|
+
this.timeoutHandle = null;
|
|
22
|
+
this.aborted = false; // this controls the per-interval and final harvests for the scheduler (currently per feature specific!)
|
|
23
|
+
|
|
24
|
+
this.harvest = new Harvest(this.sharedContext);
|
|
25
|
+
subscribeToEOL(() => {
|
|
26
|
+
if (this.aborted) return;
|
|
27
|
+
|
|
28
|
+
// If opts.onUnload is defined, these are special actions to execute before attempting to send the final payload.
|
|
29
|
+
if (this.opts.onUnload) this.opts.onUnload();
|
|
30
|
+
this.runHarvest({
|
|
31
|
+
unload: true
|
|
32
|
+
});
|
|
33
|
+
}, getConfigurationValue(this.sharedContext.agentIdentifier, 'allow_bfcache')); // TO DO: remove feature flag after rls stable
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
startTimer(interval, initialDelay) {
|
|
37
|
+
this.interval = interval;
|
|
38
|
+
this.started = true;
|
|
39
|
+
this.scheduleHarvest(initialDelay != null ? initialDelay : this.interval);
|
|
40
|
+
}
|
|
41
|
+
stopTimer(permanently = false) {
|
|
42
|
+
this.aborted = permanently; // stopping permanently is same as aborting, but this function also cleans up the setTimeout loop
|
|
43
|
+
this.started = false;
|
|
44
|
+
if (this.timeoutHandle) {
|
|
45
|
+
clearTimeout(this.timeoutHandle);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
scheduleHarvest(delay, opts) {
|
|
49
|
+
if (this.timeoutHandle) return;
|
|
50
|
+
var timer = this;
|
|
51
|
+
if (delay == null) {
|
|
52
|
+
delay = this.interval;
|
|
53
|
+
}
|
|
54
|
+
this.timeoutHandle = setTimeout(() => {
|
|
55
|
+
timer.timeoutHandle = null;
|
|
56
|
+
timer.runHarvest(opts);
|
|
57
|
+
}, delay * 1000);
|
|
58
|
+
}
|
|
59
|
+
runHarvest(opts) {
|
|
60
|
+
if (this.aborted) return;
|
|
61
|
+
var scheduler = this;
|
|
62
|
+
if (this.opts.getPayload) {
|
|
63
|
+
// Ajax & PVT
|
|
64
|
+
var submitMethod = getSubmitMethod(this.endpoint, opts);
|
|
65
|
+
if (!submitMethod) return false;
|
|
66
|
+
var retry = submitMethod.method === submitData.xhr;
|
|
67
|
+
var payload = this.opts.getPayload({
|
|
68
|
+
retry: retry
|
|
69
|
+
});
|
|
70
|
+
if (payload) {
|
|
71
|
+
payload = Object.prototype.toString.call(payload) === '[object Array]' ? payload : [payload];
|
|
72
|
+
for (var i = 0; i < payload.length; i++) {
|
|
73
|
+
this.harvest.send(this.endpoint, payload[i], opts, submitMethod, onHarvestFinished);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
} else {
|
|
77
|
+
const runAfterSending = opts?.unload ? undefined : onHarvestFinished; // don't bother running onFinish handler if this is the final harvest
|
|
78
|
+
this.harvest.sendX(this.endpoint, opts, runAfterSending);
|
|
79
|
+
}
|
|
80
|
+
if (this.started) {
|
|
81
|
+
this.scheduleHarvest();
|
|
82
|
+
}
|
|
83
|
+
return;
|
|
84
|
+
function onHarvestFinished(result) {
|
|
85
|
+
if (result.blocked) scheduler.onHarvestBlocked(opts, result);else scheduler.onHarvestFinished(opts, result);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
onHarvestFinished(opts, result) {
|
|
89
|
+
if (this.opts.onFinished) {
|
|
90
|
+
this.opts.onFinished(result);
|
|
91
|
+
}
|
|
92
|
+
if (result.sent && result.retry) {
|
|
93
|
+
var delay = result.delay || this.opts.retryDelay;
|
|
94
|
+
// reschedule next harvest if should be delayed longer
|
|
95
|
+
if (this.started && delay) {
|
|
96
|
+
clearTimeout(this.timeoutHandle);
|
|
97
|
+
this.timeoutHandle = null;
|
|
98
|
+
this.scheduleHarvest(delay, opts);
|
|
99
|
+
} else if (!this.started && delay) {
|
|
100
|
+
// if not running on a timer, schedule a single retry
|
|
101
|
+
this.scheduleHarvest(delay, opts);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|