@newrelic/browser-agent 0.1.229 → 0.1.231
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 +65 -2
- package/dist/cjs/common/browser-version/ios-version.js +4 -3
- package/dist/cjs/common/config/state/configurable.js +3 -2
- package/dist/cjs/common/config/state/info.js +1 -1
- package/dist/cjs/common/config/state/init.js +1 -1
- package/dist/cjs/common/config/state/loader-config.js +1 -1
- package/dist/cjs/common/config/state/runtime.js +6 -5
- package/dist/cjs/common/constants/env.cdn.js +29 -0
- package/dist/cjs/common/constants/env.js +32 -0
- package/dist/cjs/common/constants/env.npm.js +30 -0
- package/dist/cjs/common/context/shared-context.js +2 -1
- package/dist/cjs/common/drain/drain.js +9 -3
- package/dist/cjs/common/event-emitter/contextual-ee.test.js +282 -0
- package/dist/cjs/common/event-emitter/handle.test.js +58 -0
- package/dist/cjs/common/event-emitter/register-handler.test.js +55 -0
- package/dist/cjs/common/event-listener/event-listener-opts.js +4 -2
- package/dist/cjs/common/harvest/harvest-scheduler.js +2 -1
- package/dist/cjs/common/harvest/harvest.js +15 -4
- package/dist/cjs/common/ids/id.js +14 -6
- package/dist/cjs/common/ids/id.test.js +85 -0
- package/dist/cjs/common/ids/unique-id.js +75 -51
- package/dist/cjs/common/ids/unique-id.test.js +49 -0
- package/dist/cjs/common/timing/nav-timing.js +51 -30
- package/dist/cjs/common/timing/nav-timing.test.js +192 -0
- package/dist/cjs/common/url/clean-url.test.js +9 -0
- package/dist/cjs/common/url/encode.test.js +74 -0
- package/dist/cjs/common/url/location.js +4 -0
- package/dist/cjs/common/url/location.test.js +13 -0
- package/dist/cjs/common/url/parse-url.test.js +111 -0
- package/dist/cjs/common/url/protocol.js +2 -12
- package/dist/cjs/common/url/protocol.test.js +16 -0
- package/dist/cjs/common/util/console.js +2 -2
- package/dist/cjs/common/util/map-own.js +21 -14
- package/dist/cjs/common/util/map-own.test.js +49 -0
- package/dist/cjs/common/util/obfuscate.js +1 -1
- package/dist/cjs/common/util/submit-data.js +11 -3
- package/dist/cjs/common/window/page-visibility.js +4 -2
- package/dist/cjs/common/window/session-storage.js +56 -11
- package/dist/cjs/common/wrap/index.js +4 -4
- package/dist/cjs/common/wrap/wrap-events.js +10 -10
- package/dist/cjs/common/wrap/wrap-fetch.js +6 -8
- package/dist/cjs/common/wrap/wrap-function.js +4 -18
- package/dist/cjs/common/wrap/wrap-history.js +7 -6
- package/dist/cjs/common/wrap/wrap-jsonp.js +7 -6
- package/dist/cjs/common/wrap/wrap-mutation.js +7 -6
- package/dist/cjs/common/wrap/wrap-promise.js +11 -7
- package/dist/cjs/common/wrap/wrap-promise.test.js +119 -0
- package/dist/cjs/common/wrap/wrap-raf.js +6 -6
- package/dist/cjs/common/wrap/wrap-timer.js +6 -6
- package/dist/cjs/common/wrap/wrap-xhr.js +5 -6
- package/dist/cjs/features/ajax/aggregate/index.js +1 -1
- package/dist/cjs/features/ajax/instrument/index.js +2 -1
- package/dist/cjs/features/jserrors/aggregate/canonical-function-name.test.js +5 -4
- package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.js +1 -2
- package/dist/cjs/features/jserrors/aggregate/compute-stack-trace.test.js +5 -5
- package/dist/cjs/features/jserrors/aggregate/format-stack-trace.test.js +6 -5
- package/dist/cjs/features/jserrors/aggregate/index.js +35 -14
- package/dist/cjs/features/jserrors/aggregate/string-hash-code.test.js +5 -4
- package/dist/cjs/features/jserrors/instrument/index.js +9 -12
- package/dist/cjs/features/metrics/aggregate/index.js +16 -6
- package/dist/cjs/features/metrics/instrument/index.js +2 -1
- package/dist/cjs/features/metrics/instrument/workers-helper.js +9 -6
- package/dist/cjs/features/page_action/aggregate/index.js +12 -4
- package/dist/cjs/features/page_action/instrument/index.js +2 -1
- package/dist/cjs/features/page_view_event/aggregate/index.js +25 -10
- package/dist/cjs/features/page_view_event/instrument/index.js +2 -1
- package/dist/cjs/features/page_view_timing/aggregate/index.js +90 -61
- package/dist/cjs/features/page_view_timing/instrument/index.js +2 -1
- package/dist/cjs/features/session_trace/aggregate/index.js +69 -26
- package/dist/cjs/features/session_trace/instrument/index.js +2 -1
- package/dist/cjs/features/spa/instrument/index.js +2 -1
- package/dist/cjs/features/utils/instrument-base.js +8 -3
- package/dist/cjs/features/utils/lazy-loader.js +1 -1
- package/dist/cjs/index.js +9 -9
- package/dist/cjs/loaders/agent.js +3 -2
- package/dist/cjs/loaders/api/api.js +90 -22
- package/dist/cjs/loaders/api/apiAsync.js +3 -3
- package/dist/cjs/loaders/configure/configure.js +13 -7
- package/dist/cjs/loaders/features/enabled-features.js +1 -1
- package/dist/cjs/loaders/micro-agent.js +20 -14
- package/dist/esm/common/browser-version/ios-version.js +4 -3
- package/dist/esm/common/config/state/configurable.js +3 -2
- package/dist/esm/common/config/state/info.js +1 -1
- package/dist/esm/common/config/state/init.js +1 -1
- package/dist/esm/common/config/state/loader-config.js +1 -1
- package/dist/esm/common/config/state/runtime.js +3 -2
- package/dist/esm/common/constants/env.cdn.js +20 -0
- package/dist/esm/common/constants/env.js +23 -0
- package/dist/esm/common/constants/env.npm.js +21 -0
- package/dist/esm/common/context/shared-context.js +2 -1
- package/dist/esm/common/drain/drain.js +9 -3
- package/dist/esm/common/event-emitter/contextual-ee.test.js +278 -0
- package/dist/esm/common/event-emitter/handle.test.js +54 -0
- package/dist/esm/common/event-emitter/register-handler.test.js +51 -0
- package/dist/esm/common/event-listener/event-listener-opts.js +4 -2
- package/dist/esm/common/harvest/harvest-scheduler.js +2 -1
- package/dist/esm/common/harvest/harvest.js +14 -3
- package/dist/esm/common/ids/id.js +16 -6
- package/dist/esm/common/ids/id.test.js +81 -0
- package/dist/esm/common/ids/unique-id.js +75 -51
- package/dist/esm/common/ids/unique-id.test.js +44 -0
- package/dist/esm/common/timing/nav-timing.js +51 -29
- package/dist/esm/common/timing/nav-timing.test.js +190 -0
- package/dist/esm/common/url/clean-url.test.js +7 -0
- package/dist/esm/common/url/encode.test.js +70 -0
- package/dist/esm/common/url/location.js +4 -0
- package/dist/esm/common/url/location.test.js +11 -0
- package/dist/esm/common/url/parse-url.test.js +107 -0
- package/dist/esm/common/url/protocol.js +3 -12
- package/dist/esm/common/url/protocol.test.js +14 -0
- package/dist/esm/common/util/console.js +2 -2
- package/dist/esm/common/util/map-own.js +19 -13
- package/dist/esm/common/util/map-own.test.js +47 -0
- package/dist/esm/common/util/obfuscate.js +2 -2
- package/dist/esm/common/util/submit-data.js +11 -3
- package/dist/esm/common/window/page-visibility.js +4 -2
- package/dist/esm/common/window/session-storage.js +54 -13
- package/dist/esm/common/wrap/index.js +3 -3
- package/dist/esm/common/wrap/wrap-events.js +11 -11
- package/dist/esm/common/wrap/wrap-fetch.js +7 -9
- package/dist/esm/common/wrap/wrap-function.js +4 -17
- package/dist/esm/common/wrap/wrap-history.js +8 -7
- package/dist/esm/common/wrap/wrap-jsonp.js +8 -7
- package/dist/esm/common/wrap/wrap-mutation.js +7 -6
- package/dist/esm/common/wrap/wrap-promise.js +11 -7
- package/dist/esm/common/wrap/wrap-promise.test.js +115 -0
- package/dist/esm/common/wrap/wrap-raf.js +7 -7
- package/dist/esm/common/wrap/wrap-timer.js +7 -7
- package/dist/esm/common/wrap/wrap-xhr.js +7 -8
- package/dist/esm/features/ajax/aggregate/index.js +1 -1
- package/dist/esm/features/ajax/instrument/index.js +2 -1
- package/dist/esm/features/jserrors/aggregate/canonical-function-name.test.js +5 -4
- package/dist/esm/features/jserrors/aggregate/compute-stack-trace.js +1 -2
- package/dist/esm/features/jserrors/aggregate/compute-stack-trace.test.js +5 -5
- package/dist/esm/features/jserrors/aggregate/format-stack-trace.test.js +6 -5
- package/dist/esm/features/jserrors/aggregate/index.js +35 -14
- package/dist/esm/features/jserrors/aggregate/string-hash-code.test.js +5 -4
- package/dist/esm/features/jserrors/instrument/index.js +9 -12
- package/dist/esm/features/metrics/aggregate/index.js +17 -7
- package/dist/esm/features/metrics/instrument/index.js +2 -1
- package/dist/esm/features/metrics/instrument/workers-helper.js +9 -6
- package/dist/esm/features/page_action/aggregate/index.js +12 -4
- package/dist/esm/features/page_action/instrument/index.js +2 -1
- package/dist/esm/features/page_view_event/aggregate/index.js +25 -10
- package/dist/esm/features/page_view_event/instrument/index.js +2 -1
- package/dist/esm/features/page_view_timing/aggregate/index.js +90 -61
- package/dist/esm/features/page_view_timing/instrument/index.js +2 -1
- package/dist/esm/features/session_trace/aggregate/index.js +69 -26
- package/dist/esm/features/session_trace/instrument/index.js +2 -1
- package/dist/esm/features/spa/instrument/index.js +2 -1
- package/dist/esm/features/utils/instrument-base.js +3 -2
- package/dist/esm/features/utils/lazy-loader.js +1 -1
- package/dist/esm/index.js +4 -4
- package/dist/esm/loaders/agent.js +3 -2
- package/dist/esm/loaders/api/api.js +85 -21
- package/dist/esm/loaders/api/apiAsync.js +3 -3
- package/dist/esm/loaders/configure/configure.js +14 -8
- package/dist/esm/loaders/features/enabled-features.js +1 -1
- package/dist/esm/loaders/micro-agent.js +18 -13
- package/dist/types/cdn/lite.d.ts +2 -0
- package/dist/types/cdn/lite.d.ts.map +1 -0
- package/dist/types/cdn/polyfills/lite.d.ts +2 -0
- package/dist/types/cdn/polyfills/lite.d.ts.map +1 -0
- package/dist/types/cdn/polyfills/pro.d.ts +2 -0
- package/dist/types/cdn/polyfills/pro.d.ts.map +1 -0
- package/dist/types/cdn/polyfills/spa.d.ts +2 -0
- package/dist/types/cdn/polyfills/spa.d.ts.map +1 -0
- package/dist/types/cdn/polyfills.d.ts +2 -0
- package/dist/types/cdn/polyfills.d.ts.map +1 -0
- package/dist/types/cdn/pro.d.ts +2 -0
- package/dist/types/cdn/pro.d.ts.map +1 -0
- package/dist/types/cdn/spa.d.ts +2 -0
- package/dist/types/cdn/spa.d.ts.map +1 -0
- package/dist/types/cdn/worker.d.ts +2 -0
- package/dist/types/cdn/worker.d.ts.map +1 -0
- package/dist/types/common/aggregate/aggregator.d.ts +11 -0
- package/dist/types/common/aggregate/aggregator.d.ts.map +1 -0
- package/dist/types/common/browser-version/firefox-version.d.ts +2 -0
- package/dist/types/common/browser-version/firefox-version.d.ts.map +1 -0
- package/dist/types/common/browser-version/ios-version.d.ts +3 -0
- package/dist/types/common/browser-version/ios-version.d.ts.map +1 -0
- package/dist/types/common/config/config.d.ts +13 -0
- package/dist/types/common/config/config.d.ts.map +1 -0
- package/dist/types/common/config/state/configurable.d.ts +4 -0
- package/dist/types/common/config/state/configurable.d.ts.map +1 -0
- package/dist/types/common/config/state/info.d.ts +4 -0
- package/dist/types/common/config/state/info.d.ts.map +1 -0
- package/dist/types/common/config/state/init.d.ts +4 -0
- package/dist/types/common/config/state/init.d.ts.map +1 -0
- package/dist/types/common/config/state/loader-config.d.ts +3 -0
- package/dist/types/common/config/state/loader-config.d.ts.map +1 -0
- package/dist/types/common/config/state/originals.d.ts +2 -0
- package/dist/types/common/config/state/originals.d.ts.map +1 -0
- package/dist/types/common/config/state/runtime.d.ts +3 -0
- package/dist/types/common/config/state/runtime.d.ts.map +1 -0
- package/dist/types/common/constants/env.cdn.d.ts +18 -0
- package/dist/types/common/constants/env.cdn.d.ts.map +1 -0
- package/dist/types/common/constants/env.d.ts +13 -0
- package/dist/types/common/constants/env.d.ts.map +1 -0
- package/dist/types/common/constants/env.npm.d.ts +19 -0
- package/dist/types/common/constants/env.npm.d.ts.map +1 -0
- package/dist/types/common/context/shared-context.d.ts +5 -0
- package/dist/types/common/context/shared-context.d.ts.map +1 -0
- package/dist/types/common/deny-list/deny-list.d.ts +12 -0
- package/dist/types/common/deny-list/deny-list.d.ts.map +1 -0
- package/dist/types/common/drain/drain.d.ts +17 -0
- package/dist/types/common/drain/drain.d.ts.map +1 -0
- package/dist/types/common/event-emitter/contextual-ee.d.ts +4 -0
- package/dist/types/common/event-emitter/contextual-ee.d.ts.map +1 -0
- package/dist/types/common/event-emitter/handle.d.ts +3 -0
- package/dist/types/common/event-emitter/handle.d.ts.map +1 -0
- package/dist/types/common/event-emitter/register-handler.d.ts +8 -0
- package/dist/types/common/event-emitter/register-handler.d.ts.map +1 -0
- package/dist/types/common/event-listener/event-listener-opts.d.ts +10 -0
- package/dist/types/common/event-listener/event-listener-opts.d.ts.map +1 -0
- package/dist/types/common/harvest/harvest-scheduler.d.ts +21 -0
- package/dist/types/common/harvest/harvest-scheduler.d.ts.map +1 -0
- package/dist/types/common/harvest/harvest.d.ts +58 -0
- package/dist/types/common/harvest/harvest.d.ts.map +1 -0
- package/dist/types/common/ids/id.d.ts +12 -0
- package/dist/types/common/ids/id.d.ts.map +1 -0
- package/dist/types/common/ids/unique-id.d.ts +28 -0
- package/dist/types/common/ids/unique-id.d.ts.map +1 -0
- package/dist/types/common/metrics/framework-detection.d.ts +2 -0
- package/dist/types/common/metrics/framework-detection.d.ts.map +1 -0
- package/dist/types/common/metrics/paint-metrics.d.ts +2 -0
- package/dist/types/common/metrics/paint-metrics.d.ts.map +1 -0
- package/dist/types/common/serialize/bel-serializer.d.ts +5 -0
- package/dist/types/common/serialize/bel-serializer.d.ts.map +1 -0
- package/dist/types/common/timing/nav-timing.d.ts +4 -0
- package/dist/types/common/timing/nav-timing.d.ts.map +1 -0
- package/dist/types/common/timing/now.d.ts +2 -0
- package/dist/types/common/timing/now.d.ts.map +1 -0
- package/dist/types/common/unload/eol.d.ts +8 -0
- package/dist/types/common/unload/eol.d.ts.map +1 -0
- package/dist/types/common/url/clean-url.d.ts +2 -0
- package/dist/types/common/url/clean-url.d.ts.map +1 -0
- package/dist/types/common/url/encode.d.ts +5 -0
- package/dist/types/common/url/encode.d.ts.map +1 -0
- package/dist/types/common/url/location.d.ts +6 -0
- package/dist/types/common/url/location.d.ts.map +1 -0
- package/dist/types/common/url/parse-url.d.ts +2 -0
- package/dist/types/common/url/parse-url.d.ts.map +1 -0
- package/dist/types/common/url/protocol.d.ts +2 -0
- package/dist/types/common/url/protocol.d.ts.map +1 -0
- package/dist/types/common/util/console.d.ts +8 -0
- package/dist/types/common/util/console.d.ts.map +1 -0
- package/dist/types/common/util/data-size.d.ts +2 -0
- package/dist/types/common/util/data-size.d.ts.map +1 -0
- package/dist/types/common/util/feature-flags.d.ts +3 -0
- package/dist/types/common/util/feature-flags.d.ts.map +1 -0
- package/dist/types/common/util/get-or-set.d.ts +2 -0
- package/dist/types/common/util/get-or-set.d.ts.map +1 -0
- package/dist/types/common/util/global-scope.d.ts +13 -0
- package/dist/types/common/util/global-scope.d.ts.map +1 -0
- package/dist/types/common/util/map-own.d.ts +3 -0
- package/dist/types/common/util/map-own.d.ts.map +1 -0
- package/dist/types/common/util/obfuscate.d.ts +8 -0
- package/dist/types/common/util/obfuscate.d.ts.map +1 -0
- package/dist/types/common/util/s-hash.d.ts +2 -0
- package/dist/types/common/util/s-hash.d.ts.map +1 -0
- package/dist/types/common/util/single.d.ts +2 -0
- package/dist/types/common/util/single.d.ts.map +1 -0
- package/dist/types/common/util/stringify.d.ts +8 -0
- package/dist/types/common/util/stringify.d.ts.map +1 -0
- package/dist/types/common/util/submit-data.d.ts +35 -0
- package/dist/types/common/util/submit-data.d.ts.map +1 -0
- package/dist/types/common/util/traverse.d.ts +2 -0
- package/dist/types/common/util/traverse.d.ts.map +1 -0
- package/dist/types/common/util/user-agent.d.ts +5 -0
- package/dist/types/common/util/user-agent.d.ts.map +1 -0
- package/dist/types/common/window/load.d.ts +3 -0
- package/dist/types/common/window/load.d.ts.map +1 -0
- package/dist/types/common/window/nreum.d.ts +14 -0
- package/dist/types/common/window/nreum.d.ts.map +1 -0
- package/dist/types/common/window/page-visibility.d.ts +7 -0
- package/dist/types/common/window/page-visibility.d.ts.map +1 -0
- package/dist/types/common/window/session-storage.d.ts +18 -0
- package/dist/types/common/window/session-storage.d.ts.map +1 -0
- package/dist/types/common/window/supports-performance-observer.d.ts +2 -0
- package/dist/types/common/window/supports-performance-observer.d.ts.map +1 -0
- package/dist/types/common/wrap/index.d.ts +11 -0
- package/dist/types/common/wrap/index.d.ts.map +1 -0
- package/dist/types/common/wrap/wrap-events.d.ts +17 -0
- package/dist/types/common/wrap/wrap-events.d.ts.map +1 -0
- package/dist/types/common/wrap/wrap-fetch.d.ts +18 -0
- package/dist/types/common/wrap/wrap-fetch.d.ts.map +1 -0
- package/dist/types/common/wrap/wrap-function.d.ts +28 -0
- package/dist/types/common/wrap/wrap-function.d.ts.map +1 -0
- package/dist/types/common/wrap/wrap-history.d.ts +16 -0
- package/dist/types/common/wrap/wrap-history.d.ts.map +1 -0
- package/dist/types/common/wrap/wrap-jsonp.d.ts +16 -0
- package/dist/types/common/wrap/wrap-jsonp.d.ts.map +1 -0
- package/dist/types/common/wrap/wrap-mutation.d.ts +16 -0
- package/dist/types/common/wrap/wrap-mutation.d.ts.map +1 -0
- package/dist/types/common/wrap/wrap-promise.d.ts +17 -0
- package/dist/types/common/wrap/wrap-promise.d.ts.map +1 -0
- package/dist/types/common/wrap/wrap-raf.d.ts +16 -0
- package/dist/types/common/wrap/wrap-raf.d.ts.map +1 -0
- package/dist/types/common/wrap/wrap-timer.d.ts +17 -0
- package/dist/types/common/wrap/wrap-timer.d.ts.map +1 -0
- package/dist/types/common/wrap/wrap-xhr.d.ts +16 -0
- package/dist/types/common/wrap/wrap-xhr.d.ts.map +1 -0
- package/dist/types/features/ajax/aggregate/index.d.ts +16 -0
- package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -0
- package/dist/types/features/ajax/constants.d.ts +2 -0
- package/dist/types/features/ajax/constants.d.ts.map +1 -0
- package/dist/types/features/ajax/index.d.ts +2 -0
- package/dist/types/features/ajax/index.d.ts.map +1 -0
- package/dist/types/features/ajax/instrument/distributed-tracing.d.ts +19 -0
- package/dist/types/features/ajax/instrument/distributed-tracing.d.ts.map +1 -0
- package/dist/types/features/ajax/instrument/index.d.ts +9 -0
- package/dist/types/features/ajax/instrument/index.d.ts.map +1 -0
- package/dist/types/features/ajax/instrument/response-size.d.ts +2 -0
- package/dist/types/features/ajax/instrument/response-size.d.ts.map +1 -0
- package/dist/types/features/jserrors/aggregate/canonical-function-name.d.ts +2 -0
- package/dist/types/features/jserrors/aggregate/canonical-function-name.d.ts.map +1 -0
- package/dist/types/features/jserrors/aggregate/compute-stack-trace.d.ts +22 -0
- package/dist/types/features/jserrors/aggregate/compute-stack-trace.d.ts.map +1 -0
- package/dist/types/features/jserrors/aggregate/format-stack-trace.d.ts +3 -0
- package/dist/types/features/jserrors/aggregate/format-stack-trace.d.ts.map +1 -0
- package/dist/types/features/jserrors/aggregate/index.d.ts +24 -0
- package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -0
- package/dist/types/features/jserrors/aggregate/string-hash-code.d.ts +2 -0
- package/dist/types/features/jserrors/aggregate/string-hash-code.d.ts.map +1 -0
- package/dist/types/features/jserrors/constants.d.ts +3 -0
- package/dist/types/features/jserrors/constants.d.ts.map +1 -0
- package/dist/types/features/jserrors/index.d.ts +2 -0
- package/dist/types/features/jserrors/index.d.ts.map +1 -0
- package/dist/types/features/jserrors/instrument/debug.d.ts +2 -0
- package/dist/types/features/jserrors/instrument/debug.d.ts.map +1 -0
- package/dist/types/features/jserrors/instrument/index.d.ts +22 -0
- package/dist/types/features/jserrors/instrument/index.d.ts.map +1 -0
- package/dist/types/features/metrics/aggregate/index.d.ts +12 -0
- package/dist/types/features/metrics/aggregate/index.d.ts.map +1 -0
- package/dist/types/features/metrics/constants.d.ts +6 -0
- package/dist/types/features/metrics/constants.d.ts.map +1 -0
- package/dist/types/features/metrics/index.d.ts +2 -0
- package/dist/types/features/metrics/index.d.ts.map +1 -0
- package/dist/types/features/metrics/instrument/index.d.ts +6 -0
- package/dist/types/features/metrics/instrument/index.d.ts.map +1 -0
- package/dist/types/features/metrics/instrument/workers-helper.d.ts +7 -0
- package/dist/types/features/metrics/instrument/workers-helper.d.ts.map +1 -0
- package/dist/types/features/page_action/aggregate/index.d.ts +24 -0
- package/dist/types/features/page_action/aggregate/index.d.ts.map +1 -0
- package/dist/types/features/page_action/constants.d.ts +2 -0
- package/dist/types/features/page_action/constants.d.ts.map +1 -0
- package/dist/types/features/page_action/index.d.ts +2 -0
- package/dist/types/features/page_action/index.d.ts.map +1 -0
- package/dist/types/features/page_action/instrument/index.d.ts +6 -0
- package/dist/types/features/page_action/instrument/index.d.ts.map +1 -0
- package/dist/types/features/page_view_event/aggregate/index.d.ts +9 -0
- package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -0
- package/dist/types/features/page_view_event/aggregate/initialized-features.d.ts +8 -0
- package/dist/types/features/page_view_event/aggregate/initialized-features.d.ts.map +1 -0
- package/dist/types/features/page_view_event/constants.d.ts +5 -0
- package/dist/types/features/page_view_event/constants.d.ts.map +1 -0
- package/dist/types/features/page_view_event/index.d.ts +2 -0
- package/dist/types/features/page_view_event/index.d.ts.map +1 -0
- package/dist/types/features/page_view_event/instrument/index.d.ts +6 -0
- package/dist/types/features/page_view_event/instrument/index.d.ts.map +1 -0
- package/dist/types/features/page_view_timing/aggregate/index.d.ts +32 -0
- package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -0
- package/dist/types/features/page_view_timing/constants.d.ts +2 -0
- package/dist/types/features/page_view_timing/constants.d.ts.map +1 -0
- package/dist/types/features/page_view_timing/first-paint.d.ts +2 -0
- package/dist/types/features/page_view_timing/first-paint.d.ts.map +1 -0
- package/dist/types/features/page_view_timing/index.d.ts +2 -0
- package/dist/types/features/page_view_timing/index.d.ts.map +1 -0
- package/dist/types/features/page_view_timing/instrument/index.d.ts +6 -0
- package/dist/types/features/page_view_timing/instrument/index.d.ts.map +1 -0
- package/dist/types/features/page_view_timing/long-tasks.d.ts +2 -0
- package/dist/types/features/page_view_timing/long-tasks.d.ts.map +1 -0
- package/dist/types/features/session_trace/aggregate/index.d.ts +77 -0
- package/dist/types/features/session_trace/aggregate/index.d.ts.map +1 -0
- package/dist/types/features/session_trace/constants.d.ts +13 -0
- package/dist/types/features/session_trace/constants.d.ts.map +1 -0
- package/dist/types/features/session_trace/index.d.ts +2 -0
- package/dist/types/features/session_trace/index.d.ts.map +1 -0
- package/dist/types/features/session_trace/instrument/index.d.ts +11 -0
- package/dist/types/features/session_trace/instrument/index.d.ts.map +1 -0
- package/dist/types/features/spa/aggregate/index.d.ts +25 -0
- package/dist/types/features/spa/aggregate/index.d.ts.map +1 -0
- package/dist/types/features/spa/aggregate/interaction-node.d.ts +15 -0
- package/dist/types/features/spa/aggregate/interaction-node.d.ts.map +1 -0
- package/dist/types/features/spa/aggregate/interaction.d.ts +20 -0
- package/dist/types/features/spa/aggregate/interaction.d.ts.map +1 -0
- package/dist/types/features/spa/aggregate/serializer.d.ts +15 -0
- package/dist/types/features/spa/aggregate/serializer.d.ts.map +1 -0
- package/dist/types/features/spa/constants.d.ts +23 -0
- package/dist/types/features/spa/constants.d.ts.map +1 -0
- package/dist/types/features/spa/index.d.ts +2 -0
- package/dist/types/features/spa/index.d.ts.map +1 -0
- package/dist/types/features/spa/instrument/index.d.ts +8 -0
- package/dist/types/features/spa/instrument/index.d.ts.map +1 -0
- package/dist/types/features/utils/aggregate-base.d.ts +4 -0
- package/dist/types/features/utils/aggregate-base.d.ts.map +1 -0
- package/dist/types/features/utils/feature-base.d.ts +23 -0
- package/dist/types/features/utils/feature-base.d.ts.map +1 -0
- package/dist/types/features/utils/handler-cache.d.ts +22 -0
- package/dist/types/features/utils/handler-cache.d.ts.map +1 -0
- package/dist/types/features/utils/instrument-base.d.ts +27 -0
- package/dist/types/features/utils/instrument-base.d.ts.map +1 -0
- package/dist/types/features/utils/lazy-loader.d.ts +13 -0
- package/dist/types/features/utils/lazy-loader.d.ts.map +1 -0
- package/dist/types/index.d.ts +12 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/loaders/agent.d.ts +20 -0
- package/dist/types/loaders/agent.d.ts.map +1 -0
- package/dist/types/loaders/api/api.d.ts +17 -0
- package/dist/types/loaders/api/api.d.ts.map +1 -0
- package/dist/types/loaders/api/apiAsync.d.ts +2 -0
- package/dist/types/loaders/api/apiAsync.d.ts.map +1 -0
- package/dist/types/loaders/browser-agent.d.ts +9 -0
- package/dist/types/loaders/browser-agent.d.ts.map +1 -0
- package/dist/types/loaders/configure/configure.d.ts +10 -0
- package/dist/types/loaders/configure/configure.d.ts.map +1 -0
- package/dist/types/loaders/features/enabled-features.d.ts +2 -0
- package/dist/types/loaders/features/enabled-features.d.ts.map +1 -0
- package/dist/types/loaders/features/featureDependencies.d.ts +3 -0
- package/dist/types/loaders/features/featureDependencies.d.ts.map +1 -0
- package/dist/types/loaders/features/features.d.ts +18 -0
- package/dist/types/loaders/features/features.d.ts.map +1 -0
- package/dist/types/loaders/micro-agent.d.ts +25 -0
- package/dist/types/loaders/micro-agent.d.ts.map +1 -0
- package/dist/types/loaders/worker-agent.d.ts +8 -0
- package/dist/types/loaders/worker-agent.d.ts.map +1 -0
- package/package.json +67 -59
- package/src/cdn/lite.js +18 -0
- package/src/cdn/polyfills/lite.js +7 -0
- package/src/cdn/polyfills/pro.js +7 -0
- package/src/cdn/polyfills/spa.js +7 -0
- package/src/cdn/polyfills.js +17 -0
- package/src/cdn/pro.js +27 -0
- package/src/cdn/spa.js +28 -0
- package/src/cdn/worker.js +21 -0
- package/src/common/aggregate/aggregator.js +171 -0
- package/src/common/browser-version/firefox-version.js +10 -0
- package/src/common/browser-version/ios-version.js +11 -0
- package/src/common/config/config.js +12 -0
- package/src/common/config/state/configurable.js +26 -0
- package/src/common/config/state/info.js +49 -0
- package/src/common/config/state/init.js +56 -0
- package/src/common/config/state/loader-config.js +25 -0
- package/src/common/config/state/originals.js +3 -0
- package/src/common/config/state/runtime.js +47 -0
- package/src/common/constants/env.cdn.js +20 -0
- package/src/common/constants/env.js +23 -0
- package/src/common/constants/env.npm.js +21 -0
- package/src/common/context/shared-context.js +21 -0
- package/src/common/deny-list/deny-list.js +116 -0
- package/src/common/drain/drain.js +119 -0
- package/src/common/event-emitter/contextual-ee.js +159 -0
- package/src/common/event-emitter/contextual-ee.test.js +310 -0
- package/src/common/event-emitter/handle.js +17 -0
- package/src/common/event-emitter/handle.test.js +56 -0
- package/src/common/event-emitter/register-handler.js +25 -0
- package/src/common/event-emitter/register-handler.test.js +61 -0
- package/src/common/event-listener/event-listener-opts.js +41 -0
- package/src/common/harvest/harvest-scheduler.js +112 -0
- package/src/common/harvest/harvest.js +248 -0
- package/src/common/ids/id.js +32 -0
- package/src/common/ids/id.test.js +92 -0
- package/src/common/ids/unique-id.js +104 -0
- package/src/common/ids/unique-id.test.js +58 -0
- package/src/common/metrics/framework-detection.js +71 -0
- package/src/common/metrics/paint-metrics.js +6 -0
- package/src/common/serialize/bel-serializer.js +93 -0
- package/src/common/timing/nav-timing.js +90 -0
- package/src/common/timing/nav-timing.test.js +161 -0
- package/src/common/timing/now.js +9 -0
- package/src/common/unload/eol.js +62 -0
- package/src/common/url/clean-url.js +10 -0
- package/src/common/url/clean-url.test.js +25 -0
- package/src/common/url/encode.js +75 -0
- package/src/common/url/encode.test.js +80 -0
- package/src/common/url/location.js +12 -0
- package/src/common/url/location.test.js +15 -0
- package/src/common/url/parse-url.js +70 -0
- package/src/common/url/parse-url.test.js +110 -0
- package/src/common/url/protocol.js +9 -0
- package/src/common/url/protocol.test.js +18 -0
- package/src/common/util/console.js +11 -0
- package/src/common/util/data-size.js +21 -0
- package/src/common/util/feature-flags.js +38 -0
- package/src/common/util/get-or-set.js +34 -0
- package/src/common/util/global-scope.js +47 -0
- package/src/common/util/map-own.js +22 -0
- package/src/common/util/map-own.test.js +52 -0
- package/src/common/util/obfuscate.js +73 -0
- package/src/common/util/s-hash.js +14 -0
- package/src/common/util/single.js +18 -0
- package/src/common/util/stringify.js +42 -0
- package/src/common/util/submit-data.js +101 -0
- package/src/common/util/traverse.js +36 -0
- package/src/common/util/user-agent.js +56 -0
- package/src/common/window/load.js +15 -0
- package/src/common/window/nreum.js +110 -0
- package/src/common/window/page-visibility.js +24 -0
- package/src/common/window/session-storage.js +75 -0
- package/src/common/window/supports-performance-observer.js +10 -0
- package/src/common/wrap/index.js +17 -0
- package/src/common/wrap/wrap-events.js +106 -0
- package/src/common/wrap/wrap-fetch.js +110 -0
- package/src/common/wrap/wrap-function.js +248 -0
- package/src/common/wrap/wrap-history.js +51 -0
- package/src/common/wrap/wrap-jsonp.js +136 -0
- package/src/common/wrap/wrap-mutation.js +58 -0
- package/src/common/wrap/wrap-promise.js +166 -0
- package/src/common/wrap/wrap-promise.test.js +140 -0
- package/src/common/wrap/wrap-raf.js +52 -0
- package/src/common/wrap/wrap-timer.js +69 -0
- package/src/common/wrap/wrap-xhr.js +214 -0
- package/src/features/ajax/aggregate/index.js +248 -0
- package/src/features/ajax/constants.js +3 -0
- package/src/features/ajax/index.js +1 -0
- package/src/features/ajax/instrument/distributed-tracing.js +166 -0
- package/src/features/ajax/instrument/index.js +380 -0
- package/src/features/ajax/instrument/response-size.js +18 -0
- package/src/features/jserrors/aggregate/canonical-function-name.js +14 -0
- package/src/features/jserrors/aggregate/canonical-function-name.test.js +13 -0
- package/src/features/jserrors/aggregate/compute-stack-trace.js +231 -0
- package/src/features/jserrors/aggregate/compute-stack-trace.test.js +297 -0
- package/src/features/jserrors/aggregate/format-stack-trace.js +30 -0
- package/src/features/jserrors/aggregate/format-stack-trace.test.js +39 -0
- package/src/features/jserrors/aggregate/index.js +310 -0
- package/src/features/jserrors/aggregate/string-hash-code.js +17 -0
- package/src/features/jserrors/aggregate/string-hash-code.test.js +12 -0
- package/src/features/jserrors/constants.js +4 -0
- package/src/features/jserrors/index.js +1 -0
- package/src/features/jserrors/instrument/debug.js +36 -0
- package/src/features/jserrors/instrument/index.js +151 -0
- package/src/features/metrics/aggregate/index.js +133 -0
- package/src/features/metrics/constants.js +7 -0
- package/src/features/metrics/index.js +1 -0
- package/src/features/metrics/instrument/index.js +14 -0
- package/src/features/metrics/instrument/workers-helper.js +113 -0
- package/src/features/page_action/aggregate/index.js +113 -0
- package/src/features/page_action/constants.js +3 -0
- package/src/features/page_action/index.js +1 -0
- package/src/features/page_action/instrument/index.js +15 -0
- package/src/features/page_view_event/aggregate/index.js +143 -0
- package/src/features/page_view_event/aggregate/initialized-features.js +31 -0
- package/src/features/page_view_event/constants.js +6 -0
- package/src/features/page_view_event/index.js +1 -0
- package/src/features/page_view_event/instrument/index.js +33 -0
- package/src/features/page_view_timing/aggregate/index.js +257 -0
- package/src/features/page_view_timing/constants.js +3 -0
- package/src/features/page_view_timing/first-paint.js +41 -0
- package/src/features/page_view_timing/index.js +1 -0
- package/src/features/page_view_timing/instrument/index.js +30 -0
- package/src/features/page_view_timing/long-tasks.js +60 -0
- package/src/features/session_trace/aggregate/index.js +413 -0
- package/src/features/session_trace/constants.js +15 -0
- package/src/features/session_trace/index.js +1 -0
- package/src/features/session_trace/instrument/index.js +127 -0
- package/src/features/spa/aggregate/index.js +738 -0
- package/src/features/spa/aggregate/interaction-node.js +85 -0
- package/src/features/spa/aggregate/interaction-node.test.js +17 -0
- package/src/features/spa/aggregate/interaction.js +112 -0
- package/src/features/spa/aggregate/serializer.js +198 -0
- package/src/features/spa/constants.js +36 -0
- package/src/features/spa/index.js +1 -0
- package/src/features/spa/instrument/index.js +114 -0
- package/src/features/utils/aggregate-base.js +7 -0
- package/src/features/utils/feature-base.js +51 -0
- package/src/features/utils/handler-cache.js +60 -0
- package/src/features/utils/instrument-base.js +68 -0
- package/src/features/utils/lazy-loader.js +37 -0
- package/src/index.js +15 -0
- package/src/loaders/agent.js +80 -0
- package/src/loaders/api/api.js +175 -0
- package/src/loaders/api/apiAsync.js +92 -0
- package/src/loaders/browser-agent.js +33 -0
- package/src/loaders/configure/configure.js +39 -0
- package/src/loaders/features/enabled-features.js +16 -0
- package/src/loaders/features/featureDependencies.js +26 -0
- package/src/loaders/features/features.js +25 -0
- package/src/loaders/micro-agent.js +84 -0
- package/src/loaders/worker-agent.js +24 -0
- package/dist/cjs/common/constants/environment-variables.js +0 -20
- package/dist/cjs/common/util/reduce.js +0 -22
- package/dist/cjs/common/window/top-level-callers.js +0 -23
- package/dist/esm/common/constants/environment-variables.js +0 -11
- package/dist/esm/common/util/reduce.js +0 -16
- package/dist/esm/common/window/top-level-callers.js +0 -17
- package/types.ts +0 -221
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { handle } from '../../../common/event-emitter/handle'
|
|
2
|
+
import { FEATURE_NAMES } from '../../../loaders/features/features'
|
|
3
|
+
import { isiOS } from '../../../common/browser-version/ios-version'
|
|
4
|
+
import { onTTFB } from 'web-vitals'
|
|
5
|
+
import { mapOwn } from '../../../common/util/map-own'
|
|
6
|
+
import { param, fromArray } from '../../../common/url/encode'
|
|
7
|
+
import { addPT, addPN } from '../../../common/timing/nav-timing'
|
|
8
|
+
import { stringify } from '../../../common/util/stringify'
|
|
9
|
+
import { paintMetrics } from '../../../common/metrics/paint-metrics'
|
|
10
|
+
import { submitData } from '../../../common/util/submit-data'
|
|
11
|
+
import { getConfigurationValue, getInfo, getRuntime } from '../../../common/config/config'
|
|
12
|
+
import { HarvestScheduler } from '../../../common/harvest/harvest-scheduler'
|
|
13
|
+
import { AggregateBase } from '../../utils/aggregate-base'
|
|
14
|
+
import * as CONSTANTS from '../constants'
|
|
15
|
+
import { getActivatedFeaturesFlags } from './initialized-features'
|
|
16
|
+
import { globalScope, isBrowserScope } from '../../../common/util/global-scope'
|
|
17
|
+
import { drain } from '../../../common/drain/drain'
|
|
18
|
+
|
|
19
|
+
const jsonp = 'NREUM.setToken'
|
|
20
|
+
|
|
21
|
+
export class Aggregate extends AggregateBase {
|
|
22
|
+
static featureName = CONSTANTS.FEATURE_NAME
|
|
23
|
+
constructor (agentIdentifier, aggregator) {
|
|
24
|
+
super(agentIdentifier, aggregator, CONSTANTS.FEATURE_NAME)
|
|
25
|
+
|
|
26
|
+
if (typeof PerformanceNavigationTiming !== 'undefined' && !isiOS) {
|
|
27
|
+
this.alreadySent = false // we don't support timings on BFCache restores
|
|
28
|
+
const agentRuntime = getRuntime(agentIdentifier) // we'll store timing values on the runtime obj to be read by the aggregate module
|
|
29
|
+
|
|
30
|
+
/* Time To First Byte
|
|
31
|
+
This listener must record these values *before* PVE's aggregate sends RUM. */
|
|
32
|
+
onTTFB(({ value, entries }) => {
|
|
33
|
+
if (this.alreadySent) return
|
|
34
|
+
this.alreadySent = true
|
|
35
|
+
|
|
36
|
+
agentRuntime[CONSTANTS.TTFB] = Math.round(value) // this is our "backend" duration; web-vitals will ensure it's lower bounded at 0
|
|
37
|
+
|
|
38
|
+
// Similar to what vitals does for ttfb, we have to factor in activation-start when calculating relative timings:
|
|
39
|
+
const navEntry = entries[0]
|
|
40
|
+
const respOrActivStart = Math.max(navEntry.responseStart, navEntry.activationStart || 0)
|
|
41
|
+
agentRuntime[CONSTANTS.FBTWL] = Math.max(Math.round(navEntry.loadEventEnd - respOrActivStart), 0) // our "frontend" duration
|
|
42
|
+
handle('timing', ['load', Math.round(navEntry.loadEventEnd)], undefined, FEATURE_NAMES.pageViewTiming, this.ee)
|
|
43
|
+
agentRuntime[CONSTANTS.FBTDC] = Math.max(Math.round(navEntry.domContentLoadedEventEnd - respOrActivStart), 0) // our "dom processing" duration
|
|
44
|
+
|
|
45
|
+
this.sendRum()
|
|
46
|
+
})
|
|
47
|
+
} else {
|
|
48
|
+
this.sendRum() // timings either already in runtime from instrument or is meant to get 0'd.
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
getScheme () {
|
|
53
|
+
return getConfigurationValue(this.agentIdentifier, 'ssl') === false ? 'http' : 'https'
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
sendRum () {
|
|
57
|
+
const info = getInfo(this.agentIdentifier)
|
|
58
|
+
if (!info.beacon) return
|
|
59
|
+
if (info.queueTime) this.aggregator.store('measures', 'qt', { value: info.queueTime })
|
|
60
|
+
if (info.applicationTime) this.aggregator.store('measures', 'ap', { value: info.applicationTime })
|
|
61
|
+
const agentRuntime = getRuntime(this.agentIdentifier)
|
|
62
|
+
|
|
63
|
+
// These 3 values should've been recorded after load and before this func runs. They are part of the minimum required for PageView events to be created.
|
|
64
|
+
// Following PR #428, which demands that all agents send RUM call, these need to be sent even outside of the main window context where PerformanceTiming
|
|
65
|
+
// or PerformanceNavigationTiming do not exists. Hence, they'll be filled in by 0s instead in, for example, worker threads that still init the PVE module.
|
|
66
|
+
this.aggregator.store('measures', 'be', { value: isBrowserScope ? agentRuntime[CONSTANTS.TTFB] : 0 })
|
|
67
|
+
this.aggregator.store('measures', 'fe', { value: isBrowserScope ? agentRuntime[CONSTANTS.FBTWL] : 0 })
|
|
68
|
+
this.aggregator.store('measures', 'dc', { value: isBrowserScope ? agentRuntime[CONSTANTS.FBTDC] : 0 })
|
|
69
|
+
|
|
70
|
+
var measuresMetrics = this.aggregator.get('measures')
|
|
71
|
+
|
|
72
|
+
var measuresQueryString = mapOwn(measuresMetrics, function (metricName, measure) {
|
|
73
|
+
return '&' + metricName + '=' + measure.params.value
|
|
74
|
+
}).join('')
|
|
75
|
+
|
|
76
|
+
// currently we only have one version of our protocol
|
|
77
|
+
// in the future we may add more
|
|
78
|
+
var protocol = '1'
|
|
79
|
+
|
|
80
|
+
var scheduler = new HarvestScheduler('page_view_event', {}, this)
|
|
81
|
+
|
|
82
|
+
var chunksForQueryString = [scheduler.harvest.baseQueryString()]
|
|
83
|
+
|
|
84
|
+
chunksForQueryString.push(measuresQueryString)
|
|
85
|
+
|
|
86
|
+
chunksForQueryString.push(param('tt', info.ttGuid))
|
|
87
|
+
chunksForQueryString.push(param('us', info.user))
|
|
88
|
+
chunksForQueryString.push(param('ac', info.account))
|
|
89
|
+
chunksForQueryString.push(param('pr', info.product))
|
|
90
|
+
chunksForQueryString.push(param('af', getActivatedFeaturesFlags(this.agentIdentifier).join(',')))
|
|
91
|
+
|
|
92
|
+
if (globalScope.performance) {
|
|
93
|
+
if (typeof PerformanceNavigationTiming !== 'undefined') { // Navigation Timing level 2 API that replaced PerformanceTiming & PerformanceNavigation
|
|
94
|
+
const navTimingEntry = globalScope?.performance?.getEntriesByType('navigation')?.[0]
|
|
95
|
+
const perf = ({
|
|
96
|
+
timing: addPT(agentRuntime.offset, navTimingEntry, {}),
|
|
97
|
+
navigation: addPN(navTimingEntry, {})
|
|
98
|
+
})
|
|
99
|
+
chunksForQueryString.push(param('perf', stringify(perf)))
|
|
100
|
+
} else if (typeof PerformanceTiming !== 'undefined') { // Safari pre-15 did not support level 2 timing
|
|
101
|
+
const perf = ({
|
|
102
|
+
timing: addPT(agentRuntime.offset, globalScope.performance.timing, {}, true),
|
|
103
|
+
navigation: addPN(globalScope.performance.navigation, {})
|
|
104
|
+
})
|
|
105
|
+
chunksForQueryString.push(param('perf', stringify(perf)))
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
try { // PVTiming sends these too, albeit using web-vitals and slightly different; it's unknown why they're duplicated, but PVT should be the truth
|
|
110
|
+
var entries = globalScope.performance.getEntriesByType('paint')
|
|
111
|
+
entries.forEach(function (entry) {
|
|
112
|
+
if (!entry.startTime || entry.startTime <= 0) return
|
|
113
|
+
|
|
114
|
+
if (entry.name === 'first-paint') {
|
|
115
|
+
chunksForQueryString.push(param('fp', String(Math.floor(entry.startTime))))
|
|
116
|
+
} else if (entry.name === 'first-contentful-paint') {
|
|
117
|
+
chunksForQueryString.push(param('fcp', String(Math.floor(entry.startTime))))
|
|
118
|
+
}
|
|
119
|
+
paintMetrics[entry.name] = Math.floor(entry.startTime) // this is consumed by Spa module
|
|
120
|
+
})
|
|
121
|
+
} catch (e) {}
|
|
122
|
+
|
|
123
|
+
chunksForQueryString.push(param('xx', info.extra))
|
|
124
|
+
chunksForQueryString.push(param('ua', info.userAttributes))
|
|
125
|
+
chunksForQueryString.push(param('at', info.atts))
|
|
126
|
+
|
|
127
|
+
var customJsAttributes = stringify(info.jsAttributes)
|
|
128
|
+
chunksForQueryString.push(param('ja', customJsAttributes === '{}' ? null : customJsAttributes))
|
|
129
|
+
|
|
130
|
+
var queryString = fromArray(chunksForQueryString, agentRuntime.maxBytes)
|
|
131
|
+
|
|
132
|
+
// Capture bytes sent to RUM call endpoint (currently `1`) as a supportability metric. See metrics aggregator (on unload).
|
|
133
|
+
agentRuntime.bytesSent[protocol] = (agentRuntime.bytesSent[protocol] || 0) + queryString?.length || 0
|
|
134
|
+
|
|
135
|
+
const isValidJsonp = submitData.jsonp(
|
|
136
|
+
this.getScheme() + '://' + info.beacon + '/' + protocol + '/' + info.licenseKey + queryString,
|
|
137
|
+
jsonp
|
|
138
|
+
)
|
|
139
|
+
// Usually `drain` is invoked automatically after processing feature flags contained in the JSONP callback from
|
|
140
|
+
// ingest (see `activateFeatures`), so when JSONP cannot execute (as with module workers), we drain manually.
|
|
141
|
+
if (!isValidJsonp) drain(this.agentIdentifier, CONSTANTS.FEATURE_NAME)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { FEATURE_NAMES } from '../../../loaders/features/features'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Get an array of flags required by downstream (NR UI) based on the features initialized in this agent
|
|
5
|
+
* (aka what is running on the page).
|
|
6
|
+
* @param {String} agentId - the ID of the initialized agent on the page, mapping to the one under the global 'newrelic' object
|
|
7
|
+
* @returns {String[]} Up to 5 short strings corresponding to ingest mapping of features.
|
|
8
|
+
*/
|
|
9
|
+
export function getActivatedFeaturesFlags (agentId) {
|
|
10
|
+
const flagArr = []
|
|
11
|
+
|
|
12
|
+
Object.keys(newrelic.initializedAgents[agentId].features).forEach(featName => {
|
|
13
|
+
switch (featName) {
|
|
14
|
+
case FEATURE_NAMES.ajax:
|
|
15
|
+
flagArr.push('xhr'); break
|
|
16
|
+
case FEATURE_NAMES.jserrors:
|
|
17
|
+
flagArr.push('err'); break
|
|
18
|
+
case FEATURE_NAMES.pageAction:
|
|
19
|
+
flagArr.push('ins'); break
|
|
20
|
+
case FEATURE_NAMES.sessionTrace:
|
|
21
|
+
flagArr.push('stn'); break
|
|
22
|
+
case FEATURE_NAMES.spa:
|
|
23
|
+
flagArr.push('spa'); break
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
return flagArr
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Note: this module and the "af" param in src/features/page_view_event/aggregate/index.js can be removed in the future at such time
|
|
31
|
+
// that it's no longer being used. For the browser agent, this is an unused flag system.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Instrument as PageViewEvent } from './instrument/index'
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
|
|
2
|
+
import { handle } from '../../../common/event-emitter/handle'
|
|
3
|
+
import { isiOS } from '../../../common/browser-version/ios-version'
|
|
4
|
+
import { InstrumentBase } from '../../utils/instrument-base'
|
|
5
|
+
import * as CONSTANTS from '../constants'
|
|
6
|
+
import { FEATURE_NAMES } from '../../../loaders/features/features'
|
|
7
|
+
import { getRuntime } from '../../../common/config/config'
|
|
8
|
+
import { onDOMContentLoaded, onWindowLoad } from '../../../common/window/load'
|
|
9
|
+
import { now } from '../../../common/timing/now'
|
|
10
|
+
|
|
11
|
+
export class Instrument extends InstrumentBase {
|
|
12
|
+
static featureName = CONSTANTS.FEATURE_NAME
|
|
13
|
+
constructor (agentIdentifier, aggregator, auto = true) {
|
|
14
|
+
super(agentIdentifier, aggregator, CONSTANTS.FEATURE_NAME, auto)
|
|
15
|
+
|
|
16
|
+
if ((typeof PerformanceNavigationTiming === 'undefined' || isiOS) && typeof PerformanceTiming !== 'undefined') {
|
|
17
|
+
// For majority browser versions in which PNT exists, we can get load timings later from the nav entry (in the aggregate portion). At minimum, PT should exist for main window.
|
|
18
|
+
// *cli Mar'23 - iOS 15.2 & 15.4 testing in Sauce still fails with onTTFB. Hence, all iOS will fallback to this for now. Unknown if this is similar in nature to iOS_below16 bug.
|
|
19
|
+
const agentRuntime = getRuntime(agentIdentifier)
|
|
20
|
+
|
|
21
|
+
agentRuntime[CONSTANTS.TTFB] = Math.max(Date.now() - agentRuntime.offset, 0)
|
|
22
|
+
onDOMContentLoaded(() => agentRuntime[CONSTANTS.FBTDC] = Math.max(now() - agentRuntime[CONSTANTS.TTFB], 0))
|
|
23
|
+
onWindowLoad(() => {
|
|
24
|
+
const timeNow = now()
|
|
25
|
+
agentRuntime[CONSTANTS.FBTWL] = Math.max(timeNow - agentRuntime[CONSTANTS.TTFB], 0)
|
|
26
|
+
handle('timing', ['load', timeNow], undefined, FEATURE_NAMES.pageViewTiming, this.ee)
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
// Else, inference: inside worker or some other env where these events are irrelevant. They'll get filled in with 0s in RUM call.
|
|
30
|
+
|
|
31
|
+
this.importAggregator()
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,257 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { onFCP, onFID, onLCP, onCLS, onINP } from 'web-vitals'
|
|
7
|
+
import { onFirstPaint } from '../first-paint'
|
|
8
|
+
import { onLongTask } from '../long-tasks'
|
|
9
|
+
import { iOS_below16 } from '../../../common/browser-version/ios-version'
|
|
10
|
+
import { nullable, numeric, getAddStringContext, addCustomAttributes } from '../../../common/serialize/bel-serializer'
|
|
11
|
+
import { mapOwn } from '../../../common/util/map-own'
|
|
12
|
+
import { HarvestScheduler } from '../../../common/harvest/harvest-scheduler'
|
|
13
|
+
import { registerHandler } from '../../../common/event-emitter/register-handler'
|
|
14
|
+
import { cleanURL } from '../../../common/url/clean-url'
|
|
15
|
+
import { handle } from '../../../common/event-emitter/handle'
|
|
16
|
+
import { getInfo, getConfigurationValue, getRuntime } from '../../../common/config/config'
|
|
17
|
+
import { AggregateBase } from '../../utils/aggregate-base'
|
|
18
|
+
import { FEATURE_NAME } from '../constants'
|
|
19
|
+
import { drain } from '../../../common/drain/drain'
|
|
20
|
+
import { FEATURE_NAMES } from '../../../loaders/features/features'
|
|
21
|
+
|
|
22
|
+
export class Aggregate extends AggregateBase {
|
|
23
|
+
static featureName = FEATURE_NAME
|
|
24
|
+
constructor (agentIdentifier, aggregator) {
|
|
25
|
+
super(agentIdentifier, aggregator, FEATURE_NAME)
|
|
26
|
+
|
|
27
|
+
this.timings = []
|
|
28
|
+
this.timingsSent = []
|
|
29
|
+
this.curSessEndRecorded = false
|
|
30
|
+
this.cls = null // this should be null unless set to a numeric value by web-vitals so that we differentiate if CLS is supported
|
|
31
|
+
|
|
32
|
+
/*! This is the section that used to be in the loader portion: !*/
|
|
33
|
+
/* ------------------------------------------------------------ */
|
|
34
|
+
const pageStartedHidden = getRuntime(agentIdentifier).initHidden // our attempt at recapturing initial vis state since this code runs post-load time
|
|
35
|
+
this.alreadySent = new Set() // since we don't support timings on BFCache restores, this tracks and helps cap metrics that web-vitals report more than once
|
|
36
|
+
|
|
37
|
+
/* PerformancePaintTiming API - BFC is not yet supported. */
|
|
38
|
+
onFirstPaint(({ name, value }) => {
|
|
39
|
+
if (pageStartedHidden) return
|
|
40
|
+
this.addTiming(name.toLowerCase(), Math.floor(value))
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
/* First Contentful Paint - As of WV v3, it still imperfectly tries to detect document vis state asap and isn't supposed to report if page starts hidden. */
|
|
44
|
+
if (iOS_below16) {
|
|
45
|
+
try {
|
|
46
|
+
if (!pageStartedHidden) { // see ios-version.js for detail on this following bug case; tldr: buffered flag doesn't work but getEntriesByType does
|
|
47
|
+
const paintEntries = performance.getEntriesByType('paint')
|
|
48
|
+
paintEntries.forEach(entry => {
|
|
49
|
+
if (entry.name === 'first-contentful-paint') {
|
|
50
|
+
this.addTiming('fcp', Math.floor(entry.startTime))
|
|
51
|
+
}
|
|
52
|
+
})
|
|
53
|
+
}
|
|
54
|
+
} catch (e) {}
|
|
55
|
+
} else {
|
|
56
|
+
onFCP(({ name, value }) => {
|
|
57
|
+
if (pageStartedHidden || this.alreadySent.has(name)) return
|
|
58
|
+
this.alreadySent.add(name)
|
|
59
|
+
this.addTiming(name.toLowerCase(), value)
|
|
60
|
+
})
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/* First Input Delay (+"First Interaction") - As of WV v3, it still imperfectly tries to detect document vis state asap and isn't supposed to report if page starts hidden. */
|
|
64
|
+
onFID(({ name, value, entries }) => {
|
|
65
|
+
if (pageStartedHidden || this.alreadySent.has(name) || entries.length === 0) return
|
|
66
|
+
this.alreadySent.add(name)
|
|
67
|
+
|
|
68
|
+
// CWV will only report one (THE) first-input entry to us; fid isn't reported if there are no user interactions occurs before the *first* page hiding.
|
|
69
|
+
const fiEntry = entries[0]
|
|
70
|
+
const attributes = {
|
|
71
|
+
type: fiEntry.name,
|
|
72
|
+
fid: Math.round(value)
|
|
73
|
+
}
|
|
74
|
+
this.addConnectionAttributes(attributes)
|
|
75
|
+
this.addTiming('fi', Math.round(fiEntry.startTime), attributes)
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
/* Largest Contentful Paint - As of WV v3, it still imperfectly tries to detect document vis state asap and isn't supposed to report if page starts hidden. */
|
|
79
|
+
onLCP(({ name, value, entries }) => {
|
|
80
|
+
if (pageStartedHidden || this.alreadySent.has(name)) return
|
|
81
|
+
this.alreadySent.add(name)
|
|
82
|
+
|
|
83
|
+
const attributes = {}
|
|
84
|
+
if (entries.length > 0) {
|
|
85
|
+
// CWV will only ever report one (THE) lcp entry to us; lcp is also only reported *once* on earlier(user interaction, page hidden).
|
|
86
|
+
const lcpEntry = entries[entries.length - 1] // this looks weird if we only expect one, but this is how cwv-attribution gets it so to be sure...
|
|
87
|
+
attributes.size = lcpEntry.size
|
|
88
|
+
attributes.eid = lcpEntry.id
|
|
89
|
+
|
|
90
|
+
if (lcpEntry.url) {
|
|
91
|
+
attributes['elUrl'] = cleanURL(lcpEntry.url)
|
|
92
|
+
}
|
|
93
|
+
if (lcpEntry.element?.tagName) {
|
|
94
|
+
attributes['elTag'] = lcpEntry.element.tagName
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
this.addConnectionAttributes(attributes)
|
|
99
|
+
this.addTiming(name.toLowerCase(), value, attributes)
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
/* Cumulative Layout Shift - We don't have to limit this callback since cls is stored as a state and only sent as attribute on other timings.
|
|
103
|
+
reportAllChanges ensures our tracked cls has the most recent rolling value to attach to 'unload' and 'pagehide'. */
|
|
104
|
+
onCLS(({ value }) => this.cls = value, { reportAllChanges: true })
|
|
105
|
+
|
|
106
|
+
/* Interaction-to-Next-Paint */
|
|
107
|
+
onINP(({ name, value, id }) => this.addTiming(name.toLowerCase(), value, { metricId: id }))
|
|
108
|
+
|
|
109
|
+
/* PerformanceLongTaskTiming API */
|
|
110
|
+
if (getConfigurationValue(this.agentIdentifier, 'page_view_timing.long_task') === true) {
|
|
111
|
+
onLongTask(({ name, value, info }) => this.addTiming(name.toLowerCase(), value, info)) // lt context is passed as 'info'=attrs in the timing node
|
|
112
|
+
}
|
|
113
|
+
/* ------------------------------------End of ex-loader section */
|
|
114
|
+
|
|
115
|
+
/* It's important that CWV api, like "onLCP", is called before this scheduler is initialized. The reason is because they listen to the same
|
|
116
|
+
on vis change or pagehide events, and we'd want ex. onLCP to record the timing (win the race) before we try to send "final harvest". */
|
|
117
|
+
this.scheduler = new HarvestScheduler('events', {
|
|
118
|
+
onFinished: (...args) => this.onHarvestFinished(...args),
|
|
119
|
+
getPayload: (...args) => this.prepareHarvest(...args)
|
|
120
|
+
}, this)
|
|
121
|
+
|
|
122
|
+
registerHandler('timing', (name, value, attrs) => this.addTiming(name, value, attrs), this.featureName, this.ee) // notice CLS is added to all timings via 4th param
|
|
123
|
+
registerHandler('docHidden', msTimestamp => this.endCurrentSession(msTimestamp), this.featureName, this.ee)
|
|
124
|
+
registerHandler('winPagehide', msTimestamp => this.recordPageUnload(msTimestamp), this.featureName, this.ee)
|
|
125
|
+
|
|
126
|
+
const initialHarvestSeconds = getConfigurationValue(this.agentIdentifier, 'page_view_timing.initialHarvestSeconds') || 10
|
|
127
|
+
const harvestTimeSeconds = getConfigurationValue(this.agentIdentifier, 'page_view_timing.harvestTimeSeconds') || 30
|
|
128
|
+
// send initial data sooner, then start regular
|
|
129
|
+
this.ee.on(`drain-${this.featureName}`, () => { this.scheduler.startTimer(harvestTimeSeconds, initialHarvestSeconds) })
|
|
130
|
+
|
|
131
|
+
drain(this.agentIdentifier, this.featureName)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// takes an attributes object and appends connection attributes if available
|
|
135
|
+
addConnectionAttributes (attributes) {
|
|
136
|
+
var connection = navigator.connection || navigator.mozConnection || navigator.webkitConnection // to date, both window & worker shares the same support for connection
|
|
137
|
+
if (!connection) return
|
|
138
|
+
|
|
139
|
+
if (connection.type) attributes['net-type'] = connection.type
|
|
140
|
+
if (connection.effectiveType) attributes['net-etype'] = connection.effectiveType
|
|
141
|
+
if (connection.rtt) attributes['net-rtt'] = connection.rtt
|
|
142
|
+
if (connection.downlink) attributes['net-dlink'] = connection.downlink
|
|
143
|
+
|
|
144
|
+
return attributes
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Add the time of _document visibilitychange to hidden_ to the next PVT harvest == NRDB pageHide attr.
|
|
149
|
+
* @param {number} timestamp
|
|
150
|
+
*/
|
|
151
|
+
endCurrentSession (timestamp) {
|
|
152
|
+
if (!this.curSessEndRecorded) { // TO DO: stage 2 - we don't want to capture this timing twice on page navigating away, but it should run again if we return to page and away *again*
|
|
153
|
+
this.addTiming('pageHide', timestamp, null)
|
|
154
|
+
this.curSessEndRecorded = true
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Add the time of _window pagehide event_ firing to the next PVT harvest == NRDB windowUnload attr.
|
|
160
|
+
*/
|
|
161
|
+
recordPageUnload (timestamp) {
|
|
162
|
+
this.addTiming('unload', timestamp, null)
|
|
163
|
+
/*
|
|
164
|
+
Issue: Because window's pageHide commonly fires BEFORE vis change and "final" harvest would happen at the former in this case, we also have to add our vis-change event now or it may not be sent.
|
|
165
|
+
Affected: Safari < v14.1/.5 ; versions that don't support 'visiilitychange' event
|
|
166
|
+
Impact: For affected w/o this, NR 'pageHide' attribute may not be sent. For other browsers w/o this, NR 'pageHide' gets fragmented into its own harvest call on page unloading because of dual EoL logic.
|
|
167
|
+
Mitigation: NR 'unload' and 'pageHide' are both recorded when window pageHide fires, rather than only recording 'unload'.
|
|
168
|
+
Future: When EoL can become the singular subscribeToVisibilityChange, it's likely endCurrentSession isn't needed here as 'unload'-'pageHide' can be untangled.
|
|
169
|
+
*/
|
|
170
|
+
this.endCurrentSession(timestamp)
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
addTiming (name, value, attrs) {
|
|
174
|
+
attrs = attrs || {}
|
|
175
|
+
|
|
176
|
+
// If cls was set to another value by `onCLS`, then it's supported and is attached onto any timing but is omitted until such time.
|
|
177
|
+
/*
|
|
178
|
+
*cli Apr'23 - Convert attach-to-all -> attach-if-not-null. See NEWRELIC-6143.
|
|
179
|
+
Issue: Because NR 'pageHide' was only sent once with what is considered the "final" CLS value, in the case that 'pageHide' fires before 'load' happens, we incorrectly a final CLS of 0 for that page.
|
|
180
|
+
Mitigation: We've set initial CLS to null so that it's omitted from timings like 'pageHide' in that edge case. It should only be included if onCLS callback was executed at least once.
|
|
181
|
+
Future: onCLS value changes should be reported directly & CLS separated into its own timing node so it's not beholden to 'pageHide' firing. It'd also be possible to report the real final CLS.
|
|
182
|
+
*/
|
|
183
|
+
if (this.cls !== null) {
|
|
184
|
+
attrs['cls'] = this.cls
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
this.timings.push({
|
|
188
|
+
name: name,
|
|
189
|
+
value: value,
|
|
190
|
+
attrs: attrs
|
|
191
|
+
})
|
|
192
|
+
|
|
193
|
+
handle('pvtAdded', [name, value, attrs], undefined, FEATURE_NAMES.sessionTrace, this.ee)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
onHarvestFinished (result) {
|
|
197
|
+
if (result.retry && this.timingsSent.length > 0) {
|
|
198
|
+
for (var i = 0; i < this.timingsSent.length; i++) {
|
|
199
|
+
this.timings.push(this.timingsSent[i])
|
|
200
|
+
}
|
|
201
|
+
this.timingsSent = []
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
appendGlobalCustomAttributes (timing) {
|
|
206
|
+
var timingAttributes = timing.attrs || {}
|
|
207
|
+
var customAttributes = getInfo(this.agentIdentifier).jsAttributes || {}
|
|
208
|
+
|
|
209
|
+
var reservedAttributes = ['size', 'eid', 'cls', 'type', 'fid', 'elTag', 'elUrl', 'net-type',
|
|
210
|
+
'net-etype', 'net-rtt', 'net-dlink']
|
|
211
|
+
mapOwn(customAttributes, function (key, val) {
|
|
212
|
+
if (reservedAttributes.indexOf(key) < 0) {
|
|
213
|
+
timingAttributes[key] = val
|
|
214
|
+
}
|
|
215
|
+
})
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
// serialize and return current timing data, clear and save current data for retry
|
|
219
|
+
prepareHarvest (options) {
|
|
220
|
+
if (this.timings.length === 0) return
|
|
221
|
+
|
|
222
|
+
var payload = this.getPayload(this.timings)
|
|
223
|
+
if (options.retry) {
|
|
224
|
+
for (var i = 0; i < this.timings.length; i++) {
|
|
225
|
+
this.timingsSent.push(this.timings[i])
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
this.timings = []
|
|
229
|
+
return { body: { e: payload } }
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
// serialize array of timing data
|
|
233
|
+
getPayload (data) {
|
|
234
|
+
var addString = getAddStringContext(this.agentIdentifier)
|
|
235
|
+
|
|
236
|
+
var payload = 'bel.6;'
|
|
237
|
+
|
|
238
|
+
for (var i = 0; i < data.length; i++) {
|
|
239
|
+
var timing = data[i]
|
|
240
|
+
|
|
241
|
+
payload += 'e,'
|
|
242
|
+
payload += addString(timing.name) + ','
|
|
243
|
+
payload += nullable(timing.value, numeric, false) + ','
|
|
244
|
+
|
|
245
|
+
this.appendGlobalCustomAttributes(timing)
|
|
246
|
+
|
|
247
|
+
var attrParts = addCustomAttributes(timing.attrs, addString)
|
|
248
|
+
if (attrParts && attrParts.length > 0) {
|
|
249
|
+
payload += numeric(attrParts.length) + ';' + attrParts.join(';')
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
if ((i + 1) < data.length) payload += ';'
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
return payload
|
|
256
|
+
}
|
|
257
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Calls the `onReport` function when the 'first-paint' PerformancePaintTiming entry is observed.
|
|
3
|
+
* The argument supplied is an object similar to the Metric type used by web-vitals library.
|
|
4
|
+
*
|
|
5
|
+
* @param {Function} onReport - callback that accepts a `metric` object as the single parameter
|
|
6
|
+
*/
|
|
7
|
+
export const onFirstPaint = (onReport) => {
|
|
8
|
+
const handleEntries = (entries) => {
|
|
9
|
+
entries.forEach(entry => {
|
|
10
|
+
if (entry.name === 'first-paint') {
|
|
11
|
+
observer.disconnect()
|
|
12
|
+
|
|
13
|
+
/* Initial hidden state and pre-rendering not yet considered for first paint. See web-vitals onFCP for example. */
|
|
14
|
+
const metric = {
|
|
15
|
+
name: 'FP',
|
|
16
|
+
value: entry.startTime
|
|
17
|
+
}
|
|
18
|
+
onReport(metric)
|
|
19
|
+
}
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let observer
|
|
24
|
+
try {
|
|
25
|
+
if (PerformanceObserver.supportedEntryTypes.includes('paint')) {
|
|
26
|
+
observer = new PerformanceObserver((list) => {
|
|
27
|
+
// Delay by a microtask to workaround a bug in Safari where the
|
|
28
|
+
// callback is invoked immediately, rather than in a separate task.
|
|
29
|
+
// See: https://github.com/GoogleChrome/web-vitals/issues/277
|
|
30
|
+
Promise.resolve().then(() => {
|
|
31
|
+
handleEntries(list.getEntries())
|
|
32
|
+
})
|
|
33
|
+
})
|
|
34
|
+
observer.observe({ type: 'paint', buffered: true })
|
|
35
|
+
}
|
|
36
|
+
} catch (e) {
|
|
37
|
+
// Do nothing.
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/* BFCache restore not yet considered for first paint. See web-vitals onFCP for example. */
|
|
41
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Instrument as PageViewTiming } from './instrument/index'
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { handle } from '../../../common/event-emitter/handle'
|
|
6
|
+
import { getRuntime } from '../../../common/config/config'
|
|
7
|
+
import { subscribeToVisibilityChange } from '../../../common/window/page-visibility'
|
|
8
|
+
import { windowAddEventListener } from '../../../common/event-listener/event-listener-opts'
|
|
9
|
+
import { now } from '../../../common/timing/now'
|
|
10
|
+
import { InstrumentBase } from '../../utils/instrument-base'
|
|
11
|
+
import { FEATURE_NAME } from '../constants'
|
|
12
|
+
import { isBrowserScope } from '../../../common/util/global-scope'
|
|
13
|
+
|
|
14
|
+
export class Instrument extends InstrumentBase {
|
|
15
|
+
static featureName = FEATURE_NAME
|
|
16
|
+
constructor (agentIdentifier, aggregator, auto = true) {
|
|
17
|
+
super(agentIdentifier, aggregator, FEATURE_NAME, auto)
|
|
18
|
+
if (!isBrowserScope) return // CWV is irrelevant outside web context
|
|
19
|
+
|
|
20
|
+
// Document visibility state becomes hidden; this should run as soon as possible in page life.
|
|
21
|
+
// While we try to replicate web-vital's visibilitywatcher logic in an effort to defer that library to post-pageload, this isn't perfect and doesn't consider prerendering.
|
|
22
|
+
getRuntime(agentIdentifier).initHidden = Boolean(document.visibilityState === 'hidden')
|
|
23
|
+
subscribeToVisibilityChange(() => handle('docHidden', [now()], undefined, FEATURE_NAME, this.ee), true)
|
|
24
|
+
|
|
25
|
+
// Window fires its pagehide event (typically on navigation--this occurrence is a *subset* of vis change); don't defer this unless it's guarantee it cannot happen before load(?)
|
|
26
|
+
windowAddEventListener('pagehide', () => handle('winPagehide', [now()], undefined, FEATURE_NAME, this.ee))
|
|
27
|
+
|
|
28
|
+
this.importAggregator()
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { subscribeToEOL } from '../../common/unload/eol'
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Calls the `onReport` function for every entry reported by the PerformanceLongTaskTiming API.
|
|
5
|
+
* The reported value is a `DOMHighResTimeStamp`.
|
|
6
|
+
*
|
|
7
|
+
* The callback is always called when the page's visibility state changes to hidden.
|
|
8
|
+
* As a result, the `onReport` function might be called multiple times during the same page load.
|
|
9
|
+
*
|
|
10
|
+
* @param {Function} onReport - callback that accepts a `metric` object as the single parameter
|
|
11
|
+
*/
|
|
12
|
+
export const onLongTask = (onReport) => {
|
|
13
|
+
const handleEntries = (entries) => {
|
|
14
|
+
entries.forEach(entry => {
|
|
15
|
+
const metric = {
|
|
16
|
+
name: 'LT',
|
|
17
|
+
value: entry.duration,
|
|
18
|
+
info: { // this property deviates from CWV std interface but will hold the custom context to send to NRDB
|
|
19
|
+
ltFrame: entry.name, // MDN: the browsing context or frame that can be attributed to the long task
|
|
20
|
+
ltStart: entry.startTime, // MDN: a double representing the time (millisec) when the task started
|
|
21
|
+
ltCtr: entry.attribution[0].containerType // MDN: type of frame container: 'iframe', 'embed', or 'object' ... but this can also be 'window'
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
if (metric.info.ltCtr !== 'window') { // the following properties are only of relevance & appended for html elements
|
|
25
|
+
Object.assign(metric.info, {
|
|
26
|
+
ltCtrSrc: entry.attribution[0].containerSrc, // MDN: container's 'src' attribute
|
|
27
|
+
ltCtrId: entry.attribution[0].containerId, // MDN: container's 'id' attribute
|
|
28
|
+
ltCtrName: entry.attribution[0].containerName // MDN: container's 'name' attribute
|
|
29
|
+
})
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
onReport(metric) // report every long task observed unconditionally
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
let observer
|
|
37
|
+
try {
|
|
38
|
+
if (PerformanceObserver.supportedEntryTypes.includes('longtask')) {
|
|
39
|
+
observer = new PerformanceObserver((list) => {
|
|
40
|
+
// Delay by a microtask to workaround a bug in Safari where the
|
|
41
|
+
// callback is invoked immediately, rather than in a separate task.
|
|
42
|
+
// See: https://github.com/GoogleChrome/web-vitals/issues/277
|
|
43
|
+
Promise.resolve().then(() => {
|
|
44
|
+
handleEntries(list.getEntries())
|
|
45
|
+
})
|
|
46
|
+
})
|
|
47
|
+
observer.observe({ type: 'longtask', buffered: true })
|
|
48
|
+
}
|
|
49
|
+
} catch (e) {
|
|
50
|
+
// Do nothing.
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (observer) {
|
|
54
|
+
subscribeToEOL(() => {
|
|
55
|
+
handleEntries(observer.takeRecords())
|
|
56
|
+
}, 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
|
|
57
|
+
|
|
58
|
+
/* No work needed on BFCache restore for long task. */
|
|
59
|
+
}
|
|
60
|
+
}
|