@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,37 @@
|
|
|
1
|
+
import { FEATURE_NAMES } from '../../loaders/features/features';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Centralizes the lazy loading of agent feature aggregate and instrument sources.
|
|
5
|
+
*
|
|
6
|
+
* This function uses two defined switch cases to allow us to easily name our chunks and re-use these
|
|
7
|
+
* chunks for different agent types. We do not use template strings or string concatenation here because
|
|
8
|
+
* doing so makes it much more difficult to name the chunks and forces Webpack to "guess" what the chunks
|
|
9
|
+
* should be.
|
|
10
|
+
* @param featureName Name of the feature to import such as ajax or session_trace
|
|
11
|
+
* @param featurePart Name of the feature part to load; should be either instrument or aggregate
|
|
12
|
+
* @returns {Promise<InstrumentBase|AggregateBase|null>}
|
|
13
|
+
*/
|
|
14
|
+
export function lazyLoader(featureName, featurePart) {
|
|
15
|
+
if (featurePart === 'aggregate') {
|
|
16
|
+
switch (featureName) {
|
|
17
|
+
case FEATURE_NAMES.ajax:
|
|
18
|
+
return import( /* webpackChunkName: "ajax-aggregate" */'../ajax/aggregate');
|
|
19
|
+
case FEATURE_NAMES.jserrors:
|
|
20
|
+
return import( /* webpackChunkName: "jserrors-aggregate" */'../jserrors/aggregate');
|
|
21
|
+
case FEATURE_NAMES.metrics:
|
|
22
|
+
return import( /* webpackChunkName: "metrics-aggregate" */'../metrics/aggregate');
|
|
23
|
+
case FEATURE_NAMES.pageAction:
|
|
24
|
+
return import( /* webpackChunkName: "page_action-aggregate" */'../page_action/aggregate');
|
|
25
|
+
case FEATURE_NAMES.pageViewEvent:
|
|
26
|
+
return import( /* webpackChunkName: "page_view_event-aggregate" */'../page_view_event/aggregate');
|
|
27
|
+
case FEATURE_NAMES.pageViewTiming:
|
|
28
|
+
return import( /* webpackChunkName: "page_view_timing-aggregate" */'../page_view_timing/aggregate');
|
|
29
|
+
case FEATURE_NAMES.sessionTrace:
|
|
30
|
+
return import( /* webpackChunkName: "session_trace-aggregate" */'../session_trace/aggregate');
|
|
31
|
+
case FEATURE_NAMES.spa:
|
|
32
|
+
return import( /* webpackChunkName: "spa-aggregate" */'../spa/aggregate');
|
|
33
|
+
default:
|
|
34
|
+
throw new Error(`Attempted to load unsupported agent feature: ${featureName} ${featurePart}`);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { CustomAgent } from './custom-agent';
|
|
2
|
+
export { BrowserAgent } from './browser-agent';
|
|
3
|
+
export { WorkerAgent } from './worker-agent';
|
|
4
|
+
|
|
5
|
+
/** IN-PROGRESS -- DOES NOT CURRENTLY WORK CORRECTLY */
|
|
6
|
+
// export { MicroAgent } from './micro-agent'
|
|
7
|
+
|
|
8
|
+
export { Ajax } from './features/ajax';
|
|
9
|
+
export { JSErrors } from './features/jserrors';
|
|
10
|
+
export { Metrics } from './features/metrics';
|
|
11
|
+
export { PageAction } from './features/page_action';
|
|
12
|
+
export { PageViewEvent } from './features/page_view_event';
|
|
13
|
+
export { PageViewTiming } from './features/page_view_timing';
|
|
14
|
+
export { SessionTrace } from './features/session_trace';
|
|
15
|
+
export { Spa } from './features/spa';
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// loader files
|
|
2
|
+
import { getEnabledFeatures } from './features/enabled-features';
|
|
3
|
+
import { configure } from './configure/configure';
|
|
4
|
+
import { getFeatureDependencyNames } from './features/featureDependencies';
|
|
5
|
+
import { featurePriority, FEATURE_NAMES } from './features/features';
|
|
6
|
+
// required features
|
|
7
|
+
import { Instrument as PageViewEvent } from '../features/page_view_event/instrument';
|
|
8
|
+
// common files
|
|
9
|
+
import { Aggregator } from '../common/aggregate/aggregator';
|
|
10
|
+
import { gosNREUM, gosNREUMInitializedAgents } from '../common/window/nreum';
|
|
11
|
+
import { generateRandomHexString } from '../common/ids/unique-id';
|
|
12
|
+
import { getConfiguration, getInfo, getLoaderConfig, getRuntime } from '../common/config/config';
|
|
13
|
+
import { warn } from '../common/util/console';
|
|
14
|
+
import { stringify } from '../common/util/stringify';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* A flexible class that may be used to compose an agent from a select subset of feature modules. In applications
|
|
18
|
+
* sensitive to network load, this may result in smaller builds with slightly lower performance impact.
|
|
19
|
+
*/
|
|
20
|
+
export class Agent {
|
|
21
|
+
constructor(options, agentIdentifier = generateRandomHexString(16)) {
|
|
22
|
+
this.agentIdentifier = agentIdentifier;
|
|
23
|
+
this.sharedAggregator = new Aggregator({
|
|
24
|
+
agentIdentifier: this.agentIdentifier
|
|
25
|
+
});
|
|
26
|
+
this.features = {};
|
|
27
|
+
this.desiredFeatures = new Set(options.features || []); // expected to be a list of static Instrument/InstrumentBase classes, see "spa.js" for example
|
|
28
|
+
|
|
29
|
+
// For Now... ALL agents must make the rum call whether the page_view_event feature was enabled or not.
|
|
30
|
+
// NR1 creates an index on the rum call, and if not seen for a few days, will remove the browser app!
|
|
31
|
+
// Future work is being planned to evaluate removing this behavior from the backend, but for now we must ensure this call is made
|
|
32
|
+
this.desiredFeatures.add(PageViewEvent);
|
|
33
|
+
Object.assign(this, configure(this.agentIdentifier, options, options.loaderType || 'agent'));
|
|
34
|
+
this.start();
|
|
35
|
+
}
|
|
36
|
+
get config() {
|
|
37
|
+
return {
|
|
38
|
+
info: getInfo(this.agentIdentifier),
|
|
39
|
+
init: getConfiguration(this.agentIdentifier),
|
|
40
|
+
loader_config: getLoaderConfig(this.agentIdentifier),
|
|
41
|
+
runtime: getRuntime(this.agentIdentifier)
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
start() {
|
|
45
|
+
const NR_FEATURES_REF_NAME = 'features';
|
|
46
|
+
// Attempt to initialize all the requested features (sequentially in prio order & synchronously), with any failure aborting the whole process.
|
|
47
|
+
try {
|
|
48
|
+
const enabledFeatures = getEnabledFeatures(this.agentIdentifier);
|
|
49
|
+
const featuresToStart = Array.from(this.desiredFeatures);
|
|
50
|
+
featuresToStart.sort((a, b) => featurePriority[a.featureName] - featurePriority[b.featureName]);
|
|
51
|
+
featuresToStart.forEach(f => {
|
|
52
|
+
// pageViewEvent must be enabled because RUM calls are not optional. See comment in constructor and PR 428.
|
|
53
|
+
if (enabledFeatures[f.featureName] || f.featureName === FEATURE_NAMES.pageViewEvent) {
|
|
54
|
+
const dependencies = getFeatureDependencyNames(f.featureName);
|
|
55
|
+
const hasAllDeps = dependencies.every(x => enabledFeatures[x]);
|
|
56
|
+
if (!hasAllDeps) warn(`${f.featureName} is enabled but one or more dependent features has been disabled (${stringify(dependencies)}). This may cause unintended consequences or missing data...`);
|
|
57
|
+
this.features[f.featureName] = new f(this.agentIdentifier, this.sharedAggregator);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
gosNREUMInitializedAgents(this.agentIdentifier, this.features, NR_FEATURES_REF_NAME);
|
|
61
|
+
} catch (err) {
|
|
62
|
+
warn('Failed to initialize all enabled instrument classes (agent aborted) -', err);
|
|
63
|
+
for (const featName in this.features) {
|
|
64
|
+
// this.features hold only features that have been instantiated
|
|
65
|
+
this.features[featName].abortHandler?.();
|
|
66
|
+
}
|
|
67
|
+
const newrelic = gosNREUM();
|
|
68
|
+
delete newrelic.initializedAgents[this.agentIdentifier]?.['api']; // prevent further calls to agent-specific APIs (see "configure.js")
|
|
69
|
+
delete newrelic.initializedAgents[this.agentIdentifier]?.[NR_FEATURES_REF_NAME]; // GC mem used internally by features
|
|
70
|
+
delete this.sharedAggregator;
|
|
71
|
+
// Keep the initialized agent object with its configs for troubleshooting purposes.
|
|
72
|
+
newrelic.ee?.abort(); // set flag and clear global backlog
|
|
73
|
+
delete newrelic.ee?.get(this.agentIdentifier); // clear this agent's own backlog too
|
|
74
|
+
return false;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import slice from 'lodash._slice';
|
|
6
|
+
import { FEATURE_NAMES } from '../features/features';
|
|
7
|
+
import { getRuntime, setInfo, getInfo } from '../../common/config/config';
|
|
8
|
+
import { handle } from '../../common/event-emitter/handle';
|
|
9
|
+
import { mapOwn } from '../../common/util/map-own';
|
|
10
|
+
import { ee } from '../../common/event-emitter/contextual-ee';
|
|
11
|
+
import { now } from '../../common/timing/now';
|
|
12
|
+
import { drain, registerDrain } from '../../common/drain/drain';
|
|
13
|
+
import { onWindowLoad } from '../../common/window/load';
|
|
14
|
+
import { isWorkerScope } from '../../common/util/global-scope';
|
|
15
|
+
import { warn } from '../../common/util/console';
|
|
16
|
+
import { SUPPORTABILITY_METRIC_CHANNEL } from '../../features/metrics/constants';
|
|
17
|
+
export function setAPI(agentIdentifier, forceDrain) {
|
|
18
|
+
if (!forceDrain) registerDrain(agentIdentifier, 'api');
|
|
19
|
+
const apiInterface = {};
|
|
20
|
+
var instanceEE = ee.get(agentIdentifier);
|
|
21
|
+
var tracerEE = instanceEE.get('tracer');
|
|
22
|
+
var asyncApiFns = ['setErrorHandler', 'finished', 'addToTrace', 'inlineHit', 'addRelease'];
|
|
23
|
+
var prefix = 'api-';
|
|
24
|
+
var spaPrefix = prefix + 'ixn-';
|
|
25
|
+
|
|
26
|
+
// Setup stub functions that queue calls for later processing.
|
|
27
|
+
mapOwn(asyncApiFns, function (num, fnName) {
|
|
28
|
+
apiInterface[fnName] = apiCall(prefix, fnName, true, 'api');
|
|
29
|
+
});
|
|
30
|
+
apiInterface.addPageAction = apiCall(prefix, 'addPageAction', true, FEATURE_NAMES.pageAction);
|
|
31
|
+
apiInterface.setCurrentRouteName = apiCall(prefix, 'routeName', true, FEATURE_NAMES.spa);
|
|
32
|
+
apiInterface.setPageViewName = function (name, host) {
|
|
33
|
+
if (typeof name !== 'string') return;
|
|
34
|
+
if (name.charAt(0) !== '/') name = '/' + name;
|
|
35
|
+
getRuntime(agentIdentifier).customTransaction = (host || 'http://custom.transaction') + name;
|
|
36
|
+
return apiCall(prefix, 'setPageViewName', true, 'api')();
|
|
37
|
+
};
|
|
38
|
+
apiInterface.setCustomAttribute = function (name, value) {
|
|
39
|
+
const currentInfo = getInfo(agentIdentifier);
|
|
40
|
+
setInfo(agentIdentifier, {
|
|
41
|
+
...currentInfo,
|
|
42
|
+
jsAttributes: {
|
|
43
|
+
...currentInfo.jsAttributes,
|
|
44
|
+
[name]: value
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
return apiCall(prefix, 'setCustomAttribute', true, 'api')();
|
|
48
|
+
};
|
|
49
|
+
apiInterface.interaction = function () {
|
|
50
|
+
return new InteractionHandle().get();
|
|
51
|
+
};
|
|
52
|
+
function InteractionHandle() {}
|
|
53
|
+
var InteractionApiProto = InteractionHandle.prototype = {
|
|
54
|
+
createTracer: function (name, cb) {
|
|
55
|
+
var contextStore = {};
|
|
56
|
+
var ixn = this;
|
|
57
|
+
var hasCb = typeof cb === 'function';
|
|
58
|
+
handle(spaPrefix + 'tracer', [now(), name, contextStore], ixn, FEATURE_NAMES.spa, instanceEE);
|
|
59
|
+
return function () {
|
|
60
|
+
tracerEE.emit((hasCb ? '' : 'no-') + 'fn-start', [now(), ixn, hasCb], contextStore);
|
|
61
|
+
if (hasCb) {
|
|
62
|
+
try {
|
|
63
|
+
return cb.apply(this, arguments);
|
|
64
|
+
} catch (err) {
|
|
65
|
+
tracerEE.emit('fn-err', [arguments, this, typeof err == 'string' ? new Error(err) : err], contextStore);
|
|
66
|
+
// the error came from outside the agent, so don't swallow
|
|
67
|
+
throw err;
|
|
68
|
+
} finally {
|
|
69
|
+
tracerEE.emit('fn-end', [now()], contextStore);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
mapOwn('actionText,setName,setAttribute,save,ignore,onEnd,getContext,end,get'.split(','), function addApi(n, name) {
|
|
76
|
+
InteractionApiProto[name] = apiCall(spaPrefix, name, undefined, FEATURE_NAMES.spa);
|
|
77
|
+
});
|
|
78
|
+
function apiCall(prefix, name, notSpa, bufferGroup) {
|
|
79
|
+
return function () {
|
|
80
|
+
handle(SUPPORTABILITY_METRIC_CHANNEL, ['API/' + name + '/called'], undefined, FEATURE_NAMES.metrics, instanceEE);
|
|
81
|
+
handle(prefix + name, [now()].concat(slice(arguments)), notSpa ? null : this, bufferGroup, instanceEE);
|
|
82
|
+
return notSpa ? void 0 : this;
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
apiInterface.noticeError = function (err, customAttributes) {
|
|
86
|
+
if (typeof err === 'string') err = new Error(err);
|
|
87
|
+
handle(SUPPORTABILITY_METRIC_CHANNEL, ['API/noticeError/called'], undefined, FEATURE_NAMES.metrics, instanceEE);
|
|
88
|
+
handle('err', [err, now(), false, customAttributes], undefined, FEATURE_NAMES.jserrors, instanceEE);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// theres no window.load event on non-browser scopes, lazy load immediately
|
|
92
|
+
if (isWorkerScope) lazyLoad();
|
|
93
|
+
// try to stay out of the way of the window.load event, lazy load once that has finished.
|
|
94
|
+
else onWindowLoad(() => lazyLoad(), true);
|
|
95
|
+
function lazyLoad() {
|
|
96
|
+
import( /* webpackChunkName: "async-api" */'./apiAsync').then(({
|
|
97
|
+
setAPI
|
|
98
|
+
}) => {
|
|
99
|
+
setAPI(agentIdentifier);
|
|
100
|
+
drain(agentIdentifier, 'api');
|
|
101
|
+
}).catch(() => warn('Downloading runtime APIs failed...'));
|
|
102
|
+
}
|
|
103
|
+
return apiInterface;
|
|
104
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { FEATURE_NAMES } from '../features/features';
|
|
2
|
+
import { getConfigurationValue, getInfo, getRuntime } from '../../common/config/config';
|
|
3
|
+
import { ee } from '../../common/event-emitter/contextual-ee';
|
|
4
|
+
import { handle } from '../../common/event-emitter/handle';
|
|
5
|
+
import { registerHandler } from '../../common/event-emitter/register-handler';
|
|
6
|
+
import { mapOwn } from '../../common/util/map-own';
|
|
7
|
+
import { single } from '../../common/util/single';
|
|
8
|
+
import { submitData } from '../../common/util/submit-data';
|
|
9
|
+
import { isBrowserScope } from '../../common/util/global-scope';
|
|
10
|
+
import { CUSTOM_METRIC_CHANNEL } from '../../features/metrics/constants';
|
|
11
|
+
export function setAPI(agentIdentifier) {
|
|
12
|
+
var instanceEE = ee.get(agentIdentifier);
|
|
13
|
+
var cycle = 0;
|
|
14
|
+
var scheme = getConfigurationValue(agentIdentifier, 'ssl') === false ? 'http' : 'https';
|
|
15
|
+
var api = {
|
|
16
|
+
finished: single(finished),
|
|
17
|
+
setErrorHandler: setErrorHandler,
|
|
18
|
+
addToTrace: addToTrace,
|
|
19
|
+
inlineHit: inlineHit,
|
|
20
|
+
addRelease: addRelease
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
// Hook all of the api functions up to the queues/stubs created in loader/api.js
|
|
24
|
+
mapOwn(api, function (fnName, fn) {
|
|
25
|
+
registerHandler('api-' + fnName, fn, 'api', instanceEE);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
// All API functions get passed the time they were called as their
|
|
29
|
+
// first parameter. These functions can be called asynchronously.
|
|
30
|
+
|
|
31
|
+
function finished(t, providedTime) {
|
|
32
|
+
var time = providedTime ? providedTime - getRuntime(agentIdentifier).offset : t;
|
|
33
|
+
handle(CUSTOM_METRIC_CHANNEL, ['finished', {
|
|
34
|
+
time
|
|
35
|
+
}], undefined, FEATURE_NAMES.metrics, instanceEE);
|
|
36
|
+
addToTrace(t, {
|
|
37
|
+
name: 'finished',
|
|
38
|
+
start: time + getRuntime(agentIdentifier).offset,
|
|
39
|
+
origin: 'nr'
|
|
40
|
+
});
|
|
41
|
+
handle('api-addPageAction', [time, 'finished'], undefined, FEATURE_NAMES.pageAction, instanceEE);
|
|
42
|
+
}
|
|
43
|
+
function addToTrace(t, evt) {
|
|
44
|
+
if (!(evt && typeof evt === 'object' && evt.name && evt.start)) return;
|
|
45
|
+
var report = {
|
|
46
|
+
n: evt.name,
|
|
47
|
+
s: evt.start - getRuntime(agentIdentifier).offset,
|
|
48
|
+
e: (evt.end || evt.start) - getRuntime(agentIdentifier).offset,
|
|
49
|
+
o: evt.origin || '',
|
|
50
|
+
t: 'api'
|
|
51
|
+
};
|
|
52
|
+
handle('bstApi', [report], undefined, FEATURE_NAMES.sessionTrace, instanceEE);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// NREUM.inlineHit(request_name, queue_time, app_time, total_be_time, dom_time, fe_time)
|
|
56
|
+
//
|
|
57
|
+
// request_name - the 'web page' name or service name
|
|
58
|
+
// queue_time - the amount of time spent in the app tier queue
|
|
59
|
+
// app_time - the amount of time spent in the application code
|
|
60
|
+
// total_be_time - the total roundtrip time of the remote service call
|
|
61
|
+
// dom_time - the time spent processing the result of the service call (or user defined)
|
|
62
|
+
// fe_time - the time spent rendering the result of the service call (or user defined)
|
|
63
|
+
function inlineHit(t, request_name, queue_time, app_time, total_be_time, dom_time, fe_time) {
|
|
64
|
+
if (!isBrowserScope) return;
|
|
65
|
+
request_name = window.encodeURIComponent(request_name);
|
|
66
|
+
cycle += 1;
|
|
67
|
+
const agentInfo = getInfo(agentIdentifier);
|
|
68
|
+
if (!agentInfo.beacon) return;
|
|
69
|
+
var url = scheme + '://' + agentInfo.beacon + '/1/' + agentInfo.licenseKey;
|
|
70
|
+
url += '?a=' + agentInfo.applicationID + '&';
|
|
71
|
+
url += 't=' + request_name + '&';
|
|
72
|
+
url += 'qt=' + ~~queue_time + '&';
|
|
73
|
+
url += 'ap=' + ~~app_time + '&';
|
|
74
|
+
url += 'be=' + ~~total_be_time + '&';
|
|
75
|
+
url += 'dc=' + ~~dom_time + '&';
|
|
76
|
+
url += 'fe=' + ~~fe_time + '&';
|
|
77
|
+
url += 'c=' + cycle;
|
|
78
|
+
submitData.img(url);
|
|
79
|
+
}
|
|
80
|
+
function setErrorHandler(t, handler) {
|
|
81
|
+
getRuntime(agentIdentifier).onerror = handler;
|
|
82
|
+
}
|
|
83
|
+
var releaseCount = 0;
|
|
84
|
+
function addRelease(t, name, id) {
|
|
85
|
+
if (++releaseCount > 10) return;
|
|
86
|
+
getRuntime(agentIdentifier).releaseIds[name.slice(-200)] = ('' + id).slice(-200);
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Agent } from './agent';
|
|
2
|
+
import { Instrument as InstrumentPageViewEvent } from '../features/page_view_event/instrument';
|
|
3
|
+
import { Instrument as InstrumentPageViewTiming } from '../features/page_view_timing/instrument';
|
|
4
|
+
import { Instrument as InstrumentMetrics } from '../features/metrics/instrument';
|
|
5
|
+
import { Instrument as InstrumentErrors } from '../features/jserrors/instrument';
|
|
6
|
+
import { Instrument as InstrumentXhr } from '../features/ajax/instrument';
|
|
7
|
+
import { Instrument as InstrumentSessionTrace } from '../features/session_trace/instrument';
|
|
8
|
+
import { Instrument as InstrumentSpa } from '../features/spa/instrument';
|
|
9
|
+
import { Instrument as InstrumentPageAction } from '../features/page_action/instrument';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* An agent class with all feature modules available. Features may be disabled and enabled via runtime configuration.
|
|
13
|
+
* The BrowserAgent class is the most convenient and reliable option for most use cases.
|
|
14
|
+
*/
|
|
15
|
+
export class BrowserAgent extends Agent {
|
|
16
|
+
constructor(args) {
|
|
17
|
+
super({
|
|
18
|
+
...args,
|
|
19
|
+
features: [InstrumentXhr, InstrumentPageViewEvent, InstrumentPageViewTiming, InstrumentSessionTrace, InstrumentMetrics, InstrumentPageAction, InstrumentErrors, InstrumentSpa],
|
|
20
|
+
loaderType: 'browser-agent'
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { setAPI } from '../api/api';
|
|
2
|
+
import { addToNREUM, gosCDN, gosNREUMInitializedAgents } from '../../common/window/nreum';
|
|
3
|
+
import { setConfiguration, setInfo, setLoaderConfig, setRuntime } from '../../common/config/config';
|
|
4
|
+
import { activateFeatures, activatedFeatures } from '../../common/util/feature-flags';
|
|
5
|
+
import { isWorkerScope } from '../../common/util/global-scope';
|
|
6
|
+
import { setTopLevelCallers } from '../../common/window/top-level-callers';
|
|
7
|
+
export function configure(agentIdentifier, opts = {}, loaderType, forceDrain) {
|
|
8
|
+
let {
|
|
9
|
+
init,
|
|
10
|
+
info,
|
|
11
|
+
loader_config,
|
|
12
|
+
runtime = {
|
|
13
|
+
loaderType
|
|
14
|
+
},
|
|
15
|
+
exposed = true
|
|
16
|
+
} = opts;
|
|
17
|
+
const nr = gosCDN();
|
|
18
|
+
if (!info) {
|
|
19
|
+
init = nr.init;
|
|
20
|
+
info = nr.info;
|
|
21
|
+
loader_config = nr.loader_config;
|
|
22
|
+
}
|
|
23
|
+
if (isWorkerScope) {
|
|
24
|
+
// add a default attr to all worker payloads
|
|
25
|
+
info.jsAttributes = {
|
|
26
|
+
...info.jsAttributes,
|
|
27
|
+
isWorker: true
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
setInfo(agentIdentifier, info);
|
|
31
|
+
setConfiguration(agentIdentifier, init || {});
|
|
32
|
+
setLoaderConfig(agentIdentifier, loader_config || {});
|
|
33
|
+
setRuntime(agentIdentifier, runtime);
|
|
34
|
+
setTopLevelCallers();
|
|
35
|
+
const api = setAPI(agentIdentifier, forceDrain);
|
|
36
|
+
gosNREUMInitializedAgents(agentIdentifier, api, 'api');
|
|
37
|
+
gosNREUMInitializedAgents(agentIdentifier, exposed, 'exposed');
|
|
38
|
+
addToNREUM('activatedFeatures', activatedFeatures);
|
|
39
|
+
addToNREUM('setToken', flags => activateFeatures(flags, agentIdentifier));
|
|
40
|
+
return api;
|
|
41
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FEATURE_NAMES } from './features';
|
|
2
|
+
import { getConfigurationValue, getRuntime } from '../../common/config/config';
|
|
3
|
+
const featureNames = Object.values(FEATURE_NAMES);
|
|
4
|
+
function isEnabled(name, agentIdentifier) {
|
|
5
|
+
return getConfigurationValue(agentIdentifier, `${name}.enabled`) !== false;
|
|
6
|
+
}
|
|
7
|
+
export function getEnabledFeatures(agentIdentifier) {
|
|
8
|
+
const enabledFeatures = {};
|
|
9
|
+
featureNames.forEach(featureName => {
|
|
10
|
+
enabledFeatures[featureName] = isEnabled(featureName, agentIdentifier);
|
|
11
|
+
});
|
|
12
|
+
return enabledFeatures;
|
|
13
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { FEATURE_NAMES } from './features';
|
|
2
|
+
export function getFeatureDependencyNames(feature) {
|
|
3
|
+
switch (feature) {
|
|
4
|
+
case FEATURE_NAMES.ajax:
|
|
5
|
+
return [FEATURE_NAMES.jserrors];
|
|
6
|
+
case FEATURE_NAMES.sessionTrace:
|
|
7
|
+
return [FEATURE_NAMES.ajax, FEATURE_NAMES.pageViewEvent];
|
|
8
|
+
case FEATURE_NAMES.pageViewTiming:
|
|
9
|
+
return [FEATURE_NAMES.pageViewEvent];
|
|
10
|
+
// this could change if we disconnect window load timings
|
|
11
|
+
default:
|
|
12
|
+
return [];
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
export function getFrozenAttributes(feature) {
|
|
16
|
+
switch (feature) {
|
|
17
|
+
// right now, jserrors is the only feature that can have "on" or "off" page-level auto-instrumentation...
|
|
18
|
+
// page_action is always "off" (no instr)
|
|
19
|
+
// as new API/manual implementation methods are added, this list can likely be pruned
|
|
20
|
+
case FEATURE_NAMES.jserrors:
|
|
21
|
+
return [];
|
|
22
|
+
default:
|
|
23
|
+
return ['auto'];
|
|
24
|
+
}
|
|
25
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export const FEATURE_NAMES = {
|
|
2
|
+
ajax: 'ajax',
|
|
3
|
+
jserrors: 'jserrors',
|
|
4
|
+
metrics: 'metrics',
|
|
5
|
+
pageAction: 'page_action',
|
|
6
|
+
pageViewEvent: 'page_view_event',
|
|
7
|
+
pageViewTiming: 'page_view_timing',
|
|
8
|
+
sessionTrace: 'session_trace',
|
|
9
|
+
spa: 'spa'
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* The order in which features will be instrumented. This is the traditional order. It's unclear if the order of
|
|
14
|
+
* wrapping events has any ramifications, so we are enforcing this order intentionally for now.
|
|
15
|
+
*/
|
|
16
|
+
export const featurePriority = {
|
|
17
|
+
[FEATURE_NAMES.pageViewEvent]: 1,
|
|
18
|
+
[FEATURE_NAMES.pageViewTiming]: 2,
|
|
19
|
+
[FEATURE_NAMES.metrics]: 3,
|
|
20
|
+
[FEATURE_NAMES.jserrors]: 4,
|
|
21
|
+
[FEATURE_NAMES.ajax]: 5,
|
|
22
|
+
[FEATURE_NAMES.sessionTrace]: 6,
|
|
23
|
+
[FEATURE_NAMES.pageAction]: 7,
|
|
24
|
+
[FEATURE_NAMES.spa]: 8
|
|
25
|
+
};
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
// loader files
|
|
2
|
+
import { getEnabledFeatures } from './features/enabled-features';
|
|
3
|
+
import { configure } from './configure/configure';
|
|
4
|
+
// core files
|
|
5
|
+
import { Aggregator } from '../common/aggregate/aggregator';
|
|
6
|
+
import { gosNREUMInitializedAgents } from '../common/window/nreum';
|
|
7
|
+
import { generateRandomHexString } from '../common/ids/unique-id';
|
|
8
|
+
import { getConfiguration, getInfo, getLoaderConfig, getRuntime } from '../common/config/config';
|
|
9
|
+
import { FEATURE_NAMES } from './features/features';
|
|
10
|
+
import { warn } from '../common/util/console';
|
|
11
|
+
const nonAutoFeatures = [FEATURE_NAMES.jserrors, FEATURE_NAMES.pageAction];
|
|
12
|
+
const autoFeatures = [FEATURE_NAMES.metrics];
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* A minimal agent class designed to be loaded multiple times on the same page, each instance narrowly scoped to the
|
|
16
|
+
* concerns of a particular component, as with the micro-frontend architectural pattern. This class does not
|
|
17
|
+
* automatically instrument. Instead, each MicroAgent instance may be configured to lazy-load specific
|
|
18
|
+
* instrumentations at runtime, and to report desired data, events, and errors programatically.
|
|
19
|
+
*/
|
|
20
|
+
export class MicroAgent {
|
|
21
|
+
/**
|
|
22
|
+
* @param {Object} options - Specifies features and runtime configuration,
|
|
23
|
+
* @param {string=} agentIdentifier - The optional unique ID of the agent.
|
|
24
|
+
*/
|
|
25
|
+
constructor(options, agentIdentifier = generateRandomHexString(16)) {
|
|
26
|
+
this.agentIdentifier = agentIdentifier;
|
|
27
|
+
this.sharedAggregator = new Aggregator({
|
|
28
|
+
agentIdentifier: this.agentIdentifier
|
|
29
|
+
});
|
|
30
|
+
this.features = {};
|
|
31
|
+
Object.assign(this, configure(this.agentIdentifier, {
|
|
32
|
+
...options,
|
|
33
|
+
runtime: {
|
|
34
|
+
isolatedBacklog: true
|
|
35
|
+
}
|
|
36
|
+
}, options.loaderType || 'micro-agent'));
|
|
37
|
+
this.start();
|
|
38
|
+
}
|
|
39
|
+
get config() {
|
|
40
|
+
return {
|
|
41
|
+
info: getInfo(this.agentIdentifier),
|
|
42
|
+
init: getConfiguration(this.agentIdentifier),
|
|
43
|
+
loader_config: getLoaderConfig(this.agentIdentifier),
|
|
44
|
+
runtime: getRuntime(this.agentIdentifier)
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
start() {
|
|
48
|
+
try {
|
|
49
|
+
const enabledFeatures = getEnabledFeatures(this.agentIdentifier);
|
|
50
|
+
autoFeatures.forEach(f => {
|
|
51
|
+
if (enabledFeatures[f]) {
|
|
52
|
+
// TODO - THIS does not work, the instrument switch in lazy loader increases the size of the worker build. Needs to be revisited
|
|
53
|
+
import( /* webpackChunkName: "lazy-loader" */'../features/utils/lazy-loader').then(({
|
|
54
|
+
lazyLoader
|
|
55
|
+
}) => {
|
|
56
|
+
return lazyLoader(f, 'instrument');
|
|
57
|
+
}).then(({
|
|
58
|
+
Instrument
|
|
59
|
+
}) => {
|
|
60
|
+
this.features[f] = new Instrument(this.agentIdentifier, this.sharedAggregator);
|
|
61
|
+
}).catch(err => warn('Something prevented the agent from being downloaded.'));
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
nonAutoFeatures.forEach(f => {
|
|
65
|
+
if (enabledFeatures[f]) {
|
|
66
|
+
// TODO - THIS does not work, the instrument switch in lazy loader increases the size of the worker build. Needs to be revisited
|
|
67
|
+
// Parts of the lazy-loader were removed because webpack was transpiling them into the worker build, errantly inflating the build size.
|
|
68
|
+
import( /* webpackChunkName: "lazy-loader" */'../features/utils/lazy-loader').then(({
|
|
69
|
+
lazyLoader
|
|
70
|
+
}) => {
|
|
71
|
+
return lazyLoader(f, 'aggregate');
|
|
72
|
+
}).then(({
|
|
73
|
+
Aggregate
|
|
74
|
+
}) => {
|
|
75
|
+
this.features[f] = new Aggregate(this.agentIdentifier, this.sharedAggregator);
|
|
76
|
+
}).catch(err => warn('Something prevented the agent from being downloaded.'));
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
gosNREUMInitializedAgents(this.agentIdentifier, this.features, 'features');
|
|
80
|
+
return this;
|
|
81
|
+
} catch (err) {
|
|
82
|
+
warn('Failed to initialize instrument classes.', err);
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Agent } from './agent';
|
|
2
|
+
import { Instrument as InstrumentMetrics } from '../features/metrics/instrument';
|
|
3
|
+
import { Instrument as InstrumentErrors } from '../features/jserrors/instrument';
|
|
4
|
+
import { Instrument as InstrumentXhr } from '../features/ajax/instrument';
|
|
5
|
+
import { Instrument as InstrumentPageAction } from '../features/page_action/instrument';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* A streamlined agent class designed for the service worker context, limited to features relevant in that scope.
|
|
9
|
+
*/
|
|
10
|
+
export class WorkerAgent extends Agent {
|
|
11
|
+
constructor(args) {
|
|
12
|
+
super({
|
|
13
|
+
...args,
|
|
14
|
+
features: [InstrumentMetrics, InstrumentErrors, InstrumentXhr, InstrumentPageAction],
|
|
15
|
+
loaderType: 'worker-agent'
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|