@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,75 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.onLongTask = void 0;
|
|
7
|
+
var _eol = require("../../common/unload/eol");
|
|
8
|
+
/**
|
|
9
|
+
* Calls the `onReport` function for every entry reported by the PerformanceLongTaskTiming API.
|
|
10
|
+
* The reported value is a `DOMHighResTimeStamp`.
|
|
11
|
+
*
|
|
12
|
+
* The callback is always called when the page's visibility state changes to hidden.
|
|
13
|
+
* As a result, the `onReport` function might be called multiple times during the same page load.
|
|
14
|
+
*
|
|
15
|
+
* @param {Function} onReport - callback that accepts a `metric` object as the single parameter
|
|
16
|
+
*/
|
|
17
|
+
const onLongTask = onReport => {
|
|
18
|
+
const handleEntries = entries => {
|
|
19
|
+
entries.forEach(entry => {
|
|
20
|
+
const metric = {
|
|
21
|
+
name: 'LT',
|
|
22
|
+
value: entry.duration,
|
|
23
|
+
info: {
|
|
24
|
+
// this property deviates from CWV std interface but will hold the custom context to send to NRDB
|
|
25
|
+
ltFrame: entry.name,
|
|
26
|
+
// MDN: the browsing context or frame that can be attributed to the long task
|
|
27
|
+
ltStart: entry.startTime,
|
|
28
|
+
// MDN: a double representing the time (millisec) when the task started
|
|
29
|
+
ltCtr: entry.attribution[0].containerType // MDN: type of frame container: 'iframe', 'embed', or 'object' ... but this can also be 'window'
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
if (metric.info.ltCtr !== 'window') {
|
|
34
|
+
// the following properties are only of relevance & appended for html elements
|
|
35
|
+
Object.assign(metric.info, {
|
|
36
|
+
ltCtrSrc: entry.attribution[0].containerSrc,
|
|
37
|
+
// MDN: container's 'src' attribute
|
|
38
|
+
ltCtrId: entry.attribution[0].containerId,
|
|
39
|
+
// MDN: container's 'id' attribute
|
|
40
|
+
ltCtrName: entry.attribution[0].containerName // MDN: container's 'name' attribute
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
onReport(metric); // report every long task observed unconditionally
|
|
45
|
+
});
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
let observer;
|
|
49
|
+
try {
|
|
50
|
+
if (PerformanceObserver.supportedEntryTypes.includes('longtask')) {
|
|
51
|
+
observer = new PerformanceObserver(list => {
|
|
52
|
+
// Delay by a microtask to workaround a bug in Safari where the
|
|
53
|
+
// callback is invoked immediately, rather than in a separate task.
|
|
54
|
+
// See: https://github.com/GoogleChrome/web-vitals/issues/277
|
|
55
|
+
Promise.resolve().then(() => {
|
|
56
|
+
handleEntries(list.getEntries());
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
observer.observe({
|
|
60
|
+
type: 'longtask',
|
|
61
|
+
buffered: true
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
} catch (e) {
|
|
65
|
+
// Do nothing.
|
|
66
|
+
}
|
|
67
|
+
if (observer) {
|
|
68
|
+
(0, _eol.subscribeToEOL)(() => {
|
|
69
|
+
handleEntries(observer.takeRecords());
|
|
70
|
+
}, true); // this bool is a temp arg under staged BFCache work that runs the func under the new page session logic -- tb removed w/ the feature flag later
|
|
71
|
+
|
|
72
|
+
/* No work needed on BFCache restore for long task. */
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
exports.onLongTask = onLongTask;
|
|
@@ -0,0 +1,375 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Aggregate = void 0;
|
|
7
|
+
var _registerHandler = require("../../../common/event-emitter/register-handler");
|
|
8
|
+
var _harvestScheduler = require("../../../common/harvest/harvest-scheduler");
|
|
9
|
+
var _mapOwn = require("../../../common/util/map-own");
|
|
10
|
+
var _reduce = require("../../../common/util/reduce");
|
|
11
|
+
var _stringify = require("../../../common/util/stringify");
|
|
12
|
+
var _parseUrl = require("../../../common/url/parse-url");
|
|
13
|
+
var _supportsPerformanceObserver = require("../../../common/window/supports-performance-observer");
|
|
14
|
+
var _lodash = _interopRequireDefault(require("lodash._slice"));
|
|
15
|
+
var _config = require("../../../common/config/config");
|
|
16
|
+
var _now = require("../../../common/timing/now");
|
|
17
|
+
var _aggregateBase = require("../../utils/aggregate-base");
|
|
18
|
+
var _constants = require("../constants");
|
|
19
|
+
var _drain = require("../../../common/drain/drain");
|
|
20
|
+
var _handlerCache = require("../../utils/handler-cache");
|
|
21
|
+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
|
+
/*
|
|
23
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
24
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
25
|
+
*/
|
|
26
|
+
|
|
27
|
+
class Aggregate extends _aggregateBase.AggregateBase {
|
|
28
|
+
static featureName = _constants.FEATURE_NAME;
|
|
29
|
+
constructor(agentIdentifier, aggregator) {
|
|
30
|
+
super(agentIdentifier, aggregator, _constants.FEATURE_NAME);
|
|
31
|
+
|
|
32
|
+
// Very unlikely, but in case the existing XMLHttpRequest.prototype object on the page couldn't be wrapped.
|
|
33
|
+
if (!(0, _config.getRuntime)(agentIdentifier).xhrWrappable) return;
|
|
34
|
+
const handlerCache = new _handlerCache.HandlerCache();
|
|
35
|
+
this.ptid = '';
|
|
36
|
+
this.ignoredEvents = {
|
|
37
|
+
// we find that certain events make the data too noisy to be useful
|
|
38
|
+
global: {
|
|
39
|
+
mouseup: true,
|
|
40
|
+
mousedown: true
|
|
41
|
+
},
|
|
42
|
+
// certain events are present both in the window and in PVT metrics. PVT metrics are prefered so the window events should be ignored
|
|
43
|
+
window: {
|
|
44
|
+
load: true,
|
|
45
|
+
pagehide: true
|
|
46
|
+
},
|
|
47
|
+
// when ajax instrumentation is disabled, all XMLHttpRequest events will return with origin = xhrOriginMissing and should be ignored
|
|
48
|
+
xhrOriginMissing: {
|
|
49
|
+
ignoreAll: true
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
this.toAggregate = {
|
|
53
|
+
typing: [1000, 2000],
|
|
54
|
+
scrolling: [100, 1000],
|
|
55
|
+
mousing: [1000, 2000],
|
|
56
|
+
touching: [1000, 2000]
|
|
57
|
+
};
|
|
58
|
+
this.rename = {
|
|
59
|
+
typing: {
|
|
60
|
+
keydown: true,
|
|
61
|
+
keyup: true,
|
|
62
|
+
keypress: true
|
|
63
|
+
},
|
|
64
|
+
mousing: {
|
|
65
|
+
mousemove: true,
|
|
66
|
+
mouseenter: true,
|
|
67
|
+
mouseleave: true,
|
|
68
|
+
mouseover: true,
|
|
69
|
+
mouseout: true
|
|
70
|
+
},
|
|
71
|
+
scrolling: {
|
|
72
|
+
scroll: true
|
|
73
|
+
},
|
|
74
|
+
touching: {
|
|
75
|
+
touchstart: true,
|
|
76
|
+
touchmove: true,
|
|
77
|
+
touchend: true,
|
|
78
|
+
touchcancel: true,
|
|
79
|
+
touchenter: true,
|
|
80
|
+
touchleave: true
|
|
81
|
+
}
|
|
82
|
+
};
|
|
83
|
+
this.trace = {};
|
|
84
|
+
this.nodeCount = 0;
|
|
85
|
+
this.sentTrace = null;
|
|
86
|
+
this.harvestTimeSeconds = (0, _config.getConfigurationValue)(agentIdentifier, 'session_trace.harvestTimeSeconds') || 10;
|
|
87
|
+
this.maxNodesPerHarvest = (0, _config.getConfigurationValue)(agentIdentifier, 'session_trace.maxNodesPerHarvest') || 1000;
|
|
88
|
+
this.laststart = 0;
|
|
89
|
+
(0, _registerHandler.registerHandler)('feat-stn', () => {
|
|
90
|
+
this.storeTiming(window.performance.timing);
|
|
91
|
+
var scheduler = new _harvestScheduler.HarvestScheduler('resources', {
|
|
92
|
+
onFinished: onHarvestFinished.bind(this),
|
|
93
|
+
retryDelay: this.harvestTimeSeconds
|
|
94
|
+
}, this);
|
|
95
|
+
scheduler.harvest.on('resources', prepareHarvest.bind(this));
|
|
96
|
+
scheduler.runHarvest({
|
|
97
|
+
needResponse: true
|
|
98
|
+
}); // sends first stn harvest immediately
|
|
99
|
+
|
|
100
|
+
function onHarvestFinished(result) {
|
|
101
|
+
// start timer only if ptid was returned by server
|
|
102
|
+
if (result.sent && result.responseText && !this.ptid) {
|
|
103
|
+
this.ptid = result.responseText;
|
|
104
|
+
(0, _config.getRuntime)(this.agentIdentifier).ptid = this.ptid;
|
|
105
|
+
scheduler.startTimer(this.harvestTimeSeconds);
|
|
106
|
+
}
|
|
107
|
+
if (result.sent && result.retry && this.sentTrace) {
|
|
108
|
+
(0, _mapOwn.mapOwn)(this.sentTrace, (name, nodes) => {
|
|
109
|
+
this.mergeSTNs(name, nodes);
|
|
110
|
+
});
|
|
111
|
+
this.sentTrace = null;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
function prepareHarvest(options) {
|
|
115
|
+
if ((0, _now.now)() > 15 * 60 * 1000) {
|
|
116
|
+
// been collecting for over 15 min, empty trace object and bail
|
|
117
|
+
scheduler.stopTimer();
|
|
118
|
+
this.trace = {};
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// only send when there are more than 30 nodes to send
|
|
123
|
+
if (this.ptid && this.nodeCount <= 30) return;
|
|
124
|
+
return this.takeSTNs(options.retry);
|
|
125
|
+
}
|
|
126
|
+
handlerCache.decide(true);
|
|
127
|
+
}, this.featureName, this.ee);
|
|
128
|
+
(0, _registerHandler.registerHandler)('block-stn', () => {
|
|
129
|
+
handlerCache.decide(false);
|
|
130
|
+
}, this.featureName, this.ee);
|
|
131
|
+
|
|
132
|
+
// register the handlers immediately... but let the handlerCache decide if the data should actually get stored...
|
|
133
|
+
(0, _registerHandler.registerHandler)('bst', (...args) => handlerCache.settle(() => this.storeEvent(...args)), this.featureName, this.ee);
|
|
134
|
+
(0, _registerHandler.registerHandler)('bstTimer', (...args) => handlerCache.settle(() => this.storeTimer(...args)), this.featureName, this.ee);
|
|
135
|
+
(0, _registerHandler.registerHandler)('bstResource', (...args) => handlerCache.settle(() => this.storeResources(...args)), this.featureName, this.ee);
|
|
136
|
+
(0, _registerHandler.registerHandler)('bstHist', (...args) => handlerCache.settle(() => this.storeHist(...args)), this.featureName, this.ee);
|
|
137
|
+
(0, _registerHandler.registerHandler)('bstXhrAgg', (...args) => handlerCache.settle(() => this.storeXhrAgg(...args)), this.featureName, this.ee);
|
|
138
|
+
(0, _registerHandler.registerHandler)('bstApi', (...args) => handlerCache.settle(() => this.storeSTN(...args)), this.featureName, this.ee);
|
|
139
|
+
(0, _registerHandler.registerHandler)('errorAgg', (...args) => handlerCache.settle(() => this.storeErrorAgg(...args)), this.featureName, this.ee);
|
|
140
|
+
(0, _registerHandler.registerHandler)('pvtAdded', (...args) => handlerCache.settle(() => this.processPVT(...args)), this.featureName, this.ee);
|
|
141
|
+
(0, _drain.drain)(this.agentIdentifier, this.featureName);
|
|
142
|
+
}
|
|
143
|
+
processPVT(name, value, attrs) {
|
|
144
|
+
var t = {};
|
|
145
|
+
t[name] = value;
|
|
146
|
+
this.storeTiming(t, true);
|
|
147
|
+
if (this.hasFID(name, attrs)) this.storeEvent({
|
|
148
|
+
type: 'fid',
|
|
149
|
+
target: 'document'
|
|
150
|
+
}, 'document', value, value + attrs.fid);
|
|
151
|
+
}
|
|
152
|
+
storeTiming(_t, ignoreOffset) {
|
|
153
|
+
var key;
|
|
154
|
+
var val;
|
|
155
|
+
var timeOffset;
|
|
156
|
+
var dateNow = Date.now();
|
|
157
|
+
|
|
158
|
+
// loop iterates through prototype also (for FF)
|
|
159
|
+
for (key in _t) {
|
|
160
|
+
val = _t[key];
|
|
161
|
+
|
|
162
|
+
// ignore inherited methods, meaningless 0 values, and bogus timestamps
|
|
163
|
+
// that are in the future (Microsoft Edge seems to sometimes produce these)
|
|
164
|
+
if (!(typeof val === 'number' && val > 0 && val < dateNow)) continue;
|
|
165
|
+
timeOffset = !ignoreOffset ? _t[key] - (0, _config.getRuntime)(this.agentIdentifier).offset : _t[key];
|
|
166
|
+
this.storeSTN({
|
|
167
|
+
n: key,
|
|
168
|
+
s: timeOffset,
|
|
169
|
+
e: timeOffset,
|
|
170
|
+
o: 'document',
|
|
171
|
+
t: 'timing'
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
storeTimer(target, start, end, type) {
|
|
176
|
+
var category = 'timer';
|
|
177
|
+
if (type === 'requestAnimationFrame') category = type;
|
|
178
|
+
var evt = {
|
|
179
|
+
n: type,
|
|
180
|
+
s: start,
|
|
181
|
+
e: end,
|
|
182
|
+
o: 'window',
|
|
183
|
+
t: category
|
|
184
|
+
};
|
|
185
|
+
this.storeSTN(evt);
|
|
186
|
+
}
|
|
187
|
+
storeEvent(currentEvent, target, start, end) {
|
|
188
|
+
if (this.shouldIgnoreEvent(currentEvent, target)) return false;
|
|
189
|
+
var evt = {
|
|
190
|
+
n: this.evtName(currentEvent.type),
|
|
191
|
+
s: start,
|
|
192
|
+
e: end,
|
|
193
|
+
t: 'event'
|
|
194
|
+
};
|
|
195
|
+
try {
|
|
196
|
+
// webcomponents-lite.js can trigger an exception on currentEvent.target getter because
|
|
197
|
+
// it does not check currentEvent.currentTarget before calling getRootNode() on it
|
|
198
|
+
evt.o = this.evtOrigin(currentEvent.target, target);
|
|
199
|
+
} catch (e) {
|
|
200
|
+
evt.o = this.evtOrigin(null, target);
|
|
201
|
+
}
|
|
202
|
+
this.storeSTN(evt);
|
|
203
|
+
}
|
|
204
|
+
evtName(type) {
|
|
205
|
+
var name = type;
|
|
206
|
+
(0, _mapOwn.mapOwn)(this.rename, function (key, val) {
|
|
207
|
+
if (type in val) name = key;
|
|
208
|
+
});
|
|
209
|
+
return name;
|
|
210
|
+
}
|
|
211
|
+
evtOrigin(t, target) {
|
|
212
|
+
var origin = 'unknown';
|
|
213
|
+
if (t && t instanceof XMLHttpRequest) {
|
|
214
|
+
var params = this.ee.context(t).params;
|
|
215
|
+
if (!params || !params.status || !params.method || !params.host || !params.pathname) return 'xhrOriginMissing';
|
|
216
|
+
origin = params.status + ' ' + params.method + ': ' + params.host + params.pathname;
|
|
217
|
+
} else if (t && typeof t.tagName === 'string') {
|
|
218
|
+
origin = t.tagName.toLowerCase();
|
|
219
|
+
if (t.id) origin += '#' + t.id;
|
|
220
|
+
if (t.className) origin += '.' + (0, _lodash.default)(t.classList).join('.');
|
|
221
|
+
}
|
|
222
|
+
if (origin === 'unknown') {
|
|
223
|
+
if (typeof target === 'string') origin = target;else if (target === document) origin = 'document';else if (target === window) origin = 'window';else if (target instanceof FileReader) origin = 'FileReader';
|
|
224
|
+
}
|
|
225
|
+
return origin;
|
|
226
|
+
}
|
|
227
|
+
storeHist(path, old, time) {
|
|
228
|
+
var node = {
|
|
229
|
+
n: 'history.pushState',
|
|
230
|
+
s: time,
|
|
231
|
+
e: time,
|
|
232
|
+
o: path,
|
|
233
|
+
t: old
|
|
234
|
+
};
|
|
235
|
+
this.storeSTN(node);
|
|
236
|
+
}
|
|
237
|
+
storeResources(resources) {
|
|
238
|
+
if (!resources || resources.length === 0) return;
|
|
239
|
+
resources.forEach(currentResource => {
|
|
240
|
+
var parsed = (0, _parseUrl.parseUrl)(currentResource.name);
|
|
241
|
+
var res = {
|
|
242
|
+
n: currentResource.initiatorType,
|
|
243
|
+
s: currentResource.fetchStart | 0,
|
|
244
|
+
e: currentResource.responseEnd | 0,
|
|
245
|
+
o: parsed.protocol + '://' + parsed.hostname + ':' + parsed.port + parsed.pathname,
|
|
246
|
+
// resource.name is actually a URL so it's the source
|
|
247
|
+
t: currentResource.entryType
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
// don't recollect old resources
|
|
251
|
+
if (res.s <= this.laststart) return;
|
|
252
|
+
this.storeSTN(res);
|
|
253
|
+
});
|
|
254
|
+
this.laststart = resources[resources.length - 1].fetchStart | 0;
|
|
255
|
+
}
|
|
256
|
+
storeErrorAgg(type, name, params, metrics) {
|
|
257
|
+
if (type !== 'err') return;
|
|
258
|
+
var node = {
|
|
259
|
+
n: 'error',
|
|
260
|
+
s: metrics.time,
|
|
261
|
+
e: metrics.time,
|
|
262
|
+
o: params.message,
|
|
263
|
+
t: params.stackHash
|
|
264
|
+
};
|
|
265
|
+
this.storeSTN(node);
|
|
266
|
+
}
|
|
267
|
+
storeXhrAgg(type, name, params, metrics) {
|
|
268
|
+
if (type !== 'xhr') return;
|
|
269
|
+
var node = {
|
|
270
|
+
n: 'Ajax',
|
|
271
|
+
s: metrics.time,
|
|
272
|
+
e: metrics.time + metrics.duration,
|
|
273
|
+
o: params.status + ' ' + params.method + ': ' + params.host + params.pathname,
|
|
274
|
+
t: 'ajax'
|
|
275
|
+
};
|
|
276
|
+
this.storeSTN(node);
|
|
277
|
+
}
|
|
278
|
+
storeSTN(stn) {
|
|
279
|
+
// limit the number of data that is stored
|
|
280
|
+
if (this.nodeCount >= this.maxNodesPerHarvest) return;
|
|
281
|
+
var traceArr = this.trace[stn.n];
|
|
282
|
+
if (!traceArr) traceArr = this.trace[stn.n] = [];
|
|
283
|
+
traceArr.push(stn);
|
|
284
|
+
this.nodeCount++;
|
|
285
|
+
}
|
|
286
|
+
mergeSTNs(key, nodes) {
|
|
287
|
+
// limit the number of data that is stored
|
|
288
|
+
if (this.nodeCount >= this.maxNodesPerHarvest) return;
|
|
289
|
+
var traceArr = this.trace[key];
|
|
290
|
+
if (!traceArr) traceArr = this.trace[key] = [];
|
|
291
|
+
this.trace[key] = nodes.concat(traceArr);
|
|
292
|
+
this.nodeCount += nodes.length;
|
|
293
|
+
}
|
|
294
|
+
takeSTNs(retry) {
|
|
295
|
+
// if the observer is not being used, this checks resourcetiming buffer every harvest
|
|
296
|
+
if (!(0, _supportsPerformanceObserver.supportsPerformanceObserver)()) {
|
|
297
|
+
this.storeResources(window.performance.getEntriesByType('resource'));
|
|
298
|
+
}
|
|
299
|
+
var stns = (0, _reduce.reduce)((0, _mapOwn.mapOwn)(this.trace, (name, nodes) => {
|
|
300
|
+
if (!(name in this.toAggregate)) return nodes;
|
|
301
|
+
return (0, _reduce.reduce)((0, _mapOwn.mapOwn)((0, _reduce.reduce)(nodes.sort(this.byStart), this.smearEvtsByOrigin(name), {}), this.val), this.flatten, []);
|
|
302
|
+
}), this.flatten, []);
|
|
303
|
+
if (stns.length === 0) return {};
|
|
304
|
+
if (retry) {
|
|
305
|
+
this.sentTrace = this.trace;
|
|
306
|
+
}
|
|
307
|
+
this.trace = {};
|
|
308
|
+
this.nodeCount = 0;
|
|
309
|
+
var stnInfo = {
|
|
310
|
+
qs: {
|
|
311
|
+
st: '' + (0, _config.getRuntime)(this.agentIdentifier).offset
|
|
312
|
+
},
|
|
313
|
+
body: {
|
|
314
|
+
res: stns
|
|
315
|
+
}
|
|
316
|
+
};
|
|
317
|
+
if (!this.ptid) {
|
|
318
|
+
const {
|
|
319
|
+
userAttributes,
|
|
320
|
+
atts,
|
|
321
|
+
jsAttributes
|
|
322
|
+
} = (0, _config.getInfo)(this.agentIdentifier);
|
|
323
|
+
stnInfo.qs.ua = userAttributes;
|
|
324
|
+
stnInfo.qs.at = atts;
|
|
325
|
+
var ja = (0, _stringify.stringify)(jsAttributes);
|
|
326
|
+
stnInfo.qs.ja = ja === '{}' ? null : ja;
|
|
327
|
+
}
|
|
328
|
+
return stnInfo;
|
|
329
|
+
}
|
|
330
|
+
byStart(a, b) {
|
|
331
|
+
return a.s - b.s;
|
|
332
|
+
}
|
|
333
|
+
smearEvtsByOrigin(name) {
|
|
334
|
+
var maxGap = this.toAggregate[name][0];
|
|
335
|
+
var maxLen = this.toAggregate[name][1];
|
|
336
|
+
var lastO = {};
|
|
337
|
+
return (byOrigin, evt) => {
|
|
338
|
+
var lastArr = byOrigin[evt.o];
|
|
339
|
+
lastArr || (lastArr = byOrigin[evt.o] = []);
|
|
340
|
+
var last = lastO[evt.o];
|
|
341
|
+
if (name === 'scrolling' && !this.trivial(evt)) {
|
|
342
|
+
lastO[evt.o] = null;
|
|
343
|
+
evt.n = 'scroll';
|
|
344
|
+
lastArr.push(evt);
|
|
345
|
+
} else if (last && evt.s - last.s < maxLen && last.e > evt.s - maxGap) {
|
|
346
|
+
last.e = evt.e;
|
|
347
|
+
} else {
|
|
348
|
+
lastO[evt.o] = evt;
|
|
349
|
+
lastArr.push(evt);
|
|
350
|
+
}
|
|
351
|
+
return byOrigin;
|
|
352
|
+
};
|
|
353
|
+
}
|
|
354
|
+
val(key, value) {
|
|
355
|
+
return value;
|
|
356
|
+
}
|
|
357
|
+
flatten(a, b) {
|
|
358
|
+
return a.concat(b);
|
|
359
|
+
}
|
|
360
|
+
hasFID(name, attrs) {
|
|
361
|
+
return name === 'fi' && !!attrs && typeof attrs.fid === 'number';
|
|
362
|
+
}
|
|
363
|
+
trivial(node) {
|
|
364
|
+
var limit = 4;
|
|
365
|
+
if (node && typeof node.e === 'number' && typeof node.s === 'number' && node.e - node.s < limit) return true;else return false;
|
|
366
|
+
}
|
|
367
|
+
shouldIgnoreEvent(event, target) {
|
|
368
|
+
var origin = this.evtOrigin(event.target, target);
|
|
369
|
+
if (event.type in this.ignoredEvents.global) return true;
|
|
370
|
+
if (!!this.ignoredEvents[origin] && this.ignoredEvents[origin].ignoreAll) return true;
|
|
371
|
+
if (!!this.ignoredEvents[origin] && event.type in this.ignoredEvents[origin]) return true;
|
|
372
|
+
return false;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
exports.Aggregate = Aggregate;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.START = exports.RESOURCE_TIMING_BUFFER_FULL = exports.RESOURCE = exports.PUSH_STATE = exports.ORIG_EVENT = exports.FN_START = exports.FN_END = exports.FEATURE_NAME = exports.END = exports.BST_TIMER = exports.BST_RESOURCE = exports.ADD_EVENT_LISTENER = void 0;
|
|
7
|
+
var _config = require("../../common/config/config");
|
|
8
|
+
var _features = require("../../loaders/features/features");
|
|
9
|
+
const FEATURE_NAME = _features.FEATURE_NAMES.sessionTrace;
|
|
10
|
+
exports.FEATURE_NAME = FEATURE_NAME;
|
|
11
|
+
const RESOURCE_TIMING_BUFFER_FULL = 'resourcetimingbufferfull';
|
|
12
|
+
exports.RESOURCE_TIMING_BUFFER_FULL = RESOURCE_TIMING_BUFFER_FULL;
|
|
13
|
+
const BST_RESOURCE = 'bstResource';
|
|
14
|
+
exports.BST_RESOURCE = BST_RESOURCE;
|
|
15
|
+
const RESOURCE = 'resource';
|
|
16
|
+
exports.RESOURCE = RESOURCE;
|
|
17
|
+
const START = '-start';
|
|
18
|
+
exports.START = START;
|
|
19
|
+
const END = '-end';
|
|
20
|
+
exports.END = END;
|
|
21
|
+
const FN_START = 'fn' + START;
|
|
22
|
+
exports.FN_START = FN_START;
|
|
23
|
+
const FN_END = 'fn' + END;
|
|
24
|
+
exports.FN_END = FN_END;
|
|
25
|
+
const BST_TIMER = 'bstTimer';
|
|
26
|
+
exports.BST_TIMER = BST_TIMER;
|
|
27
|
+
const PUSH_STATE = 'pushState';
|
|
28
|
+
exports.PUSH_STATE = PUSH_STATE;
|
|
29
|
+
const ORIG_EVENT = _config.originals.EV;
|
|
30
|
+
exports.ORIG_EVENT = ORIG_EVENT;
|
|
31
|
+
const ADD_EVENT_LISTENER = 'addEventListener';
|
|
32
|
+
exports.ADD_EVENT_LISTENER = ADD_EVENT_LISTENER;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "SessionTrace", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _index.Instrument;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _index = require("./instrument/index");
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.Instrument = void 0;
|
|
7
|
+
var _handle = require("../../../common/event-emitter/handle");
|
|
8
|
+
var _wrap = require("../../../common/wrap");
|
|
9
|
+
var _supportsPerformanceObserver = require("../../../common/window/supports-performance-observer");
|
|
10
|
+
var _eventListenerOpts = require("../../../common/event-listener/event-listener-opts");
|
|
11
|
+
var _now = require("../../../common/timing/now");
|
|
12
|
+
var _instrumentBase = require("../../utils/instrument-base");
|
|
13
|
+
var CONSTANTS = _interopRequireWildcard(require("../constants"));
|
|
14
|
+
var _features = require("../../../loaders/features/features");
|
|
15
|
+
var _globalScope = require("../../../common/util/global-scope");
|
|
16
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
18
|
+
/*
|
|
19
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
20
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
const {
|
|
24
|
+
BST_RESOURCE,
|
|
25
|
+
BST_TIMER,
|
|
26
|
+
END,
|
|
27
|
+
FEATURE_NAME,
|
|
28
|
+
FN_END,
|
|
29
|
+
FN_START,
|
|
30
|
+
ADD_EVENT_LISTENER,
|
|
31
|
+
PUSH_STATE,
|
|
32
|
+
RESOURCE,
|
|
33
|
+
RESOURCE_TIMING_BUFFER_FULL,
|
|
34
|
+
START,
|
|
35
|
+
ORIG_EVENT: origEvent
|
|
36
|
+
} = CONSTANTS;
|
|
37
|
+
const CRT = 'clearResourceTimings';
|
|
38
|
+
class Instrument extends _instrumentBase.InstrumentBase {
|
|
39
|
+
static featureName = FEATURE_NAME;
|
|
40
|
+
constructor(agentIdentifier, aggregator, auto = true) {
|
|
41
|
+
super(agentIdentifier, aggregator, FEATURE_NAME, auto);
|
|
42
|
+
if (!_globalScope.isBrowserScope) return; // session traces not supported outside web env
|
|
43
|
+
|
|
44
|
+
const thisInstrumentEE = this.ee;
|
|
45
|
+
this.timerEE = (0, _wrap.wrapTimer)(thisInstrumentEE);
|
|
46
|
+
this.rafEE = (0, _wrap.wrapRaf)(thisInstrumentEE);
|
|
47
|
+
(0, _wrap.wrapHistory)(thisInstrumentEE);
|
|
48
|
+
(0, _wrap.wrapEvents)(thisInstrumentEE);
|
|
49
|
+
thisInstrumentEE.on(FN_START, function (args, target) {
|
|
50
|
+
var evt = args[0];
|
|
51
|
+
if (evt instanceof origEvent) {
|
|
52
|
+
this.bstStart = (0, _now.now)();
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
thisInstrumentEE.on(FN_END, function (args, target) {
|
|
56
|
+
var evt = args[0];
|
|
57
|
+
if (evt instanceof origEvent) {
|
|
58
|
+
// ISSUE: when target is XMLHttpRequest, nr@context should have params so we can calculate event origin
|
|
59
|
+
// When ajax is disabled, this may fail without making ajax a dependency of session_trace
|
|
60
|
+
(0, _handle.handle)('bst', [evt, target, this.bstStart, (0, _now.now)()], undefined, _features.FEATURE_NAMES.sessionTrace, thisInstrumentEE);
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
this.timerEE.on(FN_START, function (args, obj, type) {
|
|
64
|
+
this.bstStart = (0, _now.now)();
|
|
65
|
+
this.bstType = type;
|
|
66
|
+
});
|
|
67
|
+
this.timerEE.on(FN_END, function (args, target) {
|
|
68
|
+
(0, _handle.handle)(BST_TIMER, [target, this.bstStart, (0, _now.now)(), this.bstType], undefined, _features.FEATURE_NAMES.sessionTrace, thisInstrumentEE);
|
|
69
|
+
});
|
|
70
|
+
this.rafEE.on(FN_START, function () {
|
|
71
|
+
this.bstStart = (0, _now.now)();
|
|
72
|
+
});
|
|
73
|
+
this.rafEE.on(FN_END, function (args, target) {
|
|
74
|
+
(0, _handle.handle)(BST_TIMER, [target, this.bstStart, (0, _now.now)(), 'requestAnimationFrame'], undefined, _features.FEATURE_NAMES.sessionTrace, thisInstrumentEE);
|
|
75
|
+
});
|
|
76
|
+
thisInstrumentEE.on(PUSH_STATE + START, function (args) {
|
|
77
|
+
this.time = (0, _now.now)();
|
|
78
|
+
this.startPath = location.pathname + location.hash;
|
|
79
|
+
});
|
|
80
|
+
thisInstrumentEE.on(PUSH_STATE + END, function (args) {
|
|
81
|
+
(0, _handle.handle)('bstHist', [location.pathname + location.hash, this.startPath, this.time], undefined, _features.FEATURE_NAMES.sessionTrace, thisInstrumentEE);
|
|
82
|
+
});
|
|
83
|
+
if ((0, _supportsPerformanceObserver.supportsPerformanceObserver)()) {
|
|
84
|
+
// capture initial resources, in case our observer missed anything
|
|
85
|
+
(0, _handle.handle)(BST_RESOURCE, [window.performance.getEntriesByType('resource')], undefined, _features.FEATURE_NAMES.sessionTrace, thisInstrumentEE);
|
|
86
|
+
observeResourceTimings();
|
|
87
|
+
} else {
|
|
88
|
+
// collect resource timings once when buffer is full
|
|
89
|
+
if (window.performance[CRT] && window.performance[ADD_EVENT_LISTENER]) {
|
|
90
|
+
window.performance.addEventListener(RESOURCE_TIMING_BUFFER_FULL, this.onResourceTimingBufferFull, (0, _eventListenerOpts.eventListenerOpts)(false));
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
function observeResourceTimings() {
|
|
94
|
+
var observer = new PerformanceObserver((list, observer) => {
|
|
95
|
+
// eslint-disable-line no-undef
|
|
96
|
+
var entries = list.getEntries();
|
|
97
|
+
(0, _handle.handle)(BST_RESOURCE, [entries], undefined, _features.FEATURE_NAMES.sessionTrace, thisInstrumentEE);
|
|
98
|
+
});
|
|
99
|
+
try {
|
|
100
|
+
observer.observe({
|
|
101
|
+
entryTypes: ['resource']
|
|
102
|
+
});
|
|
103
|
+
} catch (e) {
|
|
104
|
+
// do nothing
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
document.addEventListener('scroll', this.noOp, (0, _eventListenerOpts.eventListenerOpts)(false));
|
|
108
|
+
document.addEventListener('keypress', this.noOp, (0, _eventListenerOpts.eventListenerOpts)(false));
|
|
109
|
+
document.addEventListener('click', this.noOp, (0, _eventListenerOpts.eventListenerOpts)(false));
|
|
110
|
+
this.abortHandler = this.#abort;
|
|
111
|
+
this.importAggregator();
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** Restoration and resource release tasks to be done if Session trace loader is being aborted. Unwind changes to globals. */
|
|
115
|
+
#abort() {
|
|
116
|
+
window.performance.removeEventListener(RESOURCE_TIMING_BUFFER_FULL, this.onResourceTimingBufferFull, false);
|
|
117
|
+
// The doc interaction noOp listeners are harmless--cannot buffer data into EE.
|
|
118
|
+
this.abortHandler = undefined; // weakly allow this abort op to run only once
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
noOp(e) {/* no-op */}
|
|
122
|
+
onResourceTimingBufferFull(evt) {
|
|
123
|
+
(0, _handle.handle)(BST_RESOURCE, [window.performance.getEntriesByType(RESOURCE)], undefined, _features.FEATURE_NAMES.sessionTrace, this.ee);
|
|
124
|
+
|
|
125
|
+
// stop recording once buffer is full
|
|
126
|
+
if (window.performance[CRT]) {
|
|
127
|
+
try {
|
|
128
|
+
window.performance.removeEventListener(RESOURCE_TIMING_BUFFER_FULL, this.onResourceTimingBufferFull, false);
|
|
129
|
+
} catch (e) {}
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
exports.Instrument = Instrument;
|