@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,380 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { originals, getLoaderConfig, getRuntime } from '../../../common/config/config'
|
|
6
|
+
import { handle } from '../../../common/event-emitter/handle'
|
|
7
|
+
import { id } from '../../../common/ids/id'
|
|
8
|
+
import { ffVersion } from '../../../common/browser-version/firefox-version'
|
|
9
|
+
import { dataSize } from '../../../common/util/data-size'
|
|
10
|
+
import { eventListenerOpts } from '../../../common/event-listener/event-listener-opts'
|
|
11
|
+
import { now } from '../../../common/timing/now'
|
|
12
|
+
import { wrapFetch, wrapXhr } from '../../../common/wrap'
|
|
13
|
+
import { parseUrl } from '../../../common/url/parse-url'
|
|
14
|
+
import { DT } from './distributed-tracing'
|
|
15
|
+
import { responseSizeFromXhr } from './response-size'
|
|
16
|
+
import { InstrumentBase } from '../../utils/instrument-base'
|
|
17
|
+
import { FEATURE_NAME } from '../constants'
|
|
18
|
+
import { FEATURE_NAMES } from '../../../loaders/features/features'
|
|
19
|
+
import { globalScope } from '../../../common/util/global-scope'
|
|
20
|
+
|
|
21
|
+
var handlers = ['load', 'error', 'abort', 'timeout']
|
|
22
|
+
var handlersLen = handlers.length
|
|
23
|
+
|
|
24
|
+
var origRequest = originals.REQ
|
|
25
|
+
var origXHR = globalScope.XMLHttpRequest
|
|
26
|
+
|
|
27
|
+
export class Instrument extends InstrumentBase {
|
|
28
|
+
static featureName = FEATURE_NAME
|
|
29
|
+
constructor (agentIdentifier, aggregator, auto = true) {
|
|
30
|
+
super(agentIdentifier, aggregator, FEATURE_NAME, auto)
|
|
31
|
+
|
|
32
|
+
// Very unlikely, but in case the existing XMLHttpRequest.prototype object on the page couldn't be wrapped.
|
|
33
|
+
if (!getRuntime(agentIdentifier).xhrWrappable) return
|
|
34
|
+
|
|
35
|
+
this.dt = new DT(agentIdentifier)
|
|
36
|
+
|
|
37
|
+
this.handler = (type, args, ctx, group) => handle(type, args, ctx, group, this.ee)
|
|
38
|
+
wrapFetch(this.ee)
|
|
39
|
+
wrapXhr(this.ee)
|
|
40
|
+
subscribeToEvents(agentIdentifier, this.ee, this.handler, this.dt)
|
|
41
|
+
|
|
42
|
+
this.importAggregator()
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function subscribeToEvents (agentIdentifier, ee, handler, dt) {
|
|
47
|
+
ee.on('new-xhr', onNewXhr)
|
|
48
|
+
ee.on('open-xhr-start', onOpenXhrStart)
|
|
49
|
+
ee.on('open-xhr-end', onOpenXhrEnd)
|
|
50
|
+
ee.on('send-xhr-start', onSendXhrStart)
|
|
51
|
+
ee.on('xhr-cb-time', onXhrCbTime)
|
|
52
|
+
ee.on('xhr-load-added', onXhrLoadAdded)
|
|
53
|
+
ee.on('xhr-load-removed', onXhrLoadRemoved)
|
|
54
|
+
ee.on('xhr-resolved', onXhrResolved)
|
|
55
|
+
ee.on('addEventListener-end', onAddEventListenerEnd)
|
|
56
|
+
ee.on('removeEventListener-end', onRemoveEventListenerEnd)
|
|
57
|
+
ee.on('fn-end', onFnEnd)
|
|
58
|
+
ee.on('fetch-before-start', onFetchBeforeStart)
|
|
59
|
+
ee.on('fetch-start', onFetchStart)
|
|
60
|
+
ee.on('fn-start', onFnStart)
|
|
61
|
+
ee.on('fetch-done', onFetchDone)
|
|
62
|
+
|
|
63
|
+
// Setup the context for each new xhr object
|
|
64
|
+
function onNewXhr (xhr) {
|
|
65
|
+
var ctx = this
|
|
66
|
+
ctx.totalCbs = 0
|
|
67
|
+
ctx.called = 0
|
|
68
|
+
ctx.cbTime = 0
|
|
69
|
+
ctx.end = end
|
|
70
|
+
ctx.ended = false
|
|
71
|
+
ctx.xhrGuids = {}
|
|
72
|
+
ctx.lastSize = null
|
|
73
|
+
ctx.loadCaptureCalled = false
|
|
74
|
+
ctx.params = this.params || {}
|
|
75
|
+
ctx.metrics = this.metrics || {}
|
|
76
|
+
|
|
77
|
+
xhr.addEventListener('load', function (event) {
|
|
78
|
+
captureXhrData(ctx, xhr)
|
|
79
|
+
}, eventListenerOpts(false))
|
|
80
|
+
|
|
81
|
+
// In Firefox (v34+), XHR ProgressEvents report pre-content-decoding sizes via
|
|
82
|
+
// their 'loaded' property, rather than post-decoding sizes. We want
|
|
83
|
+
// post-decoding sizes for consistency with browsers where that's all we have.
|
|
84
|
+
// See: https://bugzilla.mozilla.org/show_bug.cgi?id=1227674
|
|
85
|
+
//
|
|
86
|
+
// So we don't use ProgressEvents to measure XHR sizes for FF.
|
|
87
|
+
if (ffVersion) return
|
|
88
|
+
|
|
89
|
+
xhr.addEventListener('progress', function (event) {
|
|
90
|
+
ctx.lastSize = event.loaded
|
|
91
|
+
}, eventListenerOpts(false))
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function onOpenXhrStart (args) {
|
|
95
|
+
this.params = { method: args[0] }
|
|
96
|
+
addUrl(this, args[1])
|
|
97
|
+
this.metrics = {}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function onOpenXhrEnd (args, xhr) {
|
|
101
|
+
var loader_config = getLoaderConfig(agentIdentifier)
|
|
102
|
+
if ('xpid' in loader_config && this.sameOrigin) {
|
|
103
|
+
xhr.setRequestHeader('X-NewRelic-ID', loader_config.xpid)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
var payload = dt.generateTracePayload(this.parsedOrigin)
|
|
107
|
+
if (payload) {
|
|
108
|
+
var added = false
|
|
109
|
+
if (payload.newrelicHeader) {
|
|
110
|
+
xhr.setRequestHeader('newrelic', payload.newrelicHeader)
|
|
111
|
+
added = true
|
|
112
|
+
}
|
|
113
|
+
if (payload.traceContextParentHeader) {
|
|
114
|
+
xhr.setRequestHeader('traceparent', payload.traceContextParentHeader)
|
|
115
|
+
if (payload.traceContextStateHeader) {
|
|
116
|
+
xhr.setRequestHeader('tracestate', payload.traceContextStateHeader)
|
|
117
|
+
}
|
|
118
|
+
added = true
|
|
119
|
+
}
|
|
120
|
+
if (added) {
|
|
121
|
+
this.dt = payload
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
function onSendXhrStart (args, xhr) {
|
|
127
|
+
var metrics = this.metrics
|
|
128
|
+
var data = args[0]
|
|
129
|
+
var context = this
|
|
130
|
+
|
|
131
|
+
if (metrics && data) {
|
|
132
|
+
var size = dataSize(data)
|
|
133
|
+
if (size) metrics.txSize = size
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
this.startTime = now()
|
|
137
|
+
|
|
138
|
+
this.listener = function (evt) {
|
|
139
|
+
try {
|
|
140
|
+
if (evt.type === 'abort' && !(context.loadCaptureCalled)) {
|
|
141
|
+
context.params.aborted = true
|
|
142
|
+
}
|
|
143
|
+
if (evt.type !== 'load' || (context.called === context.totalCbs) && (context.onloadCalled || typeof (xhr.onload) !== 'function') && typeof context.end === 'function') context.end(xhr)
|
|
144
|
+
} catch (e) {
|
|
145
|
+
try {
|
|
146
|
+
ee.emit('internal-error', [e])
|
|
147
|
+
} catch (err) {
|
|
148
|
+
// do nothing
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
for (var i = 0; i < handlersLen; i++) {
|
|
154
|
+
xhr.addEventListener(handlers[i], this.listener, eventListenerOpts(false))
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
function onXhrCbTime (time, onload, xhr) {
|
|
159
|
+
this.cbTime += time
|
|
160
|
+
if (onload) this.onloadCalled = true
|
|
161
|
+
else this.called += 1
|
|
162
|
+
if ((this.called === this.totalCbs) && (this.onloadCalled || typeof (xhr.onload) !== 'function') && typeof this.end === 'function') this.end(xhr)
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function onXhrLoadAdded (cb, useCapture) {
|
|
166
|
+
// Ignore if the same arguments are passed to addEventListener twice
|
|
167
|
+
var idString = '' + id(cb) + !!useCapture
|
|
168
|
+
if (!this.xhrGuids || this.xhrGuids[idString]) return
|
|
169
|
+
this.xhrGuids[idString] = true
|
|
170
|
+
|
|
171
|
+
this.totalCbs += 1
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
function onXhrLoadRemoved (cb, useCapture) {
|
|
175
|
+
// Ignore if event listener didn't exist for this xhr object
|
|
176
|
+
var idString = '' + id(cb) + !!useCapture
|
|
177
|
+
if (!this.xhrGuids || !this.xhrGuids[idString]) return
|
|
178
|
+
delete this.xhrGuids[idString]
|
|
179
|
+
|
|
180
|
+
this.totalCbs -= 1
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
function onXhrResolved () {
|
|
184
|
+
this.endTime = now()
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
// Listen for load listeners to be added to xhr objects
|
|
188
|
+
function onAddEventListenerEnd (args, xhr) {
|
|
189
|
+
if (xhr instanceof origXHR && args[0] === 'load') ee.emit('xhr-load-added', [args[1], args[2]], xhr)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function onRemoveEventListenerEnd (args, xhr) {
|
|
193
|
+
if (xhr instanceof origXHR && args[0] === 'load') ee.emit('xhr-load-removed', [args[1], args[2]], xhr)
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Listen for those load listeners to be called.
|
|
197
|
+
function onFnStart (args, xhr, methodName) {
|
|
198
|
+
if (xhr instanceof origXHR) {
|
|
199
|
+
if (methodName === 'onload') this.onload = true
|
|
200
|
+
if ((args[0] && args[0].type) === 'load' || this.onload) this.xhrCbStart = now()
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function onFnEnd (args, xhr) {
|
|
205
|
+
if (this.xhrCbStart) ee.emit('xhr-cb-time', [now() - this.xhrCbStart, this.onload, xhr], xhr)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
// this event only handles DT
|
|
209
|
+
function onFetchBeforeStart (args) {
|
|
210
|
+
var opts = args[1] || {}
|
|
211
|
+
var url
|
|
212
|
+
// argument is USVString
|
|
213
|
+
if (typeof args[0] === 'string') {
|
|
214
|
+
url = args[0]
|
|
215
|
+
// argument is Request object
|
|
216
|
+
} else if (args[0] && args[0].url) {
|
|
217
|
+
url = args[0].url
|
|
218
|
+
// argument is URL object
|
|
219
|
+
} else if (globalScope?.URL && args[0] && args[0] instanceof URL) {
|
|
220
|
+
url = args[0].href
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
if (url) {
|
|
224
|
+
this.parsedOrigin = parseUrl(url)
|
|
225
|
+
this.sameOrigin = this.parsedOrigin.sameOrigin
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
var payload = dt.generateTracePayload(this.parsedOrigin)
|
|
229
|
+
if (!payload || (!payload.newrelicHeader && !payload.traceContextParentHeader)) {
|
|
230
|
+
return
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (typeof args[0] === 'string' || (globalScope?.URL && args[0] && args[0] instanceof URL)) {
|
|
234
|
+
var clone = {}
|
|
235
|
+
|
|
236
|
+
for (var key in opts) {
|
|
237
|
+
clone[key] = opts[key]
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
clone.headers = new Headers(opts.headers || {})
|
|
241
|
+
if (addHeaders(clone.headers, payload)) {
|
|
242
|
+
this.dt = payload
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
if (args.length > 1) {
|
|
246
|
+
args[1] = clone
|
|
247
|
+
} else {
|
|
248
|
+
args.push(clone)
|
|
249
|
+
}
|
|
250
|
+
} else if (args[0] && args[0].headers) {
|
|
251
|
+
if (addHeaders(args[0].headers, payload)) {
|
|
252
|
+
this.dt = payload
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
function addHeaders (headersObj, payload) {
|
|
257
|
+
var added = false
|
|
258
|
+
if (payload.newrelicHeader) {
|
|
259
|
+
headersObj.set('newrelic', payload.newrelicHeader)
|
|
260
|
+
added = true
|
|
261
|
+
}
|
|
262
|
+
if (payload.traceContextParentHeader) {
|
|
263
|
+
headersObj.set('traceparent', payload.traceContextParentHeader)
|
|
264
|
+
if (payload.traceContextStateHeader) {
|
|
265
|
+
headersObj.set('tracestate', payload.traceContextStateHeader)
|
|
266
|
+
}
|
|
267
|
+
added = true
|
|
268
|
+
}
|
|
269
|
+
return added
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
function onFetchStart (fetchArguments, dtPayload) {
|
|
274
|
+
this.params = {}
|
|
275
|
+
this.metrics = {}
|
|
276
|
+
this.startTime = now()
|
|
277
|
+
this.dt = dtPayload
|
|
278
|
+
|
|
279
|
+
if (fetchArguments.length >= 1) this.target = fetchArguments[0]
|
|
280
|
+
if (fetchArguments.length >= 2) this.opts = fetchArguments[1]
|
|
281
|
+
|
|
282
|
+
var opts = this.opts || {}
|
|
283
|
+
var target = this.target
|
|
284
|
+
|
|
285
|
+
var url
|
|
286
|
+
if (typeof target === 'string') {
|
|
287
|
+
url = target
|
|
288
|
+
} else if (typeof target === 'object' && target instanceof origRequest) {
|
|
289
|
+
url = target.url
|
|
290
|
+
} else if (globalScope?.URL && typeof target === 'object' && target instanceof URL) {
|
|
291
|
+
url = target.href
|
|
292
|
+
}
|
|
293
|
+
addUrl(this, url)
|
|
294
|
+
|
|
295
|
+
var method = ('' + ((target && target instanceof origRequest && target.method) ||
|
|
296
|
+
opts.method || 'GET')).toUpperCase()
|
|
297
|
+
this.params.method = method
|
|
298
|
+
|
|
299
|
+
this.txSize = dataSize(opts.body) || 0
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
// we capture failed call as status 0, the actual error is ignored
|
|
303
|
+
// eslint-disable-next-line handle-callback-err
|
|
304
|
+
function onFetchDone (err, res) {
|
|
305
|
+
this.endTime = now()
|
|
306
|
+
if (!this.params) {
|
|
307
|
+
this.params = {}
|
|
308
|
+
}
|
|
309
|
+
this.params.status = res ? res.status : 0
|
|
310
|
+
|
|
311
|
+
// convert rxSize to a number
|
|
312
|
+
var responseSize
|
|
313
|
+
if (typeof this.rxSize === 'string' && this.rxSize.length > 0) {
|
|
314
|
+
responseSize = +this.rxSize
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
var metrics = {
|
|
318
|
+
txSize: this.txSize,
|
|
319
|
+
rxSize: responseSize,
|
|
320
|
+
duration: now() - this.startTime
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
handler('xhr', [this.params, metrics, this.startTime, this.endTime, 'fetch'], this, FEATURE_NAMES.ajax)
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
// Create report for XHR request that has finished
|
|
327
|
+
function end (xhr) {
|
|
328
|
+
var params = this.params
|
|
329
|
+
var metrics = this.metrics
|
|
330
|
+
|
|
331
|
+
if (this.ended) return
|
|
332
|
+
this.ended = true
|
|
333
|
+
|
|
334
|
+
for (var i = 0; i < handlersLen; i++) {
|
|
335
|
+
xhr.removeEventListener(handlers[i], this.listener, false)
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
if (params.aborted) return
|
|
339
|
+
metrics.duration = now() - this.startTime
|
|
340
|
+
if (!this.loadCaptureCalled && xhr.readyState === 4) {
|
|
341
|
+
captureXhrData(this, xhr)
|
|
342
|
+
} else if (params.status == null) {
|
|
343
|
+
params.status = 0
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
// Always send cbTime, even if no noticeable time was taken.
|
|
347
|
+
metrics.cbTime = this.cbTime
|
|
348
|
+
|
|
349
|
+
handler('xhr', [params, metrics, this.startTime, this.endTime, 'xhr'], this, FEATURE_NAMES.ajax)
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
function addUrl (ctx, url) {
|
|
353
|
+
var parsed = parseUrl(url)
|
|
354
|
+
var params = ctx.params
|
|
355
|
+
|
|
356
|
+
params.hostname = parsed.hostname
|
|
357
|
+
params.port = parsed.port
|
|
358
|
+
params.protocol = parsed.protocol
|
|
359
|
+
params.host = parsed.hostname + ':' + parsed.port
|
|
360
|
+
params.pathname = parsed.pathname
|
|
361
|
+
ctx.parsedOrigin = parsed
|
|
362
|
+
ctx.sameOrigin = parsed.sameOrigin
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
function captureXhrData (ctx, xhr) {
|
|
366
|
+
ctx.params.status = xhr.status
|
|
367
|
+
|
|
368
|
+
var size = responseSizeFromXhr(xhr, ctx.lastSize)
|
|
369
|
+
if (size) ctx.metrics.rxSize = size
|
|
370
|
+
|
|
371
|
+
if (ctx.sameOrigin) {
|
|
372
|
+
var header = xhr.getResponseHeader('X-NewRelic-App-Data')
|
|
373
|
+
if (header) {
|
|
374
|
+
ctx.params.cat = header.split(', ').pop()
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
ctx.loadCaptureCalled = true
|
|
379
|
+
}
|
|
380
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
import { dataSize } from '../../../common/util/data-size'
|
|
6
|
+
|
|
7
|
+
export function responseSizeFromXhr (xhr, lastSize) {
|
|
8
|
+
var type = xhr.responseType
|
|
9
|
+
if (type === 'json' && lastSize !== null) return lastSize
|
|
10
|
+
// Caution! Chrome throws an error if you try to access xhr.responseText for binary data
|
|
11
|
+
if (type === 'arraybuffer' || type === 'blob' || type === 'json') {
|
|
12
|
+
return dataSize(xhr.response)
|
|
13
|
+
} else if (type === 'text' || type === '' || type === undefined) { // empty string type defaults to 'text'
|
|
14
|
+
return dataSize(xhr.responseText)
|
|
15
|
+
} else { // e.g. ms-stream and document (we do not currently determine the size of Document objects)
|
|
16
|
+
return undefined
|
|
17
|
+
}
|
|
18
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
var canonicalFunctionNameRe = /([a-z0-9]+)$/i
|
|
7
|
+
export function canonicalFunctionName (orig) {
|
|
8
|
+
if (!orig) return
|
|
9
|
+
|
|
10
|
+
var match = orig.match(canonicalFunctionNameRe)
|
|
11
|
+
if (match) return match[1]
|
|
12
|
+
|
|
13
|
+
return
|
|
14
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { canonicalFunctionName } from './canonical-function-name'
|
|
2
|
+
|
|
3
|
+
test.each([
|
|
4
|
+
{ input: null, expected: undefined, title: 'Return undefined if no function name' },
|
|
5
|
+
{ input: 'test', expected: 'test', title: 'Simple function name' },
|
|
6
|
+
{ input: 'scope1/scope2/func', expected: 'func', title: 'Remove Firefox scopes' },
|
|
7
|
+
{ input: 'scope1.func', expected: 'func', title: 'Remove Chrome scopes' },
|
|
8
|
+
{ input: '<anonymous>', expected: undefined, title: 'Return undefined ending is non-alphanumeric' }
|
|
9
|
+
])('$title', ({ input, expected }) => {
|
|
10
|
+
const result = canonicalFunctionName(input)
|
|
11
|
+
|
|
12
|
+
expect(result).toEqual(expected)
|
|
13
|
+
})
|
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright 2020 New Relic Corporation. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/* eslint-disable no-useless-escape */
|
|
7
|
+
|
|
8
|
+
// computeStackTrace: cross-browser stack traces in JavaScript
|
|
9
|
+
//
|
|
10
|
+
// Syntax:
|
|
11
|
+
// s = computeStackTrace(exception) // consider using TraceKit.report instead
|
|
12
|
+
// Returns:
|
|
13
|
+
// s.name - exception name
|
|
14
|
+
// s.message - exception message
|
|
15
|
+
// s.stack[i].url - JavaScript or HTML file URL
|
|
16
|
+
// s.stack[i].func - function name, or empty for anonymous functions
|
|
17
|
+
// s.stack[i].line - line number, if known
|
|
18
|
+
// s.stack[i].column - column number, if known
|
|
19
|
+
// s.stack[i].context - an array of source code lines; the middle element corresponds to the correct line#
|
|
20
|
+
// s.mode - 'stack', 'stacktrace', 'multiline', 'callers', 'onerror', or 'failed' -- method used to collect the stack trace
|
|
21
|
+
//
|
|
22
|
+
// Supports:
|
|
23
|
+
// - Firefox: full stack trace with line numbers and unreliable column
|
|
24
|
+
// number on top frame
|
|
25
|
+
// - Chrome: full stack trace with line and column numbers
|
|
26
|
+
// - Safari: line and column number for the topmost stacktrace element
|
|
27
|
+
// only
|
|
28
|
+
// - IE: no line numbers whatsoever
|
|
29
|
+
|
|
30
|
+
// Contents of Exception in various browsers.
|
|
31
|
+
//
|
|
32
|
+
// SAFARI:
|
|
33
|
+
// ex.message = Can't find variable: qq
|
|
34
|
+
// ex.line = 59
|
|
35
|
+
// ex.sourceId = 580238192
|
|
36
|
+
// ex.sourceURL = http://...
|
|
37
|
+
// ex.expressionBeginOffset = 96
|
|
38
|
+
// ex.expressionCaretOffset = 98
|
|
39
|
+
// ex.expressionEndOffset = 98
|
|
40
|
+
// ex.name = ReferenceError
|
|
41
|
+
//
|
|
42
|
+
// FIREFOX:
|
|
43
|
+
// ex.message = qq is not defined
|
|
44
|
+
// ex.fileName = http://...
|
|
45
|
+
// ex.lineNumber = 59
|
|
46
|
+
// ex.stack = ...stack trace... (see the example below)
|
|
47
|
+
// ex.name = ReferenceError
|
|
48
|
+
//
|
|
49
|
+
// CHROME:
|
|
50
|
+
// ex.message = qq is not defined
|
|
51
|
+
// ex.name = ReferenceError
|
|
52
|
+
// ex.type = not_defined
|
|
53
|
+
// ex.arguments = ['aa']
|
|
54
|
+
// ex.stack = ...stack trace...
|
|
55
|
+
//
|
|
56
|
+
// INTERNET EXPLORER:
|
|
57
|
+
// ex.message = ...
|
|
58
|
+
// ex.name = ReferenceError
|
|
59
|
+
import { formatStackTrace } from './format-stack-trace'
|
|
60
|
+
|
|
61
|
+
var debug = false
|
|
62
|
+
|
|
63
|
+
var classNameRegex = /function (.+?)\s*\(/
|
|
64
|
+
var chrome = /^\s*at (?:((?:\[object object\])?(?:[^(]*\([^)]*\))*[^()]*(?: \[as \S+\])?) )?\(?((?:file|http|https|chrome-extension):.*?)?:(\d+)(?::(\d+))?\)?\s*$/i
|
|
65
|
+
var gecko = /^\s*(?:(\S*|global code)(?:\(.*?\))?@)?((?:file|http|https|chrome|safari-extension).*?):(\d+)(?::(\d+))?\s*$/i
|
|
66
|
+
var chrome_eval = /^\s*at .+ \(eval at \S+ \((?:(?:file|http|https):[^)]+)?\)(?:, [^:]*:\d+:\d+)?\)$/i
|
|
67
|
+
var ie_eval = /^\s*at Function code \(Function code:\d+:\d+\)\s*/i
|
|
68
|
+
|
|
69
|
+
export function computeStackTrace (ex) {
|
|
70
|
+
var stack = null
|
|
71
|
+
|
|
72
|
+
try {
|
|
73
|
+
stack = computeStackTraceFromStackProp(ex)
|
|
74
|
+
if (stack) {
|
|
75
|
+
return stack
|
|
76
|
+
}
|
|
77
|
+
} catch (e) {
|
|
78
|
+
if (debug) {
|
|
79
|
+
throw e
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
stack = computeStackTraceBySourceAndLine(ex)
|
|
85
|
+
if (stack) {
|
|
86
|
+
return stack
|
|
87
|
+
}
|
|
88
|
+
} catch (e) {
|
|
89
|
+
if (debug) {
|
|
90
|
+
throw e
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
try {
|
|
95
|
+
stack = computeStackTraceWithMessageOnly(ex)
|
|
96
|
+
if (stack) {
|
|
97
|
+
return stack
|
|
98
|
+
}
|
|
99
|
+
} catch (e) {
|
|
100
|
+
if (debug) {
|
|
101
|
+
throw e
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
return {
|
|
106
|
+
mode: 'failed',
|
|
107
|
+
stackString: '',
|
|
108
|
+
frames: []
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Computes stack trace information from the stack property.
|
|
114
|
+
* Chrome and Gecko use this property.
|
|
115
|
+
* @param {Error} ex
|
|
116
|
+
* @return {?Object.<string, *>} Stack trace information.
|
|
117
|
+
*/
|
|
118
|
+
function computeStackTraceFromStackProp (ex) {
|
|
119
|
+
if (!ex.stack) {
|
|
120
|
+
return null
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
var errorInfo = ex.stack.split('\n').reduce(
|
|
124
|
+
parseStackProp,
|
|
125
|
+
{ frames: [], stackLines: [], wrapperSeen: false }
|
|
126
|
+
)
|
|
127
|
+
|
|
128
|
+
if (!errorInfo.frames.length) return null
|
|
129
|
+
|
|
130
|
+
return {
|
|
131
|
+
mode: 'stack',
|
|
132
|
+
name: ex.name || getClassName(ex),
|
|
133
|
+
message: ex.message,
|
|
134
|
+
stackString: formatStackTrace(errorInfo.stackLines),
|
|
135
|
+
frames: errorInfo.frames
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
function parseStackProp (info, line) {
|
|
140
|
+
var element = getElement(line)
|
|
141
|
+
|
|
142
|
+
if (!element) {
|
|
143
|
+
info.stackLines.push(line)
|
|
144
|
+
return info
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (isWrapper(element.func)) info.wrapperSeen = true
|
|
148
|
+
else info.stackLines.push(line)
|
|
149
|
+
|
|
150
|
+
if (!info.wrapperSeen) info.frames.push(element)
|
|
151
|
+
return info
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function getElement (line) {
|
|
155
|
+
var parts = line.match(gecko)
|
|
156
|
+
if (!parts) parts = line.match(chrome)
|
|
157
|
+
|
|
158
|
+
if (parts) {
|
|
159
|
+
return ({
|
|
160
|
+
url: parts[2],
|
|
161
|
+
func: (parts[1] !== 'Anonymous function' && parts[1] !== 'global code' && parts[1]) || null,
|
|
162
|
+
line: +parts[3],
|
|
163
|
+
column: parts[4] ? +parts[4] : null
|
|
164
|
+
})
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
if (line.match(chrome_eval) || line.match(ie_eval) || line === 'anonymous') {
|
|
168
|
+
return { func: 'evaluated code' }
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
function computeStackTraceBySourceAndLine (ex) {
|
|
173
|
+
if (!('line' in ex)) return null
|
|
174
|
+
|
|
175
|
+
var className = ex.name || getClassName(ex)
|
|
176
|
+
|
|
177
|
+
// Safari does not provide a URL for errors in eval'd code
|
|
178
|
+
if (!ex.sourceURL) {
|
|
179
|
+
return ({
|
|
180
|
+
mode: 'sourceline',
|
|
181
|
+
name: className,
|
|
182
|
+
message: ex.message,
|
|
183
|
+
stackString: getClassName(ex) + ': ' + ex.message + '\n in evaluated code',
|
|
184
|
+
frames: [{
|
|
185
|
+
func: 'evaluated code'
|
|
186
|
+
}]
|
|
187
|
+
})
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
var stackString = className + ': ' + ex.message + '\n at ' + ex.sourceURL
|
|
191
|
+
if (ex.line) {
|
|
192
|
+
stackString += ':' + ex.line
|
|
193
|
+
if (ex.column) {
|
|
194
|
+
stackString += ':' + ex.column
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
return ({
|
|
199
|
+
mode: 'sourceline',
|
|
200
|
+
name: className,
|
|
201
|
+
message: ex.message,
|
|
202
|
+
stackString: stackString,
|
|
203
|
+
frames: [{
|
|
204
|
+
url: ex.sourceURL,
|
|
205
|
+
line: ex.line,
|
|
206
|
+
column: ex.column
|
|
207
|
+
}]
|
|
208
|
+
})
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
function computeStackTraceWithMessageOnly (ex) {
|
|
212
|
+
var className = ex.name || getClassName(ex)
|
|
213
|
+
if (!className) return null
|
|
214
|
+
|
|
215
|
+
return ({
|
|
216
|
+
mode: 'nameonly',
|
|
217
|
+
name: className,
|
|
218
|
+
message: ex.message,
|
|
219
|
+
stackString: className + ': ' + ex.message,
|
|
220
|
+
frames: []
|
|
221
|
+
})
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
function getClassName (obj) {
|
|
225
|
+
var results = classNameRegex.exec(String(obj.constructor))
|
|
226
|
+
return (results && results.length > 1) ? results[1] : 'unknown'
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
function isWrapper (functionName) {
|
|
230
|
+
return (functionName && functionName.indexOf('nrWrapper') >= 0)
|
|
231
|
+
}
|