@newrelic/browser-agent 0.1.229 → 0.1.230
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 +40 -1
- package/dist/cjs/common/config/state/configurable.js +2 -1
- package/dist/cjs/common/config/state/runtime.js +1 -0
- package/dist/cjs/common/constants/environment-variables.js +1 -1
- package/dist/cjs/common/context/shared-context.js +2 -1
- package/dist/cjs/common/drain/drain.js +9 -3
- 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 +13 -2
- package/dist/cjs/common/util/console.js +1 -1
- 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/submit-data.js +11 -3
- package/dist/cjs/common/window/page-visibility.js +2 -1
- package/dist/cjs/common/window/session-storage.js +56 -11
- package/dist/cjs/common/wrap/index.js +11 -4
- package/dist/cjs/common/wrap/wrap-console.js +54 -0
- package/dist/cjs/common/wrap/wrap-events.js +4 -1
- package/dist/cjs/common/wrap/wrap-fetch.js +0 -2
- package/dist/cjs/common/wrap/wrap-function.js +4 -18
- package/dist/cjs/common/wrap/wrap-promise.js +4 -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/format-stack-trace.test.js +5 -4
- package/dist/cjs/features/jserrors/aggregate/index.js +32 -11
- package/dist/cjs/features/jserrors/aggregate/string-hash-code.test.js +5 -4
- package/dist/cjs/features/jserrors/instrument/index.js +7 -10
- package/dist/cjs/features/metrics/aggregate/index.js +11 -0
- package/dist/cjs/features/metrics/instrument/index.js +27 -1
- package/dist/cjs/features/metrics/instrument/workers-helper.js +4 -1
- package/dist/cjs/features/page_action/aggregate/index.js +11 -3
- package/dist/cjs/features/page_action/instrument/index.js +2 -1
- package/dist/cjs/features/page_view_event/aggregate/index.js +8 -4
- package/dist/cjs/features/page_view_event/instrument/index.js +2 -1
- package/dist/cjs/features/page_view_timing/aggregate/index.js +54 -35
- package/dist/cjs/features/page_view_timing/instrument/index.js +2 -1
- package/dist/cjs/features/session_trace/aggregate/index.js +53 -13
- 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 +2 -1
- package/dist/cjs/index.js +9 -9
- package/dist/cjs/loaders/agent.js +2 -1
- package/dist/cjs/loaders/api/api.js +86 -21
- package/dist/cjs/loaders/api/apiAsync.js +3 -3
- package/dist/cjs/loaders/configure/configure.js +13 -7
- package/dist/cjs/loaders/micro-agent.js +18 -13
- package/dist/esm/common/config/state/configurable.js +2 -1
- package/dist/esm/common/config/state/runtime.js +1 -0
- package/dist/esm/common/constants/environment-variables.js +1 -1
- package/dist/esm/common/context/shared-context.js +2 -1
- package/dist/esm/common/drain/drain.js +9 -3
- 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 +13 -2
- package/dist/esm/common/util/console.js +1 -1
- 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/submit-data.js +11 -3
- package/dist/esm/common/window/page-visibility.js +2 -1
- package/dist/esm/common/window/session-storage.js +54 -13
- package/dist/esm/common/wrap/index.js +5 -4
- package/dist/esm/common/wrap/wrap-console.js +46 -0
- package/dist/esm/common/wrap/wrap-events.js +5 -2
- package/dist/esm/common/wrap/wrap-fetch.js +1 -3
- package/dist/esm/common/wrap/wrap-function.js +4 -17
- package/dist/esm/common/wrap/wrap-history.js +1 -1
- package/dist/esm/common/wrap/wrap-jsonp.js +1 -1
- package/dist/esm/common/wrap/wrap-promise.js +4 -1
- package/dist/esm/common/wrap/wrap-raf.js +1 -1
- package/dist/esm/common/wrap/wrap-timer.js +1 -1
- package/dist/esm/common/wrap/wrap-xhr.js +2 -2
- 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/format-stack-trace.test.js +5 -4
- package/dist/esm/features/jserrors/aggregate/index.js +32 -11
- package/dist/esm/features/jserrors/aggregate/string-hash-code.test.js +5 -4
- package/dist/esm/features/jserrors/instrument/index.js +7 -10
- package/dist/esm/features/metrics/aggregate/index.js +11 -0
- package/dist/esm/features/metrics/instrument/index.js +27 -1
- package/dist/esm/features/metrics/instrument/workers-helper.js +4 -1
- package/dist/esm/features/page_action/aggregate/index.js +11 -3
- package/dist/esm/features/page_action/instrument/index.js +2 -1
- package/dist/esm/features/page_view_event/aggregate/index.js +8 -4
- package/dist/esm/features/page_view_event/instrument/index.js +2 -1
- package/dist/esm/features/page_view_timing/aggregate/index.js +54 -35
- package/dist/esm/features/page_view_timing/instrument/index.js +2 -1
- package/dist/esm/features/session_trace/aggregate/index.js +53 -13
- 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 +2 -1
- package/dist/esm/index.js +4 -4
- package/dist/esm/loaders/agent.js +2 -1
- 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/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/environment-variables.d.ts +4 -0
- package/dist/types/common/constants/environment-variables.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 +2 -0
- package/dist/types/common/ids/id.d.ts.map +1 -0
- package/dist/types/common/ids/unique-id.d.ts +5 -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 +5 -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 +2 -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 +7 -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 +12 -0
- package/dist/types/common/wrap/index.d.ts.map +1 -0
- package/dist/types/common/wrap/wrap-console.d.ts +16 -0
- package/dist/types/common/wrap/wrap-console.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 +7 -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 +33 -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 +61 -32
- 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 +10 -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 +45 -0
- package/src/common/constants/environment-variables.js +11 -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/handle.js +17 -0
- package/src/common/event-emitter/register-handler.js +25 -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 +23 -0
- package/src/common/ids/unique-id.js +81 -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 +70 -0
- package/src/common/timing/now.js +9 -0
- package/src/common/unload/eol.js +63 -0
- package/src/common/url/clean-url.js +10 -0
- package/src/common/url/encode.js +75 -0
- package/src/common/url/location.js +8 -0
- package/src/common/url/parse-url.js +71 -0
- package/src/common/url/protocol.js +19 -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 +48 -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 +18 -0
- package/src/common/wrap/wrap-console.js +47 -0
- package/src/common/wrap/wrap-events.js +106 -0
- package/src/common/wrap/wrap-fetch.js +109 -0
- package/src/common/wrap/wrap-function.js +248 -0
- package/src/common/wrap/wrap-history.js +48 -0
- package/src/common/wrap/wrap-jsonp.js +134 -0
- package/src/common/wrap/wrap-mutation.js +55 -0
- package/src/common/wrap/wrap-promise.js +165 -0
- package/src/common/wrap/wrap-raf.js +50 -0
- package/src/common/wrap/wrap-timer.js +67 -0
- package/src/common/wrap/wrap-xhr.js +213 -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 +149 -0
- package/src/features/metrics/aggregate/index.js +134 -0
- package/src/features/metrics/constants.js +7 -0
- package/src/features/metrics/index.js +1 -0
- package/src/features/metrics/instrument/index.js +44 -0
- package/src/features/metrics/instrument/workers-helper.js +110 -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 +134 -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 +246 -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 +410 -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 +126 -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 +112 -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/util/reduce.js +0 -22
- package/dist/cjs/common/window/top-level-callers.js +0 -23
- 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,159 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { gosNREUM } from '../window/nreum'
|
|
7
|
+
import { getOrSet } from '../util/get-or-set'
|
|
8
|
+
import { mapOwn } from '../util/map-own'
|
|
9
|
+
import { getRuntime } from '../config/config'
|
|
10
|
+
|
|
11
|
+
var ctxId = 'nr@context'
|
|
12
|
+
|
|
13
|
+
// create global emitter instance that can be shared among bundles
|
|
14
|
+
let nr = gosNREUM()
|
|
15
|
+
var globalInstance
|
|
16
|
+
|
|
17
|
+
if (nr.ee) {
|
|
18
|
+
globalInstance = nr.ee
|
|
19
|
+
} else {
|
|
20
|
+
globalInstance = ee(undefined, 'globalEE')
|
|
21
|
+
nr.ee = globalInstance
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export { globalInstance as ee }
|
|
25
|
+
|
|
26
|
+
function EventContext () { }
|
|
27
|
+
|
|
28
|
+
function ee (old, debugId) {
|
|
29
|
+
var handlers = {}
|
|
30
|
+
var bufferGroupMap = {}
|
|
31
|
+
var emitters = {}
|
|
32
|
+
// In cases where multiple agents can run on a page, the event backlogs of feature event emitters must be isolated
|
|
33
|
+
// to prevent event emitter context and buffers from "bubbling up" to other agents operating in the scope.
|
|
34
|
+
// An example of this is our MicroAgent loader package, which sets this property to true to prevent overlap.
|
|
35
|
+
var isolatedBacklog = false
|
|
36
|
+
try {
|
|
37
|
+
// We only want to check the runtime configuration for `isolatedBacklog` if the event emitter belongs to a feature.
|
|
38
|
+
// For feature event emitters, the debugId will be an agentIdentifier with a length of 16. In contrast, some of our
|
|
39
|
+
// tests do not namespace the event emitter with an agentID and just use the parent (which has no ID).
|
|
40
|
+
isolatedBacklog = debugId.length !== 16 ? false : getRuntime(debugId).isolatedBacklog
|
|
41
|
+
} catch (err) {
|
|
42
|
+
// Do nothing for now.
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
var emitter = {
|
|
46
|
+
on: addEventListener,
|
|
47
|
+
addEventListener: addEventListener,
|
|
48
|
+
removeEventListener: removeEventListener,
|
|
49
|
+
emit: emit,
|
|
50
|
+
get: getOrCreate,
|
|
51
|
+
listeners: listeners,
|
|
52
|
+
context: context,
|
|
53
|
+
buffer: bufferEventsByGroup,
|
|
54
|
+
abort,
|
|
55
|
+
aborted: false,
|
|
56
|
+
isBuffering: isBuffering,
|
|
57
|
+
debugId,
|
|
58
|
+
backlog: isolatedBacklog ? {} : old && typeof old.backlog === 'object' ? old.backlog : {}
|
|
59
|
+
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return emitter
|
|
63
|
+
|
|
64
|
+
function context (contextOrStore) {
|
|
65
|
+
if (contextOrStore && contextOrStore instanceof EventContext) {
|
|
66
|
+
return contextOrStore
|
|
67
|
+
} else if (contextOrStore) {
|
|
68
|
+
return getOrSet(contextOrStore, ctxId, getNewContext)
|
|
69
|
+
} else {
|
|
70
|
+
return getNewContext()
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
function emit (type, args, contextOrStore, force, bubble) {
|
|
75
|
+
if (bubble !== false) bubble = true
|
|
76
|
+
if (globalInstance.aborted && !force) { return }
|
|
77
|
+
if (old && bubble) old.emit(type, args, contextOrStore)
|
|
78
|
+
|
|
79
|
+
var ctx = context(contextOrStore)
|
|
80
|
+
var handlersArray = listeners(type)
|
|
81
|
+
var len = handlersArray.length
|
|
82
|
+
|
|
83
|
+
// Apply each handler function in the order they were added
|
|
84
|
+
// to the context with the arguments
|
|
85
|
+
|
|
86
|
+
for (var i = 0; i < len; i++) handlersArray[i].apply(ctx, args)
|
|
87
|
+
|
|
88
|
+
// Buffer after emitting for consistent ordering
|
|
89
|
+
var bufferGroup = getBuffer()[bufferGroupMap[type]]
|
|
90
|
+
if (bufferGroup) {
|
|
91
|
+
bufferGroup.push([emitter, type, args, ctx])
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
// Return the context so that the module that emitted can see what was done.
|
|
95
|
+
return ctx
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function addEventListener (type, fn) {
|
|
99
|
+
// Retrieve type from handlers, if it doesn't exist assign the default and retrieve it.
|
|
100
|
+
handlers[type] = listeners(type).concat(fn)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function removeEventListener (type, fn) {
|
|
104
|
+
var listeners = handlers[type]
|
|
105
|
+
if (!listeners) return
|
|
106
|
+
for (var i = 0; i < listeners.length; i++) {
|
|
107
|
+
if (listeners[i] === fn) {
|
|
108
|
+
listeners.splice(i, 1)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function listeners (type) {
|
|
114
|
+
return handlers[type] || []
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
function getOrCreate (name) {
|
|
118
|
+
return (emitters[name] = emitters[name] || ee(emitter, name))
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function bufferEventsByGroup (types, group) {
|
|
122
|
+
var eventBuffer = getBuffer()
|
|
123
|
+
|
|
124
|
+
// do not buffer events if agent has been aborted
|
|
125
|
+
if (emitter.aborted) return
|
|
126
|
+
mapOwn(types, function (i, type) {
|
|
127
|
+
group = group || 'feature'
|
|
128
|
+
bufferGroupMap[type] = group
|
|
129
|
+
if (!(group in eventBuffer)) {
|
|
130
|
+
eventBuffer[group] = []
|
|
131
|
+
}
|
|
132
|
+
})
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function isBuffering (type) {
|
|
136
|
+
var bufferGroup = getBuffer()[bufferGroupMap[type]]
|
|
137
|
+
return !!bufferGroup
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// buffer is associated with a base emitter, since there are two
|
|
141
|
+
// (global and scoped to the current bundle), it is now part of the emitter
|
|
142
|
+
function getBuffer () {
|
|
143
|
+
return emitter.backlog
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
// get context object from store object, or create if does not exist
|
|
148
|
+
export function getOrSetContext (obj) {
|
|
149
|
+
return getOrSet(obj, ctxId, getNewContext)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
function getNewContext () {
|
|
153
|
+
return new EventContext()
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
function abort () {
|
|
157
|
+
globalInstance.aborted = true
|
|
158
|
+
globalInstance.backlog = {}
|
|
159
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { ee as globalInstance } from './contextual-ee'
|
|
7
|
+
export var handleEE = globalInstance.get('handle')
|
|
8
|
+
|
|
9
|
+
export function handle (type, args, ctx, group, ee) {
|
|
10
|
+
if (ee) {
|
|
11
|
+
ee.buffer([type], group)
|
|
12
|
+
ee.emit(type, args, ctx)
|
|
13
|
+
} else {
|
|
14
|
+
handleEE.buffer([type], group)
|
|
15
|
+
handleEE.emit(type, args, ctx)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { handleEE } from './handle'
|
|
7
|
+
|
|
8
|
+
export { defaultRegister as registerHandler }
|
|
9
|
+
|
|
10
|
+
defaultRegister.on = registerWithSpecificEmitter
|
|
11
|
+
|
|
12
|
+
var handlers = defaultRegister.handlers = {}
|
|
13
|
+
|
|
14
|
+
export function defaultRegister (type, handler, group, ee) {
|
|
15
|
+
registerWithSpecificEmitter(ee || handleEE, handlers, type, handler, group)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function registerWithSpecificEmitter (ee, handlers, type, handler, group) {
|
|
19
|
+
if (!group) group = 'feature'
|
|
20
|
+
if (!ee) ee = handleEE
|
|
21
|
+
|
|
22
|
+
var groupHandlers = handlers[group] = handlers[group] || {}
|
|
23
|
+
var list = groupHandlers[type] = groupHandlers[type] || []
|
|
24
|
+
list.push([ee, handler])
|
|
25
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { globalScope } from '../util/global-scope'
|
|
2
|
+
|
|
3
|
+
/*
|
|
4
|
+
* See https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener#safely_detecting_option_support
|
|
5
|
+
*/
|
|
6
|
+
let passiveSupported = false
|
|
7
|
+
let signalSupported = false
|
|
8
|
+
try {
|
|
9
|
+
const options = {
|
|
10
|
+
get passive () { // this function will be called when the browser attempts to access the passive property
|
|
11
|
+
passiveSupported = true
|
|
12
|
+
return false
|
|
13
|
+
},
|
|
14
|
+
get signal () {
|
|
15
|
+
signalSupported = true
|
|
16
|
+
return false
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
globalScope.addEventListener('test', null, options)
|
|
21
|
+
globalScope.removeEventListener('test', null, options)
|
|
22
|
+
} catch (err) {}
|
|
23
|
+
|
|
24
|
+
export function eventListenerOpts (useCapture, abortSignal) {
|
|
25
|
+
return (passiveSupported || signalSupported)
|
|
26
|
+
? {
|
|
27
|
+
capture: !!useCapture,
|
|
28
|
+
passive: passiveSupported, // passive defaults to false
|
|
29
|
+
signal: abortSignal
|
|
30
|
+
}
|
|
31
|
+
: !!useCapture // mainly just IE11 doesn't support third param options under EventTarget API
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Do not use this within the worker context. */
|
|
35
|
+
export function windowAddEventListener (event, listener, capture = false) {
|
|
36
|
+
window.addEventListener(event, listener, eventListenerOpts(capture))
|
|
37
|
+
}
|
|
38
|
+
/** Do not use this within the worker context. */
|
|
39
|
+
export function documentAddEventListener (event, listener, capture = false) {
|
|
40
|
+
document.addEventListener(event, listener, eventListenerOpts(capture))
|
|
41
|
+
}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { submitData } from '../util/submit-data'
|
|
7
|
+
import { SharedContext } from '../context/shared-context'
|
|
8
|
+
import { Harvest, getSubmitMethod } from './harvest'
|
|
9
|
+
import { subscribeToEOL } from '../unload/eol'
|
|
10
|
+
import { getConfigurationValue } from '../config/config'
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Periodically invokes harvest calls and handles retries
|
|
14
|
+
*/
|
|
15
|
+
export class HarvestScheduler extends SharedContext {
|
|
16
|
+
constructor (endpoint, opts, parent) {
|
|
17
|
+
super(parent) // gets any allowed properties from the parent and stores them in `sharedContext`
|
|
18
|
+
this.endpoint = endpoint
|
|
19
|
+
this.opts = opts || {}
|
|
20
|
+
this.started = false
|
|
21
|
+
this.timeoutHandle = null
|
|
22
|
+
this.aborted = false // this controls the per-interval and final harvests for the scheduler (currently per feature specific!)
|
|
23
|
+
|
|
24
|
+
this.harvest = new Harvest(this.sharedContext)
|
|
25
|
+
|
|
26
|
+
subscribeToEOL(() => {
|
|
27
|
+
if (this.aborted) return
|
|
28
|
+
|
|
29
|
+
// If opts.onUnload is defined, these are special actions to execute before attempting to send the final payload.
|
|
30
|
+
if (this.opts.onUnload) this.opts.onUnload()
|
|
31
|
+
this.runHarvest({ unload: true })
|
|
32
|
+
}, getConfigurationValue(this.sharedContext.agentIdentifier, 'allow_bfcache')) // TO DO: remove feature flag after rls stable
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
startTimer (interval, initialDelay) {
|
|
36
|
+
this.interval = interval
|
|
37
|
+
this.started = true
|
|
38
|
+
this.scheduleHarvest(initialDelay != null ? initialDelay : this.interval)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
stopTimer (permanently = false) {
|
|
42
|
+
this.aborted = permanently // stopping permanently is same as aborting, but this function also cleans up the setTimeout loop
|
|
43
|
+
this.started = false
|
|
44
|
+
if (this.timeoutHandle) {
|
|
45
|
+
clearTimeout(this.timeoutHandle)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
scheduleHarvest (delay, opts) {
|
|
50
|
+
if (this.timeoutHandle) return
|
|
51
|
+
var timer = this
|
|
52
|
+
|
|
53
|
+
if (delay == null) {
|
|
54
|
+
delay = this.interval
|
|
55
|
+
}
|
|
56
|
+
this.timeoutHandle = setTimeout(() => {
|
|
57
|
+
timer.timeoutHandle = null
|
|
58
|
+
timer.runHarvest(opts)
|
|
59
|
+
}, delay * 1000)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
runHarvest (opts) {
|
|
63
|
+
if (this.aborted) return
|
|
64
|
+
var scheduler = this
|
|
65
|
+
|
|
66
|
+
if (this.opts.getPayload) { // Ajax & PVT
|
|
67
|
+
var submitMethod = getSubmitMethod(this.endpoint, opts)
|
|
68
|
+
if (!submitMethod) return false
|
|
69
|
+
|
|
70
|
+
var retry = submitMethod.method === submitData.xhr
|
|
71
|
+
var payload = this.opts.getPayload({ retry: retry })
|
|
72
|
+
if (payload) {
|
|
73
|
+
payload = Object.prototype.toString.call(payload) === '[object Array]' ? payload : [payload]
|
|
74
|
+
for (var i = 0; i < payload.length; i++) {
|
|
75
|
+
this.harvest.send(this.endpoint, payload[i], opts, submitMethod, onHarvestFinished)
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
const runAfterSending = opts?.unload ? undefined : onHarvestFinished // don't bother running onFinish handler if this is the final harvest
|
|
80
|
+
this.harvest.sendX(this.endpoint, opts, runAfterSending)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
if (this.started) {
|
|
84
|
+
this.scheduleHarvest()
|
|
85
|
+
}
|
|
86
|
+
return
|
|
87
|
+
|
|
88
|
+
function onHarvestFinished (result) {
|
|
89
|
+
if (result.blocked) scheduler.onHarvestBlocked(opts, result)
|
|
90
|
+
else scheduler.onHarvestFinished(opts, result)
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
onHarvestFinished (opts, result) {
|
|
95
|
+
if (this.opts.onFinished) {
|
|
96
|
+
this.opts.onFinished(result)
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
if (result.sent && result.retry) {
|
|
100
|
+
var delay = result.delay || this.opts.retryDelay
|
|
101
|
+
// reschedule next harvest if should be delayed longer
|
|
102
|
+
if (this.started && delay) {
|
|
103
|
+
clearTimeout(this.timeoutHandle)
|
|
104
|
+
this.timeoutHandle = null
|
|
105
|
+
this.scheduleHarvest(delay, opts)
|
|
106
|
+
} else if (!this.started && delay) {
|
|
107
|
+
// if not running on a timer, schedule a single retry
|
|
108
|
+
this.scheduleHarvest(delay, opts)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { mapOwn } from '../util/map-own'
|
|
7
|
+
import { obj as encodeObj, param as encodeParam } from '../url/encode'
|
|
8
|
+
import { stringify } from '../util/stringify'
|
|
9
|
+
import { submitData } from '../util/submit-data'
|
|
10
|
+
import { getLocation } from '../url/location'
|
|
11
|
+
import { getInfo, getConfigurationValue, getRuntime, getConfiguration } from '../config/config'
|
|
12
|
+
import { cleanURL } from '../url/clean-url'
|
|
13
|
+
import { now } from '../timing/now'
|
|
14
|
+
import { eventListenerOpts } from '../event-listener/event-listener-opts'
|
|
15
|
+
import { Obfuscator } from '../util/obfuscate'
|
|
16
|
+
import { applyFnToProps } from '../util/traverse'
|
|
17
|
+
import { SharedContext } from '../context/shared-context'
|
|
18
|
+
import { VERSION } from '../constants/environment-variables'
|
|
19
|
+
import { isBrowserScope, isWorkerScope } from '../util/global-scope'
|
|
20
|
+
|
|
21
|
+
const haveSendBeacon = !!navigator.sendBeacon // only the web window obj has sendBeacon at this time, so 'false' for other envs
|
|
22
|
+
|
|
23
|
+
export class Harvest extends SharedContext {
|
|
24
|
+
constructor (parent) {
|
|
25
|
+
super(parent) // gets any allowed properties from the parent and stores them in `sharedContext`
|
|
26
|
+
|
|
27
|
+
this.tooManyRequestsDelay = getConfigurationValue(this.sharedContext.agentIdentifier, 'harvest.tooManyRequestsDelay') || 60
|
|
28
|
+
this.obfuscator = new Obfuscator(this.sharedContext)
|
|
29
|
+
this.getScheme = () => (getConfigurationValue(this.sharedContext.agentIdentifier, 'ssl') === false) ? 'http' : 'https'
|
|
30
|
+
|
|
31
|
+
this._events = {}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Initiate a harvest from multiple sources. An event that corresponds to the endpoint
|
|
36
|
+
* name is emitted, which gives any listeners the opportunity to provide payload data.
|
|
37
|
+
*
|
|
38
|
+
* @param {string} endpoint - The endpoint of the harvest (jserrors, events, resources etc.)
|
|
39
|
+
*
|
|
40
|
+
* @param {object} opts
|
|
41
|
+
* @param {bool} opts.needResponse - Specify whether the caller expects a response data.
|
|
42
|
+
* @param {bool} opts.unload - Specify whether the call is a final harvest during page unload.
|
|
43
|
+
*/
|
|
44
|
+
sendX (endpoint, opts, cbFinished) {
|
|
45
|
+
var submitMethod = getSubmitMethod(endpoint, opts)
|
|
46
|
+
if (!submitMethod) return false
|
|
47
|
+
var options = {
|
|
48
|
+
retry: submitMethod.method === submitData.xhr
|
|
49
|
+
}
|
|
50
|
+
return this.obfuscator.shouldObfuscate() ? this.obfuscateAndSend(endpoint, this.createPayload(endpoint, options), opts, submitMethod, cbFinished) : this._send(endpoint, this.createPayload(endpoint, options), opts, submitMethod, cbFinished)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Initiate a harvest call.
|
|
55
|
+
*
|
|
56
|
+
* @param {string} endpoint - The endpoint of the harvest (jserrors, events, resources etc.)
|
|
57
|
+
* @param {object} nr - The loader singleton.
|
|
58
|
+
*
|
|
59
|
+
* @param {object} singlePayload - Object representing payload.
|
|
60
|
+
* @param {object} singlePayload.qs - Map of values that should be sent as part of the request query string.
|
|
61
|
+
* @param {string} singlePayload.body - String that should be sent as the body of the request.
|
|
62
|
+
* @param {string} singlePayload.body.e - Special case of body used for browser interactions.
|
|
63
|
+
*
|
|
64
|
+
* @param {object} opts
|
|
65
|
+
* @param {bool} opts.needResponse - Specify whether the caller expects a response data.
|
|
66
|
+
* @param {bool} opts.unload - Specify whether the call is a final harvest during page unload.
|
|
67
|
+
*/
|
|
68
|
+
send (endpoint, singlePayload, opts, submitMethod, cbFinished) {
|
|
69
|
+
var makeBody = createAccumulator()
|
|
70
|
+
var makeQueryString = createAccumulator()
|
|
71
|
+
if (singlePayload.body) mapOwn(singlePayload.body, makeBody)
|
|
72
|
+
if (singlePayload.qs) mapOwn(singlePayload.qs, makeQueryString)
|
|
73
|
+
|
|
74
|
+
var payload = { body: makeBody(), qs: makeQueryString() }
|
|
75
|
+
var caller = this.obfuscator.shouldObfuscate() ? (...args) => this.obfuscateAndSend(...args) : (...args) => this._send(...args)
|
|
76
|
+
|
|
77
|
+
return caller(endpoint, payload, opts, submitMethod, cbFinished)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
obfuscateAndSend (endpoint, payload, opts, submitMethod, cbFinished) {
|
|
81
|
+
applyFnToProps(payload, (...args) => this.obfuscator.obfuscateString(...args), 'string', ['e'])
|
|
82
|
+
return this._send(endpoint, payload, opts, submitMethod, cbFinished)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
_send (endpoint, payload, opts, submitMethod, cbFinished) {
|
|
86
|
+
var info = getInfo(this.sharedContext.agentIdentifier)
|
|
87
|
+
if (!info.errorBeacon) return false
|
|
88
|
+
|
|
89
|
+
var agentRuntime = getRuntime(this.sharedContext.agentIdentifier)
|
|
90
|
+
|
|
91
|
+
if (!payload.body) { // no payload body? nothing to send, just run onfinish stuff and return
|
|
92
|
+
if (cbFinished) {
|
|
93
|
+
cbFinished({ sent: false })
|
|
94
|
+
}
|
|
95
|
+
return false
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
if (!opts) opts = {}
|
|
99
|
+
|
|
100
|
+
var url = this.getScheme() + '://' + info.errorBeacon + '/' + endpoint + '/1/' + info.licenseKey + this.baseQueryString()
|
|
101
|
+
if (payload.qs) url += encodeObj(payload.qs, agentRuntime.maxBytes)
|
|
102
|
+
|
|
103
|
+
if (!submitMethod) {
|
|
104
|
+
submitMethod = getSubmitMethod(endpoint, opts)
|
|
105
|
+
}
|
|
106
|
+
var method = submitMethod.method
|
|
107
|
+
var useBody = submitMethod.useBody
|
|
108
|
+
|
|
109
|
+
var body
|
|
110
|
+
var fullUrl = url
|
|
111
|
+
if (useBody && endpoint === 'events') {
|
|
112
|
+
body = payload.body.e
|
|
113
|
+
} else if (useBody) {
|
|
114
|
+
body = stringify(payload.body)
|
|
115
|
+
} else {
|
|
116
|
+
fullUrl = url + encodeObj(payload.body, agentRuntime.maxBytes)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
// Get bytes harvested per endpoint as a supportability metric. See metrics aggregator (on unload).
|
|
120
|
+
agentRuntime.bytesSent[endpoint] = (agentRuntime.bytesSent[endpoint] || 0) + body?.length || 0
|
|
121
|
+
|
|
122
|
+
/* Since workers don't support sendBeacon right now, or Image(), they can only use XHR method.
|
|
123
|
+
Because they still do permit synch XHR, the idea is that at final harvest time (worker is closing),
|
|
124
|
+
we just make a BLOCKING request--trivial impact--with the remaining data as a temp fill-in for sendBeacon. */
|
|
125
|
+
var result = method(fullUrl, body, opts.unload && isWorkerScope)
|
|
126
|
+
|
|
127
|
+
if (cbFinished && method === submitData.xhr) {
|
|
128
|
+
var xhr = result
|
|
129
|
+
xhr.addEventListener('load', function () {
|
|
130
|
+
var result = { sent: true }
|
|
131
|
+
if (this.status === 429) {
|
|
132
|
+
result.retry = true
|
|
133
|
+
result.delay = this.tooManyRequestsDelay
|
|
134
|
+
} else if (this.status === 408 || this.status === 500 || this.status === 503) {
|
|
135
|
+
result.retry = true
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
if (opts.needResponse) {
|
|
139
|
+
result.responseText = this.responseText
|
|
140
|
+
}
|
|
141
|
+
cbFinished(result)
|
|
142
|
+
}, eventListenerOpts(false))
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// if beacon request failed, retry with an alternative method -- will not happen for workers
|
|
146
|
+
if (!result && method === submitData.beacon) {
|
|
147
|
+
method = submitData.img
|
|
148
|
+
result = method(url + encodeObj(payload.body, agentRuntime.maxBytes))
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
return result
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// The stuff that gets sent every time.
|
|
155
|
+
baseQueryString () {
|
|
156
|
+
var runtime = getRuntime(this.sharedContext.agentIdentifier)
|
|
157
|
+
var info = getInfo(this.sharedContext.agentIdentifier)
|
|
158
|
+
|
|
159
|
+
var location = cleanURL(getLocation())
|
|
160
|
+
var ref = this.obfuscator.shouldObfuscate() ? this.obfuscator.obfuscateString(location) : location
|
|
161
|
+
|
|
162
|
+
return ([
|
|
163
|
+
'?a=' + info.applicationID,
|
|
164
|
+
encodeParam('sa', (info.sa ? '' + info.sa : '')),
|
|
165
|
+
encodeParam('v', VERSION),
|
|
166
|
+
transactionNameParam(info),
|
|
167
|
+
encodeParam('ct', runtime.customTransaction),
|
|
168
|
+
'&rst=' + now(),
|
|
169
|
+
'&ck=0', // ck param DEPRECATED - still expected by backend
|
|
170
|
+
'&s=' + (runtime.sessionId || '0'), // the 0 id encaps all untrackable and default traffic
|
|
171
|
+
encodeParam('ref', ref),
|
|
172
|
+
encodeParam('ptid', (runtime.ptid ? '' + runtime.ptid : ''))
|
|
173
|
+
].join(''))
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
createPayload (type, options) {
|
|
177
|
+
var makeBody = createAccumulator()
|
|
178
|
+
var makeQueryString = createAccumulator()
|
|
179
|
+
var listeners = (this._events[type] && this._events[type] || [])
|
|
180
|
+
|
|
181
|
+
for (var i = 0; i < listeners.length; i++) {
|
|
182
|
+
var singlePayload = listeners[i](options)
|
|
183
|
+
if (!singlePayload) continue
|
|
184
|
+
if (singlePayload.body) mapOwn(singlePayload.body, makeBody)
|
|
185
|
+
if (singlePayload.qs) mapOwn(singlePayload.qs, makeQueryString)
|
|
186
|
+
}
|
|
187
|
+
return { body: makeBody(), qs: makeQueryString() }
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
on (type, listener) {
|
|
191
|
+
var listeners = (this._events[type] || (this._events[type] = []))
|
|
192
|
+
listeners.push(listener)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
resetListeners () {
|
|
196
|
+
mapOwn(this._events, (key) => {
|
|
197
|
+
this._events[key] = []
|
|
198
|
+
})
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
function or (a, b) { return a || b }
|
|
203
|
+
|
|
204
|
+
export function getSubmitMethod (endpoint, opts) {
|
|
205
|
+
opts = opts || {}
|
|
206
|
+
var method
|
|
207
|
+
var useBody
|
|
208
|
+
|
|
209
|
+
if (opts.needResponse) { // currently: only STN needs a response
|
|
210
|
+
useBody = true
|
|
211
|
+
method = submitData.xhr
|
|
212
|
+
} else if (opts.unload && isBrowserScope) { // all the features' final harvest; neither methods work outside window context
|
|
213
|
+
useBody = haveSendBeacon
|
|
214
|
+
method = haveSendBeacon ? submitData.beacon : submitData.img // really only IE doesn't have Beacon API for web browsers
|
|
215
|
+
} else {
|
|
216
|
+
// `submitData.beacon` was removed, there is an upper limit to the
|
|
217
|
+
// number of data allowed before it starts failing, so we save it only for page unloading
|
|
218
|
+
useBody = true
|
|
219
|
+
method = submitData.xhr
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
return {
|
|
223
|
+
method: method,
|
|
224
|
+
useBody: useBody
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// Constructs the transaction name param for the beacon URL.
|
|
229
|
+
// Prefers the obfuscated transaction name over the plain text.
|
|
230
|
+
// Falls back to making up a name.
|
|
231
|
+
function transactionNameParam (info) {
|
|
232
|
+
if (info.transactionName) return encodeParam('to', info.transactionName)
|
|
233
|
+
return encodeParam('t', info.tNamePlain || 'Unnamed Transaction')
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
// returns a function that can be called to accumulate values to a single object
|
|
237
|
+
// when the function is called without parameters, then the accumulator is returned
|
|
238
|
+
function createAccumulator () {
|
|
239
|
+
var accumulator = {}
|
|
240
|
+
var hasData = false
|
|
241
|
+
return function (key, val) {
|
|
242
|
+
if (val && val.length) {
|
|
243
|
+
accumulator[key] = val
|
|
244
|
+
hasData = true
|
|
245
|
+
}
|
|
246
|
+
if (hasData) return accumulator
|
|
247
|
+
}
|
|
248
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
// Start assigning ids at 1 so 0 can always be used for WindowOrWorkerGlobalScope, without
|
|
7
|
+
// actually setting it (which would create a global variable).
|
|
8
|
+
import { getOrSet } from '../util/get-or-set'
|
|
9
|
+
import { globalScope } from '../util/global-scope'
|
|
10
|
+
|
|
11
|
+
var index = 1
|
|
12
|
+
var prop = 'nr@id'
|
|
13
|
+
|
|
14
|
+
// Always returns id of obj, may tag obj with an id in the process.
|
|
15
|
+
export function id (obj) {
|
|
16
|
+
var type = typeof obj
|
|
17
|
+
// We can only tag objects, functions, and arrays with ids.
|
|
18
|
+
// For all primitive values we instead return -1.
|
|
19
|
+
if (!obj || !(type === 'object' || type === 'function')) return -1
|
|
20
|
+
if (obj === globalScope) return 0
|
|
21
|
+
|
|
22
|
+
return getOrSet(obj, prop, function () { return index++ })
|
|
23
|
+
}
|