@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
package/README.md
CHANGED
|
@@ -1,261 +1,138 @@
|
|
|
1
|
-
[](https://opensource.newrelic.com/oss-category/#community-plus)
|
|
2
2
|
|
|
3
3
|
# New Relic Browser Agent
|
|
4
4
|
|
|
5
|
-
The New Relic
|
|
5
|
+
The New Relic browser agent instruments your web application or site and provides observability into performance, errors, and other behaviors.
|
|
6
6
|
|
|
7
|
-
|
|
7
|
+
- The instructions on this page pertain to installing the browser agent as an NPM package (currently in pre-release).
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
- The browser agent is also generally available as a copy-paste JavaScript snippet and via auto-injection by backend apps. See *[Install the browser agent](https://docs.newrelic.com/docs/browser/browser-monitoring/installation/install-browser-monitoring-agent/)* for info on these alternatives.
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
- For questions and feedback on this pre-release package, please visit the [Explorer's Hub](https://forum.newrelic.com/s/), New Relic's community support forum.
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
npm install @newrelic/browser-agent
|
|
15
|
-
```
|
|
16
|
-
|
|
17
|
-
or [yarn](https://yarnpkg.com/)
|
|
13
|
+
- Looking to contribute to the browser agent code base? See [DEVELOPING.md](DEVELOPING.md) for instructions on building and testing the browser agent library, and [CONTRIBUTING.md](CONTRIBUTING.md) for general guidance.
|
|
18
14
|
|
|
19
|
-
|
|
20
|
-
yarn add @newrelic/browser-agent
|
|
21
|
-
```
|
|
15
|
+
## Adding the agent package to your project
|
|
22
16
|
|
|
23
|
-
|
|
17
|
+
To make the agent available to your application, install via [NPM](https://docs.npmjs.com/cli/v8/commands/npm-install) or [Yarn](https://classic.yarnpkg.com/lang/en/docs/cli/install/).
|
|
24
18
|
|
|
25
|
-
|
|
19
|
+
```shell
|
|
20
|
+
$ npm install @newrelic/browser-agent --save
|
|
21
|
+
```
|
|
26
22
|
|
|
27
|
-
|
|
23
|
+
```shell
|
|
24
|
+
$ yarn add @newrelic/browser-agent
|
|
25
|
+
```
|
|
28
26
|
|
|
29
|
-
|
|
27
|
+
## Creating an app in New Relic One
|
|
30
28
|
|
|
31
|
-
|
|
32
|
-
<script src="https://unpkg.com/@newrelic/browser-agent/dist/bundled/es6/index.js"></script>
|
|
33
|
-
```
|
|
29
|
+
Before instrumenting your app using the NPM package, a Browser App should be configured in New Relic One. This may be done with or without a corresponding APM agent. Once the app has been created, the Copy/Paste JavaScript code on the app's *Application settings* page will contain the configuration values needed to define options when instantiating the agent via the NPM package.
|
|
34
30
|
|
|
35
|
-
|
|
31
|
+
1. If a browser app does not already exist, create one:
|
|
32
|
+
- From the *New Relic One* navigation panel, click *Add Data*.
|
|
33
|
+
- Select the *Browser monitoring* data source.
|
|
34
|
+
- Choose the *APM* or *Copy/Paste* method.
|
|
35
|
+
- Select or name your app and click *Enable*.
|
|
36
|
+
2. From the navigation panel, select *Browser* to view brower apps.
|
|
37
|
+
3. Select the desired app and navigate to the *Application settings* page.
|
|
38
|
+
4. From the *Copy/Paste JavaScript* box, copy the configuration values assigned to the `NREUM` object (`init`, `info`, and `loader_config`). You will use these configuration values when instantiating the agent using the NPM package.
|
|
36
39
|
|
|
37
|
-
|
|
38
|
-
<script src="https://unpkg.com/@newrelic/browser-agent/dist/bundled/es5/index.js"></script>
|
|
39
|
-
```
|
|
40
|
+
## Instantiating the agent
|
|
40
41
|
|
|
41
|
-
|
|
42
|
+
For best results, import and instantiate the `BrowserAgent` class as close to the top of the `head` element of your app's HTML output as possible. The specific location and method will vary based on your application's architecture or framework.
|
|
42
43
|
|
|
43
|
-
|
|
44
|
+
Populate the `options` parameter using configuration values found in the the *Copy/Paste JavaScript* box in your browser app's *Application settings* page in New Relic One.
|
|
44
45
|
|
|
45
46
|
```javascript
|
|
46
|
-
|
|
47
|
-
// initialize the agent as close to
|
|
48
|
-
// the top level of the application as possible
|
|
49
|
-
import NR from '@newrelic/browser-agent'
|
|
47
|
+
import { BrowserAgent } from '@newrelic/browser-agent/loaders/browser-agent'
|
|
50
48
|
|
|
49
|
+
// Populate using values in copy-paste JavaScript snippet.
|
|
51
50
|
const options = {
|
|
52
|
-
|
|
51
|
+
init: { ... }, // NREUM.init
|
|
52
|
+
info: { ... }, // NREUM.info
|
|
53
|
+
loader_config: { ...} // NREUM.loader_config
|
|
53
54
|
}
|
|
54
|
-
const nr = new NR()
|
|
55
55
|
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
})
|
|
56
|
+
// The agent loader code executes immediately on instantiation.
|
|
57
|
+
new BrowserAgent(options)
|
|
59
58
|
```
|
|
60
59
|
|
|
61
|
-
|
|
62
|
-
```javascript
|
|
63
|
-
// << SomeComponent.js >>
|
|
64
|
-
// notice handled errors
|
|
65
|
-
try {
|
|
66
|
-
...
|
|
67
|
-
} catch (err){
|
|
68
|
-
nr.noticeError(err)
|
|
69
|
-
}
|
|
60
|
+
## Turning off features at runtime
|
|
70
61
|
|
|
71
|
-
|
|
72
|
-
```
|
|
62
|
+
Features may be turned off at runtime, which may have a meaningful peformance impact in some cases.
|
|
73
63
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
```html
|
|
77
|
-
<head>
|
|
78
|
-
<!-- Download and initialize as soon as possible to avoid missing early events -->
|
|
79
|
-
<script src="https://unpkg.com/@newrelic/browser-agent/bundled"></script>
|
|
80
|
-
<script>
|
|
81
|
-
const { BrowserAgent } = NRBA;
|
|
82
|
-
const options = {
|
|
83
|
-
// See 'Configuring your application'
|
|
84
|
-
}
|
|
85
|
-
const agent = new BrowserAgent()
|
|
86
|
-
agent.start(options).then(() => {
|
|
87
|
-
console.log("Browser Agent Initialized!")
|
|
88
|
-
})
|
|
89
|
-
</script>
|
|
90
|
-
</head>
|
|
91
|
-
```
|
|
64
|
+
In the example below, the `page_view_timing` and `session_trace` features are disabled.
|
|
92
65
|
|
|
93
|
-
### Notice Errors after Setup
|
|
94
66
|
```javascript
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
67
|
+
const options = {
|
|
68
|
+
info: { ... },
|
|
69
|
+
loader_config: { ... },
|
|
70
|
+
init: {
|
|
71
|
+
page_view_timing: { enabled: false },
|
|
72
|
+
session_trace: { enabled: false },
|
|
99
73
|
...
|
|
100
|
-
}
|
|
101
|
-
nr.noticeError(err)
|
|
74
|
+
}
|
|
102
75
|
}
|
|
103
|
-
|
|
104
|
-
// thrown errors *anywhere* on the page will be captured if `auto` is enabled
|
|
105
76
|
```
|
|
106
77
|
|
|
107
|
-
|
|
78
|
+
The following features may be disabled by adding `init` entries as shown above. Note that the `page_view_event` feature may not be disabled.
|
|
108
79
|
|
|
109
|
-
|
|
80
|
+
- `ajax`
|
|
81
|
+
- `jserrors`
|
|
82
|
+
- `metrics`
|
|
83
|
+
- `page_action`
|
|
84
|
+
- `page_view_timing`
|
|
85
|
+
- `session_trace`
|
|
86
|
+
- `spa`
|
|
110
87
|
|
|
111
|
-
|
|
112
|
-
// ---- App.js ----
|
|
113
|
-
// Initialize as close to top of page as possible
|
|
114
|
-
import { BrowserAgent } from '@newrelic/browser-agent'
|
|
115
|
-
const options1 = {
|
|
116
|
-
// see 'Configuring your application'
|
|
117
|
-
licenseKey: 'abc',
|
|
118
|
-
applicationID: '123',
|
|
119
|
-
beacon: 'bam.nr-data.net'
|
|
120
|
-
}
|
|
121
|
-
const agent1 = new BrowserAgent()
|
|
122
|
-
agent1.features.errors.enabled = true // this is enabled by default, but just for visibility
|
|
123
|
-
agent1.start(options1).then(() => {
|
|
124
|
-
console.log("Browser Agent (options1) Initialized!")
|
|
125
|
-
})
|
|
88
|
+
See the [New Relic documentation site](https://docs.newrelic.com/docs/browser/browser-monitoring/getting-started/introduction-browser-monitoring/) for information on the above features.
|
|
126
89
|
|
|
127
|
-
const options2 = {
|
|
128
|
-
// see 'Configuring your application'
|
|
129
|
-
licenseKey: 'xyz',
|
|
130
|
-
applicationID: '987',
|
|
131
|
-
beacon: 'bam.nr-data.net'
|
|
132
|
-
}
|
|
133
|
-
const agent2 = new BrowserAgent()
|
|
134
|
-
agent2.features.errors.auto = false // do not capture global errors on this instance
|
|
135
|
-
agent2.start(options2).then(() => {
|
|
136
|
-
console.log("Browser Agent (options2) Initialized!")
|
|
137
|
-
})
|
|
138
90
|
|
|
139
|
-
|
|
140
|
-
// thrown errors *anywhere* on the page will be captured if `auto` is enabled in your instance
|
|
141
|
-
// agent2 has disabled `auto`, and will not capture globally thrown errors
|
|
142
|
-
|
|
143
|
-
// ---- NavBarComponent.js ----
|
|
144
|
-
class MyComponent() {
|
|
145
|
-
try {
|
|
146
|
-
...
|
|
147
|
-
} catch(err) {
|
|
148
|
-
agent1.noticeError(err)
|
|
149
|
-
// agent1 instance
|
|
150
|
-
// reports the error to applicationID '123', licenseKey 'abc'
|
|
151
|
-
}
|
|
152
|
-
}
|
|
91
|
+
## Composing a custom agent with selected feature modules
|
|
153
92
|
|
|
154
|
-
|
|
155
|
-
class MyComponent() {
|
|
156
|
-
try {
|
|
157
|
-
...
|
|
158
|
-
} catch(err) {
|
|
159
|
-
agent2.noticeError(err)
|
|
160
|
-
// agent2 instance
|
|
161
|
-
// reports to applicationID '987', licenseKey 'xyz'
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
```
|
|
93
|
+
The examples above use the `BrowserAgent` class, which is the best option for most use cases. The class makes all browser agent features available but provides the ability to turn off individual features selectively.
|
|
165
94
|
|
|
166
|
-
|
|
95
|
+
Using the base `Agent` class, it is also possible to compose a custom agent by passing an array called `features` in the `options` object, containing only the desired feature modules. Depending on which features are included, this may yield a smaller loader script and improved performance.
|
|
167
96
|
|
|
168
|
-
The
|
|
97
|
+
The example below includes three feature modules: `Metrics`, `PageViewEvent`, and `PageViewTiming`.
|
|
98
|
+
|
|
99
|
+
```javascript
|
|
100
|
+
import { Agent } from '@newrelic/browser-agent/loaders/agent'
|
|
101
|
+
import { Metrics } from '@newrelic/browser-agent/features/metrics'
|
|
102
|
+
import { PageViewEvent } from '@newrelic/browser-agent/features/page_view_event'
|
|
103
|
+
import { PageViewTiming } from '@newrelic/browser-agent/features/page_view_timing'
|
|
169
104
|
|
|
170
|
-
```js
|
|
171
105
|
const options = {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
// ... other configurations
|
|
106
|
+
info: { ... },
|
|
107
|
+
loader_config: { ... },
|
|
108
|
+
init: { ... }
|
|
176
109
|
}
|
|
177
|
-
nr.start(options)
|
|
178
|
-
```
|
|
179
110
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|Feature|Subfeature|Default|Description|
|
|
189
|
-
|-|-|-|-|
|
|
190
|
-
|errors |enabled |true|Enable's `noticeError` method|
|
|
191
|
-
|errors |auto |false|Reports all global errors |
|
|
192
|
-
|
|
193
|
-
> Features must be set before calling the .start() method.
|
|
194
|
-
|
|
195
|
-
### JavaScript Errors
|
|
196
|
-
|
|
197
|
-
This NPM package can currently capture JavaScript Error reporting in two ways. These errors will be reported to the appId & licenseKey specified in your [configuration](#configuring-your-application).
|
|
198
|
-
|
|
199
|
-
```js
|
|
200
|
-
import { BrowserAgent } from '@newrelic/browser-agent'
|
|
201
|
-
const browserAgent = new BrowserAgent()
|
|
202
|
-
|
|
203
|
-
// enable noticeError() API scoped to applicationID (enabled by default)
|
|
204
|
-
browserAgent.features.errors.enabled = true
|
|
205
|
-
|
|
206
|
-
// report global errors to applicationID (enabled by default)
|
|
207
|
-
browserAgent.features.errors.auto = true
|
|
208
|
-
|
|
209
|
-
// configure features before starting the agent
|
|
210
|
-
browserAgent.start(options)
|
|
211
|
-
```
|
|
212
|
-
|
|
213
|
-
### Capture JavaScript errors via API
|
|
214
|
-
|
|
215
|
-
```javascript
|
|
216
|
-
// if browserAgent.features.errors.enabled === true (enabled by default)
|
|
217
|
-
browserAgent.noticeError(new Error())
|
|
111
|
+
new Agent({
|
|
112
|
+
...options,
|
|
113
|
+
features: [
|
|
114
|
+
Metrics,
|
|
115
|
+
PageViewEvent,
|
|
116
|
+
PageViewTiming
|
|
117
|
+
]
|
|
118
|
+
})
|
|
218
119
|
```
|
|
219
120
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
### Automatically capture global JavaScript errors
|
|
121
|
+
The following feature modules are available for inclusion in the `features` array:
|
|
223
122
|
|
|
224
123
|
```javascript
|
|
225
|
-
|
|
124
|
+
import { Ajax } from '@newrelic/browser-agent/features/ajax';
|
|
125
|
+
import { JSErrors } from '@newrelic/browser-agent/features/jserrors';
|
|
126
|
+
import { Metrics } from '@newrelic/browser-agent/features/metrics';
|
|
127
|
+
import { PageAction } from '@newrelic/browser-agent/features/page_action';
|
|
128
|
+
import { PageViewEvent } from '@newrelic/browser-agent/features/page_view_event';
|
|
129
|
+
import { PageViewTiming } from '@newrelic/browser-agent/features/page_view_timing';
|
|
130
|
+
import { SessionTrace } from '@newrelic/browser-agent/features/session_trace';
|
|
131
|
+
import { Spa } from '@newrelic/browser-agent/features/spa';
|
|
226
132
|
```
|
|
227
133
|
|
|
228
|
-
Set `browserAgent.errors.auto` to `true` to report all errors on the page.
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
## Differences
|
|
232
|
-
|
|
233
|
-
The Browser Agent delivered through NPM will eventually offer parity to its copy/paste and APM counterparts, but during this initial development phase, **it should not yet be treated as equivalent**. Please see the following table describing the capabilities of each. The availability of these features will change over time.
|
|
234
|
-
|
|
235
|
-
| Feature | APM Injected | Copy/Paste | NPM |
|
|
236
|
-
| ------- | ------------ | ---------- | --- |
|
|
237
|
-
| JavaScript Errors | Auto, API | Auto, API | `Auto, API` |
|
|
238
|
-
| Page View | Auto | Auto | `None` |
|
|
239
|
-
| Page View Timings | Auto | Auto | `None` |
|
|
240
|
-
| Ajax Tracking | Auto | Auto | `None` |
|
|
241
|
-
| Page Actions | API | API | `None` |
|
|
242
|
-
| Session Traces | Auto | Auto | `None` |
|
|
243
|
-
| Browser Interactions (SPA) | Auto, API | Auto, API | `None` |
|
|
244
|
-
| Multiple Configurable Instances of Browser Agent on One Page | No | No | `Yes` |
|
|
245
|
-
| Configurable Code Splitting | No | No | `Yes` |
|
|
246
|
-
| IDE Code Completion and Typings | No | No | `Yes` |
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
## Contributing
|
|
250
|
-
|
|
251
|
-
We encourage your contributions to improve the Browser agent! Keep in mind that when you submit your pull request, you'll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project.
|
|
252
|
-
|
|
253
|
-
If you have any questions, or to execute our corporate CLA (which is required if your contribution is on behalf of a company), drop us an email at opensource@newrelic.com.
|
|
254
|
-
|
|
255
|
-
For more details on how best to contribute, see [CONTRIBUTING.md](CONTRIBUTING.md)
|
|
256
|
-
|
|
257
134
|
## License
|
|
258
135
|
|
|
259
136
|
The Browser agent is licensed under the [Apache 2.0](http://apache.org/licenses/LICENSE-2.0.txt) License.
|
|
260
137
|
|
|
261
|
-
The Browser agent also uses source code from third-party libraries. Full details on which libraries are used and the terms under which they are licensed can be found in the [third-party notices document](THIRD_PARTY_NOTICES.md).
|
|
138
|
+
The Browser agent also uses source code from third-party libraries. Full details on which libraries are used and the terms under which they are licensed can be found in the [third-party notices document](THIRD_PARTY_NOTICES.md).
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _agent = require("../loaders/agent");
|
|
4
|
+
var _instrument = require("../features/page_view_event/instrument");
|
|
5
|
+
var _instrument2 = require("../features/page_view_timing/instrument");
|
|
6
|
+
var _instrument3 = require("../features/metrics/instrument");
|
|
7
|
+
/**
|
|
8
|
+
* @file Creates a "Lite" agent loader bundle composed of the core Agent and a subset of available feature modules.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
new _agent.Agent({
|
|
12
|
+
features: [_instrument.Instrument, _instrument2.Instrument, _instrument3.Instrument],
|
|
13
|
+
loaderType: 'lite'
|
|
14
|
+
});
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
require("core-js/stable/promise");
|
|
4
|
+
require("core-js/stable/array/includes");
|
|
5
|
+
require("core-js/stable/array/from");
|
|
6
|
+
require("core-js/stable/array/find");
|
|
7
|
+
require("core-js/stable/array/some");
|
|
8
|
+
require("core-js/stable/object/assign");
|
|
9
|
+
require("core-js/stable/object/entries");
|
|
10
|
+
require("core-js/stable/object/values");
|
|
11
|
+
require("core-js/stable/map");
|
|
12
|
+
require("core-js/stable/reflect");
|
|
13
|
+
require("core-js/stable/set");
|
|
14
|
+
require("core-js/stable/weak-set");
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _agent = require("../loaders/agent");
|
|
4
|
+
var _instrument = require("../features/page_view_event/instrument");
|
|
5
|
+
var _instrument2 = require("../features/page_view_timing/instrument");
|
|
6
|
+
var _instrument3 = require("../features/metrics/instrument");
|
|
7
|
+
var _instrument4 = require("../features/jserrors/instrument");
|
|
8
|
+
var _instrument5 = require("../features/ajax/instrument");
|
|
9
|
+
var _instrument6 = require("../features/session_trace/instrument");
|
|
10
|
+
var _instrument7 = require("../features/page_action/instrument");
|
|
11
|
+
/**
|
|
12
|
+
* @file Creates a "Pro" agent loader bundle composed of the core Agent and all available feature modules except `spa`.
|
|
13
|
+
* This excludes collection of BrowserInteraction and BrowserTiming events.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
new _agent.Agent({
|
|
17
|
+
features: [_instrument.Instrument, _instrument2.Instrument, _instrument6.Instrument, _instrument5.Instrument, _instrument3.Instrument, _instrument7.Instrument, _instrument4.Instrument],
|
|
18
|
+
loaderType: 'pro'
|
|
19
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _agent = require("../loaders/agent");
|
|
4
|
+
var _instrument = require("../features/page_view_event/instrument");
|
|
5
|
+
var _instrument2 = require("../features/page_view_timing/instrument");
|
|
6
|
+
var _instrument3 = require("../features/metrics/instrument");
|
|
7
|
+
var _instrument4 = require("../features/jserrors/instrument");
|
|
8
|
+
var _instrument5 = require("../features/ajax/instrument");
|
|
9
|
+
var _instrument6 = require("../features/session_trace/instrument");
|
|
10
|
+
var _instrument7 = require("../features/spa/instrument");
|
|
11
|
+
var _instrument8 = require("../features/page_action/instrument");
|
|
12
|
+
/**
|
|
13
|
+
* @file Creates a "SPA" agent loader bundle composed of the core agent and all available feature modules.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
new _agent.Agent({
|
|
17
|
+
features: [_instrument5.Instrument, _instrument.Instrument, _instrument2.Instrument, _instrument6.Instrument, _instrument3.Instrument, _instrument8.Instrument, _instrument4.Instrument, _instrument7.Instrument],
|
|
18
|
+
loaderType: 'spa'
|
|
19
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _agent = require("../loaders/agent");
|
|
4
|
+
var _instrument = require("../features/metrics/instrument");
|
|
5
|
+
var _instrument2 = require("../features/jserrors/instrument");
|
|
6
|
+
var _instrument3 = require("../features/ajax/instrument");
|
|
7
|
+
var _instrument4 = require("../features/page_action/instrument");
|
|
8
|
+
/**
|
|
9
|
+
* @file Creates a "Worker" agent loader bundle composed of the core Agent and the subset of feature modules applicable
|
|
10
|
+
* in a service worker context.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
new _agent.Agent({
|
|
14
|
+
features: [_instrument.Instrument, _instrument2.Instrument, _instrument3.Instrument, _instrument4.Instrument],
|
|
15
|
+
loaderType: 'worker'
|
|
16
|
+
});
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Aggregator = void 0;
|
|
7
|
+
var _sharedContext = require("../context/shared-context");
|
|
8
|
+
var _mapOwn = require("../util/map-own");
|
|
9
|
+
/*
|
|
10
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
11
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
class Aggregator extends _sharedContext.SharedContext {
|
|
15
|
+
constructor(parent) {
|
|
16
|
+
super(parent);
|
|
17
|
+
this.aggregatedData = {};
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Items with the same type and name get aggregated together
|
|
21
|
+
// params are example data from the aggregated items
|
|
22
|
+
// metrics are the numeric values to be aggregated
|
|
23
|
+
|
|
24
|
+
store(type, name, params, newMetrics, customParams) {
|
|
25
|
+
var bucket = this.getBucket(type, name, params, customParams);
|
|
26
|
+
bucket.metrics = aggregateMetrics(newMetrics, bucket.metrics);
|
|
27
|
+
return bucket;
|
|
28
|
+
}
|
|
29
|
+
merge(type, name, metrics, params, customParams) {
|
|
30
|
+
var bucket = this.getBucket(type, name, params, customParams);
|
|
31
|
+
if (!bucket.metrics) {
|
|
32
|
+
bucket.metrics = metrics;
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
var oldMetrics = bucket.metrics;
|
|
36
|
+
oldMetrics.count += metrics.count;
|
|
37
|
+
|
|
38
|
+
// iterate through each new metric and merge
|
|
39
|
+
(0, _mapOwn.mapOwn)(metrics, function (key, value) {
|
|
40
|
+
// count is a special case handled above
|
|
41
|
+
if (key === 'count') return;
|
|
42
|
+
var oldMetric = oldMetrics[key];
|
|
43
|
+
var newMetric = metrics[key];
|
|
44
|
+
|
|
45
|
+
// handling the case where newMetric is a single-value first
|
|
46
|
+
if (newMetric && !newMetric.c) {
|
|
47
|
+
oldMetrics[key] = updateMetric(newMetric.t, oldMetric);
|
|
48
|
+
} else {
|
|
49
|
+
// newMetric is a metric object
|
|
50
|
+
oldMetrics[key] = mergeMetric(newMetric, oldMetrics[key]);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
storeMetric(type, name, params, value) {
|
|
55
|
+
var bucket = this.getBucket(type, name, params);
|
|
56
|
+
bucket.stats = updateMetric(value, bucket.stats);
|
|
57
|
+
return bucket;
|
|
58
|
+
}
|
|
59
|
+
getBucket(type, name, params, customParams) {
|
|
60
|
+
if (!this.aggregatedData[type]) this.aggregatedData[type] = {};
|
|
61
|
+
var bucket = this.aggregatedData[type][name];
|
|
62
|
+
if (!bucket) {
|
|
63
|
+
bucket = this.aggregatedData[type][name] = {
|
|
64
|
+
params: params || {}
|
|
65
|
+
};
|
|
66
|
+
if (customParams) {
|
|
67
|
+
bucket.custom = customParams;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
return bucket;
|
|
71
|
+
}
|
|
72
|
+
get(type, name) {
|
|
73
|
+
// if name is passed, get a single bucket
|
|
74
|
+
if (name) return this.aggregatedData[type] && this.aggregatedData[type][name];
|
|
75
|
+
// else, get all buckets of that type
|
|
76
|
+
return this.aggregatedData[type];
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
// Like get, but for many types and it deletes the retrieved content from the aggregatedData
|
|
80
|
+
take(types) {
|
|
81
|
+
var results = {};
|
|
82
|
+
var type = '';
|
|
83
|
+
var hasData = false;
|
|
84
|
+
for (var i = 0; i < types.length; i++) {
|
|
85
|
+
type = types[i];
|
|
86
|
+
results[type] = toArray(this.aggregatedData[type]);
|
|
87
|
+
if (results[type].length) hasData = true;
|
|
88
|
+
delete this.aggregatedData[type];
|
|
89
|
+
}
|
|
90
|
+
return hasData ? results : null;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
exports.Aggregator = Aggregator;
|
|
94
|
+
function aggregateMetrics(newMetrics, oldMetrics) {
|
|
95
|
+
if (!oldMetrics) oldMetrics = {
|
|
96
|
+
count: 0
|
|
97
|
+
};
|
|
98
|
+
oldMetrics.count += 1;
|
|
99
|
+
(0, _mapOwn.mapOwn)(newMetrics, function (key, value) {
|
|
100
|
+
oldMetrics[key] = updateMetric(value, oldMetrics[key]);
|
|
101
|
+
});
|
|
102
|
+
return oldMetrics;
|
|
103
|
+
}
|
|
104
|
+
function updateMetric(value, metric) {
|
|
105
|
+
// when there is no value, then send only count
|
|
106
|
+
if (value == null) {
|
|
107
|
+
return updateCounterMetric(metric);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// When there is only one data point, the c (count), min, max, and sos (sum of squares) params are superfluous.
|
|
111
|
+
if (!metric) return {
|
|
112
|
+
t: value
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// but on the second data point, we need to calculate the other values before aggregating in new values
|
|
116
|
+
if (!metric.c) {
|
|
117
|
+
metric = createMetricObject(metric.t);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// at this point, metric is always uncondensed
|
|
121
|
+
metric.c += 1;
|
|
122
|
+
metric.t += value;
|
|
123
|
+
metric.sos += value * value;
|
|
124
|
+
if (value > metric.max) metric.max = value;
|
|
125
|
+
if (value < metric.min) metric.min = value;
|
|
126
|
+
return metric;
|
|
127
|
+
}
|
|
128
|
+
function updateCounterMetric(metric) {
|
|
129
|
+
if (!metric) {
|
|
130
|
+
metric = {
|
|
131
|
+
c: 1
|
|
132
|
+
};
|
|
133
|
+
} else {
|
|
134
|
+
metric.c++;
|
|
135
|
+
}
|
|
136
|
+
return metric;
|
|
137
|
+
}
|
|
138
|
+
function mergeMetric(newMetric, oldMetric) {
|
|
139
|
+
if (!oldMetric) return newMetric;
|
|
140
|
+
if (!oldMetric.c) {
|
|
141
|
+
// oldMetric is a single-value
|
|
142
|
+
oldMetric = createMetricObject(oldMetric.t);
|
|
143
|
+
}
|
|
144
|
+
oldMetric.min = Math.min(newMetric.min, oldMetric.min);
|
|
145
|
+
oldMetric.max = Math.max(newMetric.max, oldMetric.max);
|
|
146
|
+
oldMetric.t += newMetric.t;
|
|
147
|
+
oldMetric.sos += newMetric.sos;
|
|
148
|
+
oldMetric.c += newMetric.c;
|
|
149
|
+
return oldMetric;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
// take a value and create a metric object
|
|
153
|
+
function createMetricObject(value) {
|
|
154
|
+
return {
|
|
155
|
+
t: value,
|
|
156
|
+
min: value,
|
|
157
|
+
max: value,
|
|
158
|
+
sos: value * value,
|
|
159
|
+
c: 1
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
function toArray(obj) {
|
|
163
|
+
if (typeof obj !== 'object') return [];
|
|
164
|
+
return (0, _mapOwn.mapOwn)(obj, getValue);
|
|
165
|
+
}
|
|
166
|
+
function getValue(key, value) {
|
|
167
|
+
return value;
|
|
168
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.ffVersion = void 0;
|
|
7
|
+
/*
|
|
8
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
9
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
/* eslint-disable no-useless-escape */
|
|
13
|
+
|
|
14
|
+
var ffVersion = 0;
|
|
15
|
+
exports.ffVersion = ffVersion;
|
|
16
|
+
var match = navigator.userAgent.match(/Firefox[\/\s](\d+\.\d+)/);
|
|
17
|
+
if (match) exports.ffVersion = ffVersion = +match[1];
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isiOS = exports.iOS_below16 = void 0;
|
|
7
|
+
const isiOS = /(iPad|iPhone|iPod)/g.test(navigator.userAgent);
|
|
8
|
+
|
|
9
|
+
/* Feature detection to get our version(s). */
|
|
10
|
+
|
|
11
|
+
// Shared Web Workers introduced in iOS 16.0+ and n/a in 15.6-
|
|
12
|
+
exports.isiOS = isiOS;
|
|
13
|
+
const iOS_below16 = isiOS && Boolean(typeof SharedWorker === 'undefined');
|
|
14
|
+
/* ^ It was discovered in Safari 14 (https://bugs.webkit.org/show_bug.cgi?id=225305) that the buffered flag in PerformanceObserver
|
|
15
|
+
did not work. This affects our onFCP metric in particular since web-vitals uses that flag to retrieve paint timing entries.
|
|
16
|
+
This was fixed in v16+.
|
|
17
|
+
*/
|
|
18
|
+
exports.iOS_below16 = iOS_below16;
|