@newrelic/browser-agent 1.320.1 → 1.321.0
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/CHANGELOG.md +15 -0
- package/dist/cjs/common/config/runtime.js +3 -0
- package/dist/cjs/common/constants/env.cdn.js +1 -1
- package/dist/cjs/common/constants/env.npm.js +1 -1
- package/dist/cjs/common/dom/selector-path.js +1 -1
- package/dist/cjs/common/event-listener/event-listener-opts.js +1 -1
- package/dist/cjs/common/harvest/connector.js +202 -0
- package/dist/cjs/common/harvest/harvester.js +5 -8
- package/dist/cjs/common/harvest/send.js +8 -7
- package/dist/cjs/common/session/session-entity.js +1 -1
- package/dist/cjs/common/timer/interaction-timer.js +2 -2
- package/dist/cjs/common/unload/eol.js +3 -3
- package/dist/cjs/common/util/console.js +2 -1
- package/dist/cjs/common/util/feature-flags.js +2 -1
- package/dist/cjs/common/v2/constants.js +21 -0
- package/dist/cjs/common/v2/utils.js +25 -23
- package/dist/cjs/common/window/page-visibility.js +1 -1
- package/dist/cjs/common/wrap/wrap-events.js +4 -3
- package/dist/cjs/common/wrap/wrap-fetch.js +2 -2
- package/dist/cjs/common/wrap/wrap-function.js +1 -1
- package/dist/cjs/common/wrap/wrap-history.js +3 -2
- package/dist/cjs/common/wrap/wrap-xhr.js +2 -2
- package/dist/cjs/features/ajax/aggregate/index.js +1 -1
- package/dist/cjs/features/generic_events/aggregate/index.js +1 -1
- package/dist/cjs/features/generic_events/instrument/index.js +1 -1
- package/dist/cjs/features/jserrors/aggregate/index.js +5 -5
- package/dist/cjs/features/logging/instrument/index.js +1 -1
- package/dist/cjs/features/page_view_event/aggregate/index.js +2 -6
- package/dist/cjs/features/page_view_event/aggregate_v2/index.js +109 -0
- package/dist/cjs/features/page_view_event/instrument/index.js +6 -1
- package/dist/cjs/features/page_view_timing/aggregate/index.js +5 -1
- package/dist/cjs/features/session_replay/instrument/index.js +9 -0
- package/dist/cjs/features/session_replay/shared/recorder.js +2 -1
- package/dist/cjs/features/session_replay/shared/utils.js +3 -5
- package/dist/cjs/features/session_trace/instrument/index.js +3 -3
- package/dist/cjs/features/soft_navigations/instrument/index.js +2 -2
- package/dist/cjs/features/utils/aggregate-base.js +0 -12
- package/dist/cjs/features/utils/instrument-base.js +72 -29
- package/dist/cjs/loaders/agent.js +2 -1
- package/dist/cjs/loaders/api/consent.js +2 -2
- package/dist/cjs/loaders/api/register.js +26 -13
- package/dist/cjs/loaders/configure/configure.js +14 -0
- package/dist/cjs/loaders/features/features.js +2 -1
- package/dist/esm/common/config/runtime.js +3 -0
- package/dist/esm/common/constants/env.cdn.js +1 -1
- package/dist/esm/common/constants/env.npm.js +1 -1
- package/dist/esm/common/dom/selector-path.js +1 -1
- package/dist/esm/common/event-listener/event-listener-opts.js +1 -1
- package/dist/esm/common/harvest/connector.js +195 -0
- package/dist/esm/common/harvest/harvester.js +5 -8
- package/dist/esm/common/harvest/send.js +10 -9
- package/dist/esm/common/session/session-entity.js +1 -1
- package/dist/esm/common/timer/interaction-timer.js +2 -2
- package/dist/esm/common/unload/eol.js +3 -3
- package/dist/esm/common/util/console.js +2 -1
- package/dist/esm/common/util/feature-flags.js +2 -1
- package/dist/esm/common/v2/constants.js +15 -0
- package/dist/esm/common/v2/utils.js +24 -22
- package/dist/esm/common/window/page-visibility.js +1 -1
- package/dist/esm/common/wrap/wrap-events.js +4 -3
- package/dist/esm/common/wrap/wrap-fetch.js +2 -2
- package/dist/esm/common/wrap/wrap-function.js +1 -1
- package/dist/esm/common/wrap/wrap-history.js +3 -2
- package/dist/esm/common/wrap/wrap-xhr.js +2 -2
- package/dist/esm/features/ajax/aggregate/index.js +2 -2
- package/dist/esm/features/generic_events/aggregate/index.js +1 -1
- package/dist/esm/features/generic_events/instrument/index.js +1 -1
- package/dist/esm/features/jserrors/aggregate/index.js +6 -6
- package/dist/esm/features/logging/instrument/index.js +1 -1
- package/dist/esm/features/page_view_event/aggregate/index.js +2 -6
- package/dist/esm/features/page_view_event/aggregate_v2/index.js +100 -0
- package/dist/esm/features/page_view_event/instrument/index.js +6 -1
- package/dist/esm/features/page_view_timing/aggregate/index.js +5 -1
- package/dist/esm/features/session_replay/instrument/index.js +9 -0
- package/dist/esm/features/session_replay/shared/recorder.js +2 -1
- package/dist/esm/features/session_replay/shared/utils.js +3 -5
- package/dist/esm/features/session_trace/instrument/index.js +3 -3
- package/dist/esm/features/soft_navigations/instrument/index.js +2 -2
- package/dist/esm/features/utils/aggregate-base.js +0 -12
- package/dist/esm/features/utils/instrument-base.js +71 -28
- package/dist/esm/loaders/agent.js +2 -1
- package/dist/esm/loaders/api/consent.js +2 -2
- package/dist/esm/loaders/api/register.js +19 -6
- package/dist/esm/loaders/configure/configure.js +14 -0
- package/dist/esm/loaders/features/features.js +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/common/config/runtime.d.ts.map +1 -1
- package/dist/types/common/event-listener/event-listener-opts.d.ts +1 -1
- package/dist/types/common/harvest/connector.d.ts +6 -0
- package/dist/types/common/harvest/connector.d.ts.map +1 -0
- package/dist/types/common/harvest/harvester.d.ts.map +1 -1
- package/dist/types/common/harvest/send.d.ts.map +1 -1
- package/dist/types/common/unload/eol.d.ts +1 -1
- package/dist/types/common/unload/eol.d.ts.map +1 -1
- package/dist/types/common/util/console.d.ts +2 -1
- package/dist/types/common/util/console.d.ts.map +1 -1
- package/dist/types/common/v2/constants.d.ts +9 -0
- package/dist/types/common/v2/constants.d.ts.map +1 -0
- package/dist/types/common/v2/utils.d.ts +36 -11
- package/dist/types/common/v2/utils.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-events.d.ts +2 -1
- package/dist/types/common/wrap/wrap-events.d.ts.map +1 -1
- package/dist/types/common/wrap/wrap-history.d.ts +2 -1
- package/dist/types/common/wrap/wrap-history.d.ts.map +1 -1
- package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/page_view_event/aggregate_v2/index.d.ts +20 -0
- package/dist/types/features/page_view_event/aggregate_v2/index.d.ts.map +1 -0
- package/dist/types/features/page_view_event/instrument/index.d.ts.map +1 -1
- package/dist/types/features/page_view_timing/aggregate/index.d.ts.map +1 -1
- package/dist/types/features/session_replay/instrument/index.d.ts +1 -0
- package/dist/types/features/session_replay/instrument/index.d.ts.map +1 -1
- package/dist/types/features/session_replay/shared/recorder.d.ts.map +1 -1
- package/dist/types/features/session_replay/shared/utils.d.ts.map +1 -1
- package/dist/types/features/session_trace/instrument/index.d.ts.map +1 -1
- package/dist/types/features/utils/aggregate-base.d.ts +0 -5
- package/dist/types/features/utils/aggregate-base.d.ts.map +1 -1
- package/dist/types/features/utils/instrument-base.d.ts.map +1 -1
- package/dist/types/loaders/agent.d.ts.map +1 -1
- package/dist/types/loaders/api/register.d.ts.map +1 -1
- package/dist/types/loaders/configure/configure.d.ts.map +1 -1
- package/dist/types/loaders/features/features.d.ts +1 -0
- package/dist/types/loaders/features/features.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/common/config/runtime.js +3 -0
- package/src/common/dom/selector-path.js +1 -1
- package/src/common/event-listener/event-listener-opts.js +1 -1
- package/src/common/harvest/connector.js +170 -0
- package/src/common/harvest/harvester.js +7 -9
- package/src/common/harvest/send.js +9 -7
- package/src/common/session/session-entity.js +1 -1
- package/src/common/timer/interaction-timer.js +2 -2
- package/src/common/unload/eol.js +3 -3
- package/src/common/util/console.js +2 -1
- package/src/common/util/feature-flags.js +1 -1
- package/src/common/v2/constants.js +15 -0
- package/src/common/v2/utils.js +23 -21
- package/src/common/window/page-visibility.js +1 -1
- package/src/common/wrap/wrap-events.js +4 -3
- package/src/common/wrap/wrap-fetch.js +2 -2
- package/src/common/wrap/wrap-function.js +1 -1
- package/src/common/wrap/wrap-history.js +3 -2
- package/src/common/wrap/wrap-xhr.js +2 -2
- package/src/features/ajax/aggregate/index.js +2 -2
- package/src/features/generic_events/aggregate/index.js +1 -1
- package/src/features/generic_events/instrument/index.js +1 -1
- package/src/features/jserrors/aggregate/index.js +6 -6
- package/src/features/logging/instrument/index.js +1 -1
- package/src/features/page_view_event/aggregate/index.js +2 -6
- package/src/features/page_view_event/aggregate_v2/index.js +97 -0
- package/src/features/page_view_event/instrument/index.js +6 -1
- package/src/features/page_view_timing/aggregate/index.js +5 -1
- package/src/features/session_replay/instrument/index.js +9 -0
- package/src/features/session_replay/shared/recorder.js +2 -1
- package/src/features/session_replay/shared/utils.js +3 -5
- package/src/features/session_trace/instrument/index.js +3 -3
- package/src/features/soft_navigations/instrument/index.js +2 -2
- package/src/features/utils/aggregate-base.js +0 -12
- package/src/features/utils/instrument-base.js +71 -25
- package/src/loaders/agent.js +2 -1
- package/src/loaders/api/consent.js +2 -2
- package/src/loaders/api/register.js +16 -6
- package/src/loaders/configure/configure.js +12 -0
- package/src/loaders/features/features.js +1 -0
- package/dist/cjs/common/url/location.js +0 -18
- package/dist/esm/common/url/location.js +0 -12
- package/dist/types/common/url/location.d.ts +0 -10
- package/dist/types/common/url/location.d.ts.map +0 -1
- package/src/common/url/__mocks__/location.js +0 -5
- package/src/common/url/location.js +0 -12
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../src/features/session_replay/shared/utils.js"],"names":[],"mappings":"AAOA,+DAIC;AAED,0DAEC;AAED,
|
|
1
|
+
{"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../../../src/features/session_replay/shared/utils.js"],"names":[],"mappings":"AAOA,+DAIC;AAED,0DAEC;AAED,2DAQC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/session_trace/instrument/index.js"],"names":[],"mappings":"AAmBA;IACE,2BAAiC;IACjC,2BA+CC;IAhCC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/session_trace/instrument/index.js"],"names":[],"mappings":"AAmBA;IACE,2BAAiC;IACjC,2BA+CC;IAhCC,6BAAsD;CAiCzD;AAED,6CAAsC;+BAhEP,6BAA6B"}
|
|
@@ -58,11 +58,6 @@ export class AggregateBase extends FeatureBase {
|
|
|
58
58
|
sent?: boolean | undefined;
|
|
59
59
|
retry?: boolean | undefined;
|
|
60
60
|
}): void;
|
|
61
|
-
/**
|
|
62
|
-
* These are actions related to shared resources that should be initialized once by whichever feature Aggregate subclass loads first.
|
|
63
|
-
* This method should run after checkConfiguration, which may reset the agent's info/runtime object that is used here.
|
|
64
|
-
*/
|
|
65
|
-
doOnceForAllAggregate(agentRef: any): void;
|
|
66
61
|
/**
|
|
67
62
|
* Report a supportability metric
|
|
68
63
|
* @param {*} metricName The tag of the name matching the Angler aggregation tag
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aggregate-base.d.ts","sourceRoot":"","sources":["../../../../src/features/utils/aggregate-base.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"aggregate-base.d.ts","sourceRoot":"","sources":["../../../../src/features/utils/aggregate-base.js"],"names":[],"mappings":"AAcA;IACE;;;;OAIG;IACH,sBAHW,MAAM,eACN,MAAM,EAiBhB;IAZC,uOAAuO;IACvO,qCAAwC;IACxC,gLAAgL;IAChL,yBAA2B;IAC3B,sFAAsF;IACtF,oBAAuB;IAEvB,gBAAqB;IAqBjB,YAAsE;IAW5E,iNAAiN;IACjN,0CAEC;IAED;;;;OAIG;IACH,8BAHU,MAAM,CAKf;IAED,qBAOC;IAFG,6BAAmB;IAIvB;;;;OAIG;IACH,2BAOC;IAED;;;;OAIG;IACH,yBAHW,MAAM,EAAE,gBAyBlB;IAED;;OAEG;IACH,cAEC;IAED,qCAEC;IAED;;;;;;OAMG;IACH,uDAJW,MAAM,GAAC,SAAS,SAsB1B;IAED;;;;;OAKG;IACH,4BAHG;QAAyB,IAAI,GAArB,OAAO,YAAC;QACS,KAAK,GAAtB,OAAO,YAAC;KAClB,QAKA;IAED;;;;OAIG;IACH,uCAHW,GAAC,UACD,GAAC,QAIX;;CACF;4BAtL2B,gBAAgB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"instrument-base.d.ts","sourceRoot":"","sources":["../../../../src/features/utils/instrument-base.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"instrument-base.d.ts","sourceRoot":"","sources":["../../../../src/features/utils/instrument-base.js"],"names":[],"mappings":"AA6BA;;;GAGG;AACH;IACE;;;;OAIG;IACH,sBAHW,MAAM,eACN,MAAM,EA0ChB;IArCC,8IAA8I;IAC9I,cADW,WAAW,SAAS,CACF;IAE7B;;;MAGE;IACF,eAHU,OAAO,kBAAkB,EAAE,aAAa,CAGpB;IAE9B;;;MAGE;IACF,iCAAmC;IACnC,kCAEE;IAEF;;;MAGE;IACF,uBAAiC;IAiBnC;;;;;;;OAOG;IACH,2BALW,MAAM,qDAEN,MAAM,QA2DhB;;CAiDF;4BAtL2B,gBAAgB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../../src/loaders/agent.js"],"names":[],"mappings":"AA2BA;;;;;;;;;GASG;AAEH;;;GAGG;AACH;IACE;;OAEG;IACH,qBAFW,YAAY,EA+BtB;IAnBC,yBAAkB;IAGlB,yCAAsD;IAkBxD;;;;;MAOC;IAED,gBAEC;IAED,
|
|
1
|
+
{"version":3,"file":"agent.d.ts","sourceRoot":"","sources":["../../../src/loaders/agent.js"],"names":[],"mappings":"AA2BA;;;;;;;;;GASG;AAEH;;;GAGG;AACH;IACE;;OAEG;IACH,qBAFW,YAAY,EA+BtB;IAnBC,yBAAkB;IAGlB,yCAAsD;IAkBxD;;;;;MAOC;IAED,gBAEC;IAED,yBAoCC;CACF;;;;;UAlGa,OAAO,uBAAuB,EAAE,IAAI;;;;;;;;;;;;;;;;;;;;;;;;;;0BApBxB,cAAc"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../../../src/loaders/api/register.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../../../src/loaders/api/register.js"],"names":[],"mappings":"AAqDA;;;;GAIG;AACH,mDAIC;;;;;;;0BArCY,OAAO,sBAAsB,EAAE,WAAW"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configure.d.ts","sourceRoot":"","sources":["../../../../src/loaders/configure/configure.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"configure.d.ts","sourceRoot":"","sources":["../../../../src/loaders/configure/configure.js"],"names":[],"mappings":"AAkBA;;;GAGG;AACH,oGAyFC"}
|
|
@@ -6,6 +6,7 @@ export const EVENTS: "events";
|
|
|
6
6
|
export const JSERRORS: "jserrors";
|
|
7
7
|
export const BLOBS: "browser/blobs";
|
|
8
8
|
export const RUM: "rum";
|
|
9
|
+
export const CONNECT: "connect";
|
|
9
10
|
export const LOGS: "browser/logs";
|
|
10
11
|
export namespace FEATURE_NAMES {
|
|
11
12
|
export let ajax: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"features.d.ts","sourceRoot":"","sources":["../../../../src/loaders/features/features.js"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,qBAAsB,QAAQ,CAAA;AAC9B,uBAAwB,UAAU,CAAA;AAClC,oBAAqB,eAAe,CAAA;AACpC,kBAAmB,KAAK,CAAA;AACxB,mBAAoB,cAAc,CAAA;;;;;;;;;;;;;;AAmBlC;;;GAGG;AACH;IACE,CAAC,aAAa,CAAC,aAAa,CAAC,SAAG;IAChC,CAAC,aAAa,CAAC,cAAc,CAAC,SAAG;IACjC,CAAC,aAAa,CAAC,OAAO,CAAC,SAAG;IAC1B,CAAC,aAAa,CAAC,QAAQ,CAAC,SAAG;IAC3B,CAAC,aAAa,CAAC,OAAO,CAAC,SAAG;IAC1B,CAAC,aAAa,CAAC,IAAI,CAAC,SAAG;IACvB,CAAC,aAAa,CAAC,YAAY,CAAC,SAAG;IAC/B,CAAC,aAAa,CAAC,aAAa,CAAC,SAAG;IAChC,CAAC,aAAa,CAAC,OAAO,CAAC,SAAG;IAC1B,CAAC,aAAa,CAAC,aAAa,CAAC,SAAI;EAClC;AAED;IACE,CAAC,aAAa,CAAC,aAAa,CAAC,SAAK;IAClC,CAAC,aAAa,CAAC,cAAc,CAAC,SAAQ;IACtC,CAAC,aAAa,CAAC,IAAI,CAAC,SAAQ;IAC5B,CAAC,aAAa,CAAC,OAAO,CAAC,SAAQ;IAC/B,CAAC,aAAa,CAAC,OAAO,CAAC,SAAU;IACjC,CAAC,aAAa,CAAC,QAAQ,CAAC,SAAU;IAClC,CAAC,aAAa,CAAC,YAAY,CAAC,SAAO;IACnC,CAAC,aAAa,CAAC,aAAa,CAAC,SAAO;IACpC,CAAC,aAAa,CAAC,OAAO,CAAC,SAAM;IAC7B,CAAC,aAAa,CAAC,aAAa,CAAC,SAAO;EACrC"}
|
|
1
|
+
{"version":3,"file":"features.d.ts","sourceRoot":"","sources":["../../../../src/loaders/features/features.js"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,qBAAsB,QAAQ,CAAA;AAC9B,uBAAwB,UAAU,CAAA;AAClC,oBAAqB,eAAe,CAAA;AACpC,kBAAmB,KAAK,CAAA;AACxB,sBAAuB,SAAS,CAAA;AAChC,mBAAoB,cAAc,CAAA;;;;;;;;;;;;;;AAmBlC;;;GAGG;AACH;IACE,CAAC,aAAa,CAAC,aAAa,CAAC,SAAG;IAChC,CAAC,aAAa,CAAC,cAAc,CAAC,SAAG;IACjC,CAAC,aAAa,CAAC,OAAO,CAAC,SAAG;IAC1B,CAAC,aAAa,CAAC,QAAQ,CAAC,SAAG;IAC3B,CAAC,aAAa,CAAC,OAAO,CAAC,SAAG;IAC1B,CAAC,aAAa,CAAC,IAAI,CAAC,SAAG;IACvB,CAAC,aAAa,CAAC,YAAY,CAAC,SAAG;IAC/B,CAAC,aAAa,CAAC,aAAa,CAAC,SAAG;IAChC,CAAC,aAAa,CAAC,OAAO,CAAC,SAAG;IAC1B,CAAC,aAAa,CAAC,aAAa,CAAC,SAAI;EAClC;AAED;IACE,CAAC,aAAa,CAAC,aAAa,CAAC,SAAK;IAClC,CAAC,aAAa,CAAC,cAAc,CAAC,SAAQ;IACtC,CAAC,aAAa,CAAC,IAAI,CAAC,SAAQ;IAC5B,CAAC,aAAa,CAAC,OAAO,CAAC,SAAQ;IAC/B,CAAC,aAAa,CAAC,OAAO,CAAC,SAAU;IACjC,CAAC,aAAa,CAAC,QAAQ,CAAC,SAAU;IAClC,CAAC,aAAa,CAAC,YAAY,CAAC,SAAO;IACnC,CAAC,aAAa,CAAC,aAAa,CAAC,SAAO;IACpC,CAAC,aAAa,CAAC,OAAO,CAAC,SAAM;IAC7B,CAAC,aAAa,CAAC,aAAa,CAAC,SAAO;EACrC"}
|
package/package.json
CHANGED
|
@@ -41,7 +41,10 @@ const RuntimeModel = {
|
|
|
41
41
|
disabled: false,
|
|
42
42
|
/** @type {Map<string, {staged: boolean, priority: number}>} */
|
|
43
43
|
drainRegistry: new Map(),
|
|
44
|
+
connector: undefined,
|
|
44
45
|
harvester: undefined,
|
|
46
|
+
/** eagerly-created in configure() -- the v2 target representing the container (main) agent, see common/v2/utils#V2Target */
|
|
47
|
+
v2Target: undefined,
|
|
45
48
|
isolatedBacklog: false,
|
|
46
49
|
isRecording: false, // true when actively recording, false when paused or stopped
|
|
47
50
|
loaderType: undefined,
|
|
@@ -18,7 +18,7 @@ import { getRegisteredTargetsFromId } from '../v2/utils'
|
|
|
18
18
|
*/
|
|
19
19
|
export const analyzeElemPath = (elem, targetFields = [], agentRef) => {
|
|
20
20
|
const targets = []
|
|
21
|
-
const result = { path: undefined, nearestFields: {}, get targets () { return targets.length ? targets : [
|
|
21
|
+
const result = { path: undefined, nearestFields: {}, get targets () { return targets.length ? targets : [agentRef.runtime.v2Target] }, hasButton: false, hasLink: false }
|
|
22
22
|
if (!elem) return result
|
|
23
23
|
if (elem === window) { result.path = 'window'; return result }
|
|
24
24
|
if (elem === document) { result.path = 'document'; return result }
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2020-2026 New Relic, Inc. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { isBrowserScope } from '../constants/runtime'
|
|
7
|
+
import { send } from './send'
|
|
8
|
+
import { TimeKeeper } from '../timing/time-keeper'
|
|
9
|
+
import { activateFeatures } from '../util/feature-flags'
|
|
10
|
+
import { now } from '../timing/now'
|
|
11
|
+
import { warn } from '../util/console'
|
|
12
|
+
import { VERSION } from '../constants/env'
|
|
13
|
+
import { CONNECT, FEATURE_NAMES, FEATURE_TO_ENDPOINT } from '../../loaders/features/features'
|
|
14
|
+
import { handle } from '../event-emitter/handle'
|
|
15
|
+
import { SUPPORTABILITY_METRIC_CHANNEL } from '../../features/metrics/constants'
|
|
16
|
+
|
|
17
|
+
const MAX_CONNECT_ATTEMPTS = 3
|
|
18
|
+
const CONNECT_RETRY_BASE_MS = 3000 // affects each retry window proportionally (attempt 2: 0-3s, 3: 0-6s, 4: 0-12s, etc)
|
|
19
|
+
|
|
20
|
+
export class Connector {
|
|
21
|
+
#agentRef
|
|
22
|
+
#connectStartTime
|
|
23
|
+
#numOfAttempts = 0
|
|
24
|
+
|
|
25
|
+
constructor (agentRef) {
|
|
26
|
+
if (!agentRef.init.feature_flags.includes('rum_v2')) return // the Connector does not run in v1; legacy PVE has its own BCS handling
|
|
27
|
+
this.#agentRef = agentRef
|
|
28
|
+
agentRef.runtime.timeKeeper = new TimeKeeper(agentRef.runtime.session)
|
|
29
|
+
|
|
30
|
+
if (isBrowserScope) {
|
|
31
|
+
const cached = agentRef.runtime.session && agentRef.runtime.session.state.cachedRumResponse
|
|
32
|
+
if (cached) {
|
|
33
|
+
// `cachedRumResponse` is stored flat (`{ app, ...flags }`, matching the old v1 RUM response), so re-nest it before applying.
|
|
34
|
+
const { app, ...config } = cached
|
|
35
|
+
this.#applyConnectResponse({ app, config })
|
|
36
|
+
return
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
this.makeConnectRequest()
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
makeConnectRequest (retryHeaders) {
|
|
43
|
+
this.#connectStartTime = now()
|
|
44
|
+
return send(this.#agentRef, {
|
|
45
|
+
endpoint: `browser/connect/2/${this.#agentRef.info.licenseKey}`,
|
|
46
|
+
payload: {
|
|
47
|
+
body: {},
|
|
48
|
+
qs: {
|
|
49
|
+
a: this.#agentRef.info.applicationID,
|
|
50
|
+
v: VERSION,
|
|
51
|
+
s: this.#agentRef.runtime.session?.state.value || '0'
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
localOpts: { sendEmptyBody: true, headers: retryHeaders },
|
|
55
|
+
raw: true,
|
|
56
|
+
featureName: CONNECT,
|
|
57
|
+
cbFinished: this.#processConnectResponse.bind(this)
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
#applyConnectResponse ({ app, config }) {
|
|
62
|
+
if (!Object.keys(this.#agentRef.runtime.appMetadata).length) this.#agentRef.runtime.appMetadata = app
|
|
63
|
+
activateFeatures(config, this.#agentRef)
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
#processConnectResponse ({ sent, status, retry, xhr, responseText }) {
|
|
67
|
+
const connectEndTime = now()
|
|
68
|
+
const session = this.#agentRef.runtime.session
|
|
69
|
+
|
|
70
|
+
if (session) {
|
|
71
|
+
// Double check that there isn't a response saved (e.g. from another agent/browser tab) btwn the async time of the request and now in a race-condition.
|
|
72
|
+
const cachedResp = session.state.cachedRumResponse
|
|
73
|
+
if (cachedResp) {
|
|
74
|
+
// Report that we've seen a race condition on updating session state
|
|
75
|
+
handle(SUPPORTABILITY_METRIC_CHANNEL, ['Session/RaceCondition/Seen'], undefined, FEATURE_NAMES.metrics, this.#agentRef.ee)
|
|
76
|
+
// `cachedRumResponse` is stored flat (`{ app, ...flags }`, matching the old v1 RUM response), so re-nest it before applying.
|
|
77
|
+
const { app, ...config } = cachedResp
|
|
78
|
+
this.#applyConnectResponse({ app, config })
|
|
79
|
+
return
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
const shouldRetry = sent && retry // important to note: no retry if HTTP status is 0
|
|
84
|
+
if (shouldRetry && ++this.#numOfAttempts < MAX_CONNECT_ATTEMPTS) {
|
|
85
|
+
// We use an exponential backoff calculation for the retry to avoid thundering herd, skipping any further processing.
|
|
86
|
+
const delay = Math.floor(Math.random() * CONNECT_RETRY_BASE_MS * (2 ** (this.#numOfAttempts - 1)))
|
|
87
|
+
const retryHeaders = [
|
|
88
|
+
{ key: 'X-Retry-Count', value: this.#numOfAttempts },
|
|
89
|
+
{ key: 'X-Previous-Status', value: status }
|
|
90
|
+
]
|
|
91
|
+
setTimeout(() => this.makeConnectRequest(retryHeaders), delay)
|
|
92
|
+
return
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (status >= 400 || status === 0) {
|
|
96
|
+
warn(18, status)
|
|
97
|
+
|
|
98
|
+
// Get estimated payload size of our backlog.
|
|
99
|
+
const textEncoder = new TextEncoder()
|
|
100
|
+
const payloadSize = Object.values(newrelic.ee.backlog).reduce((acc, value) => {
|
|
101
|
+
if (!value) return acc
|
|
102
|
+
const encoded = textEncoder.encode(value)
|
|
103
|
+
return acc + encoded.byteLength
|
|
104
|
+
}, 0)
|
|
105
|
+
|
|
106
|
+
// Send SMs about the (last) failed connect request, then abort agent.
|
|
107
|
+
const BCSError = 'BCS/Error/'
|
|
108
|
+
const sm = [{
|
|
109
|
+
params: {
|
|
110
|
+
name: BCSError + status
|
|
111
|
+
},
|
|
112
|
+
stats: {
|
|
113
|
+
c: 1
|
|
114
|
+
}
|
|
115
|
+
}, {
|
|
116
|
+
params: {
|
|
117
|
+
name: BCSError + 'Duration/Ms'
|
|
118
|
+
},
|
|
119
|
+
stats: {
|
|
120
|
+
c: 1,
|
|
121
|
+
t: connectEndTime - this.#connectStartTime
|
|
122
|
+
}
|
|
123
|
+
}, {
|
|
124
|
+
params: {
|
|
125
|
+
name: BCSError + 'Dropped/Bytes'
|
|
126
|
+
},
|
|
127
|
+
stats: {
|
|
128
|
+
c: 1,
|
|
129
|
+
t: payloadSize
|
|
130
|
+
}
|
|
131
|
+
}]
|
|
132
|
+
send(this.#agentRef, { // note we have to send it this way because the Metrics feature will never be harvested under this branch of code (BCS failure)
|
|
133
|
+
endpoint: FEATURE_TO_ENDPOINT[FEATURE_NAMES.metrics],
|
|
134
|
+
payload: { body: { sm } },
|
|
135
|
+
featureName: FEATURE_NAMES.metrics
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
this.#agentRef.ee.abort()
|
|
139
|
+
return
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
let resp
|
|
143
|
+
try {
|
|
144
|
+
resp = JSON.parse(responseText)
|
|
145
|
+
} catch (error) {
|
|
146
|
+
warn(53, error)
|
|
147
|
+
this.#agentRef.ee.abort()
|
|
148
|
+
return
|
|
149
|
+
}
|
|
150
|
+
// store the response for other pages later in same session or in parallel tabs; flatten `.config` into the old v1 RUM response shape
|
|
151
|
+
if (session) session.write({ cachedRumResponse: { app: resp.app, ...resp.config } })
|
|
152
|
+
try {
|
|
153
|
+
const wasReady = this.#agentRef.runtime.timeKeeper.ready
|
|
154
|
+
this.#agentRef.runtime.timeKeeper.processRumRequest(xhr, this.#connectStartTime, connectEndTime, resp.app.nrServerTime)
|
|
155
|
+
if (!this.#agentRef.runtime.timeKeeper.ready) throw new Error('TimeKeeper not ready')
|
|
156
|
+
|
|
157
|
+
// If timeKeeper's origin time is ahead of nrServerTime, then the timestamp is invalid. Report a supportability metric.
|
|
158
|
+
const timeDiff = this.#agentRef.runtime.timeKeeper.correctedOriginTime - resp.app.nrServerTime
|
|
159
|
+
if (wasReady && timeDiff > 0) {
|
|
160
|
+
handle(SUPPORTABILITY_METRIC_CHANNEL, ['Generic/TimeKeeper/InvalidTimestamp/Seen', timeDiff], undefined, FEATURE_NAMES.metrics, this.#agentRef.ee)
|
|
161
|
+
}
|
|
162
|
+
} catch (error) {
|
|
163
|
+
warn(17, error)
|
|
164
|
+
this.#agentRef.ee.abort()
|
|
165
|
+
return
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
this.#applyConnectResponse(resp)
|
|
169
|
+
}
|
|
170
|
+
}
|
|
@@ -22,23 +22,21 @@ export class Harvester {
|
|
|
22
22
|
constructor (agentRef) {
|
|
23
23
|
this.agentRef = agentRef
|
|
24
24
|
|
|
25
|
-
// Create obfuscator for harvest metadata (referrer URL, etc.)
|
|
26
25
|
// No event type specified - applies to all harvests regardless of feature
|
|
27
26
|
this.obfuscator = new Obfuscator(agentRef)
|
|
28
|
-
|
|
29
|
-
subscribeToEOL(() => { // do one last harvest round or check
|
|
30
|
-
this.initializedAggregates.forEach(aggregateInst => { // let all features wrap up things needed to do before ANY harvest in case there's last minute cross-feature data dependencies
|
|
31
|
-
if (typeof aggregateInst.harvestOpts.beforeUnload === 'function') aggregateInst.harvestOpts.beforeUnload()
|
|
32
|
-
})
|
|
33
|
-
this.initializedAggregates.forEach(aggregateInst => this.triggerHarvestFor(aggregateInst, { isFinalHarvest: true }))
|
|
34
|
-
/* This callback should run in bubble phase, so that CWV api, like "onLCP", is called before the final harvest so that emitted timings are part of last outgoing. */
|
|
35
|
-
}, false)
|
|
36
27
|
}
|
|
37
28
|
|
|
38
29
|
startTimer (harvestInterval = this.agentRef.init.harvest.interval) {
|
|
39
30
|
if (this.#started) return
|
|
40
31
|
this.#started = true
|
|
41
32
|
|
|
33
|
+
subscribeToEOL(() => {
|
|
34
|
+
this.initializedAggregates.forEach(aggregateInst => { // let all features wrap up things needed to do before ANY harvest in case there's last minute cross-feature data dependencies
|
|
35
|
+
if (typeof aggregateInst.harvestOpts.beforeUnload === 'function') aggregateInst.harvestOpts.beforeUnload()
|
|
36
|
+
})
|
|
37
|
+
this.initializedAggregates.forEach(aggregateInst => this.triggerHarvestFor(aggregateInst, { isFinalHarvest: true }))
|
|
38
|
+
})
|
|
39
|
+
|
|
42
40
|
const onHarvestInterval = () => {
|
|
43
41
|
this.initializedAggregates.forEach(aggregateInst => this.triggerHarvestFor(aggregateInst))
|
|
44
42
|
setTimeout(onHarvestInterval, harvestInterval * 1000) // repeat in X seconds
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Copyright 2020-2026 New Relic, Inc. All rights reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
|
-
import { JSERRORS, RUM, EVENTS, FEATURE_NAMES, BLOBS, LOGS } from '../../loaders/features/features'
|
|
5
|
+
import { JSERRORS, RUM, EVENTS, FEATURE_NAMES, BLOBS, LOGS, CONNECT } from '../../loaders/features/features'
|
|
6
6
|
import { VERSION } from '../constants/env'
|
|
7
7
|
import { globalScope, isWorkerScope } from '../constants/runtime'
|
|
8
8
|
import { handle } from '../event-emitter/handle'
|
|
@@ -12,7 +12,7 @@ import { cleanURL } from '../url/clean-url'
|
|
|
12
12
|
import { obj, param } from '../url/encode'
|
|
13
13
|
import { warn } from '../util/console'
|
|
14
14
|
import { stringify } from '../util/stringify'
|
|
15
|
-
import { xhr as xhrMethod, xhrFetch as fetchMethod } from '../util/submit-data'
|
|
15
|
+
import { xhr as xhrMethod, xhrFetch as fetchMethod, getSubmitMethod } from '../util/submit-data'
|
|
16
16
|
import { dispatchGlobalEvent } from '../dispatch/global-event'
|
|
17
17
|
|
|
18
18
|
/**
|
|
@@ -27,7 +27,7 @@ const warnings = {}
|
|
|
27
27
|
* @param {NetworkSendSpec} spec Specification for sending data
|
|
28
28
|
* @returns {boolean} True if a network call was made. Note that this does not mean or guarantee that it was successful.
|
|
29
29
|
*/
|
|
30
|
-
export function send (agentRef, { endpoint, payload, localOpts = {}, submitMethod, cbFinished, raw, featureName, endpointVersion = 1, harvesterObfuscator }) {
|
|
30
|
+
export function send (agentRef, { endpoint, payload, localOpts = {}, submitMethod = getSubmitMethod(), cbFinished, raw, featureName, endpointVersion = 1, harvesterObfuscator }) {
|
|
31
31
|
if (!agentRef.info.errorBeacon) return false
|
|
32
32
|
|
|
33
33
|
let { body, qs } = cleanPayload(payload)
|
|
@@ -39,16 +39,18 @@ export function send (agentRef, { endpoint, payload, localOpts = {}, submitMetho
|
|
|
39
39
|
|
|
40
40
|
const protocol = agentRef.init.ssl === false ? 'http' : 'https'
|
|
41
41
|
const perceivedBeacon = agentRef.init.proxy.beacon || agentRef.info.errorBeacon
|
|
42
|
+
const includeEndpointName = endpoint !== RUM || endpointVersion !== 1
|
|
42
43
|
const url = raw
|
|
43
44
|
? `${protocol}://${perceivedBeacon}/${endpoint}`
|
|
44
|
-
: `${protocol}://${perceivedBeacon}${
|
|
45
|
+
: `${protocol}://${perceivedBeacon}${includeEndpointName ? '/' + endpoint : ''}/${endpointVersion}/${agentRef.info.licenseKey}`
|
|
45
46
|
const baseParams = !raw ? baseQueryString(agentRef, qs, endpoint, harvesterObfuscator) : ''
|
|
46
47
|
let payloadParams = obj(qs, agentRef.runtime.maxBytes)
|
|
47
48
|
if (baseParams === '' && payloadParams.startsWith('&')) {
|
|
48
49
|
payloadParams = payloadParams.substring(1)
|
|
49
50
|
}
|
|
50
51
|
|
|
51
|
-
const
|
|
52
|
+
const queryString = `${baseParams}${payloadParams}`
|
|
53
|
+
const fullUrl = queryString ? `${url}?${queryString}` : url // omit the '?' if there are no query params
|
|
52
54
|
const gzip = !!qs?.attributes?.includes('gzip')
|
|
53
55
|
|
|
54
56
|
// all gzipped data is already in the correct format and needs no transformation
|
|
@@ -61,7 +63,7 @@ export function send (agentRef, { endpoint, payload, localOpts = {}, submitMetho
|
|
|
61
63
|
// Warn--once per endpoint--if the agent tries to send large payloads
|
|
62
64
|
if (endpoint !== BLOBS && stringBody.length > 750000 && (warnings[endpoint] = (warnings[endpoint] || 0) + 1) === 1) warn(28, endpoint)
|
|
63
65
|
|
|
64
|
-
const headers = [{ key: 'content-type', value: 'text/plain' }]
|
|
66
|
+
const headers = [{ key: 'content-type', value: 'text/plain' }, ...(localOpts.headers || [])]
|
|
65
67
|
|
|
66
68
|
/* Since workers don't support sendBeacon right now, they can only use XHR method.
|
|
67
69
|
Because they still do permit synch XHR, the idea is that at final harvest time (worker is closing),
|
|
@@ -92,6 +94,7 @@ export function send (agentRef, { endpoint, payload, localOpts = {}, submitMetho
|
|
|
92
94
|
|
|
93
95
|
function trackHarvestMetadata () {
|
|
94
96
|
try {
|
|
97
|
+
if (featureName === CONNECT) return
|
|
95
98
|
if (featureName === FEATURE_NAMES.jserrors && !body?.err) return
|
|
96
99
|
|
|
97
100
|
const hasReplay = baseParams.includes('hr=1')
|
|
@@ -189,7 +192,6 @@ function baseQueryString (agentRef, qs, endpoint, harvesterObfuscator) {
|
|
|
189
192
|
transactionNameParam(),
|
|
190
193
|
param('ct', agentRef.runtime.customTransaction),
|
|
191
194
|
'&rst=' + now(),
|
|
192
|
-
'&ck=0', // ck param DEPRECATED - still expected by backend
|
|
193
195
|
'&s=' + (session?.state.value || '0'), // the 0 id encaps all untrackable and default traffic
|
|
194
196
|
param('ref', ref),
|
|
195
197
|
param('ptid', (agentRef.runtime.ptid ? '' + agentRef.runtime.ptid : ''))
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright 2020-
|
|
2
|
+
* Copyright 2020-2026 New Relic, Inc. All rights reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
import { Timer } from './timer'
|
|
@@ -53,7 +53,7 @@ export class InteractionTimer extends Timer {
|
|
|
53
53
|
if (state === 'hidden') this.pause()
|
|
54
54
|
// vis change --> visible is treated like a new interaction with the page
|
|
55
55
|
else this.resume()
|
|
56
|
-
}, false,
|
|
56
|
+
}, false, this.abortController?.signal)
|
|
57
57
|
}
|
|
58
58
|
}
|
|
59
59
|
|
package/src/common/unload/eol.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright 2020-
|
|
2
|
+
* Copyright 2020-2026 New Relic, Inc. All rights reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
import { globalScope, isWorkerScope, isBrowserScope } from '../constants/runtime'
|
|
@@ -22,9 +22,9 @@ if (isWorkerScope) {
|
|
|
22
22
|
* This is used, for example, to submit a final harvest and send all remaining data on best-effort.
|
|
23
23
|
* @param {function} cb - func to run before or during the last reliable event or time of an env's life span
|
|
24
24
|
*/
|
|
25
|
-
export function subscribeToEOL (cb
|
|
25
|
+
export function subscribeToEOL (cb) {
|
|
26
26
|
if (isBrowserScope) {
|
|
27
|
-
subscribeToVisibilityChange(cb, true
|
|
27
|
+
subscribeToVisibilityChange(cb, true) // when user switches tab or hides window, esp. mobile scenario
|
|
28
28
|
} else if (isWorkerScope) {
|
|
29
29
|
globalScope.cleanupTasks.push(cb) // close() should run these tasks before quitting thread
|
|
30
30
|
}
|
|
@@ -68,7 +68,7 @@ import { dispatchGlobalEvent } from '../dispatch/global-event'
|
|
|
68
68
|
* | 50 | Failed to connect. Cannot allow registered API. |
|
|
69
69
|
* | 51 | Container agent is not available to register with. Can not connect. |
|
|
70
70
|
* | 52 | Unexpected problem encountered. There should be at least one app for harvest! |
|
|
71
|
-
* | 53 |
|
|
71
|
+
* | 53 | Failed to parse connect response. |
|
|
72
72
|
* | 54 | An experimental feature is being used. Support can not be offered for issues. |
|
|
73
73
|
* | 55 | Register API has been disabled on the container agent. |
|
|
74
74
|
* | 56 | Could not find a matching entity to store data. |
|
|
@@ -94,6 +94,7 @@ import { dispatchGlobalEvent } from '../dispatch/global-event'
|
|
|
94
94
|
* | 76 | Agent rejected post message, could not match with existing entity. |
|
|
95
95
|
* | 77 | Agent rejected post message, could not validate origin. |
|
|
96
96
|
* | 78 | RegisteredIframeEntity could not determine parent origin and will not register, to avoid trusting messages from any origin. |
|
|
97
|
+
* | 79 | Unable to initialize Connector and/or Harvester. |
|
|
97
98
|
*
|
|
98
99
|
* @param {number} code The warning code to emit, which will be used to link to the warning code documentation
|
|
99
100
|
* @param {*} [secondary] Secondary data to include, usually an extra message, error or object
|
|
@@ -19,7 +19,7 @@ export function activateFeatures (flags, agentRef) {
|
|
|
19
19
|
// let any window level subscribers know that the agent is running, per install docs
|
|
20
20
|
dispatchGlobalEvent({
|
|
21
21
|
loaded: true,
|
|
22
|
-
drained:
|
|
22
|
+
drained: !agentRef.init.feature_flags.includes('rum_v2'), // v2 RUM always call activateFeatures before any group is drained (in waitForFlags)
|
|
23
23
|
type: 'lifecycle',
|
|
24
24
|
name: 'load',
|
|
25
25
|
feature: undefined,
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright 2020-2026 New Relic, Inc. All rights reserved.
|
|
3
|
+
* SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @enum {string}
|
|
8
|
+
* @readonly
|
|
9
|
+
*/
|
|
10
|
+
export const V2_TYPES = {
|
|
11
|
+
/** Micro Frontend */
|
|
12
|
+
MFE: 'MFE',
|
|
13
|
+
/** Browser Application */
|
|
14
|
+
BA: 'BA'
|
|
15
|
+
}
|
package/src/common/v2/utils.js
CHANGED
|
@@ -4,16 +4,23 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { extractUrlsFromStack, getDeepStackTrace } from './script-tracker'
|
|
7
|
+
import { V2_TYPES } from './constants'
|
|
7
8
|
|
|
8
9
|
/**
|
|
9
|
-
* @
|
|
10
|
-
* @
|
|
10
|
+
* @typedef {Object} V2Target
|
|
11
|
+
* @property {'BA'} type always V2_TYPES.BA -- identifies this as the container (main) agent, not a registered MFE
|
|
12
|
+
* @property {string} instance the container agent's agentIdentifier
|
|
13
|
+
* @property {string} [id] the container agent's entity guid, once known (getter, resolved asynchronously)
|
|
14
|
+
* @property {{[key:string]: any}} attributes the V2 payload attributes for the container agent (getter)
|
|
11
15
|
*/
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Determines if a given target represents a registered MFE (as opposed to the container agent).
|
|
19
|
+
* @param {*} target the target to check
|
|
20
|
+
* @returns {boolean} true if the target is a registered MFE target
|
|
21
|
+
*/
|
|
22
|
+
export function isMfeTarget (target) {
|
|
23
|
+
return target?.type === V2_TYPES.MFE
|
|
17
24
|
}
|
|
18
25
|
|
|
19
26
|
/**
|
|
@@ -114,14 +121,8 @@ export function dedupeRegisteredEntitiesByAsset (entities) {
|
|
|
114
121
|
*/
|
|
115
122
|
export function getVersion2Attributes (target, aggregateInstance) {
|
|
116
123
|
if (!supportsV2(aggregateInstance)) return {}
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (!target) {
|
|
120
|
-
return {
|
|
121
|
-
'entity.guid': containerAgentEntityGuid,
|
|
122
|
-
appId: aggregateInstance.agentRef.info.applicationID
|
|
123
|
-
}
|
|
124
|
-
}
|
|
124
|
+
/** if the target isn't a registered MFE, but we are in v2 mode, this means the data belongs to the container agent */
|
|
125
|
+
if (!isMfeTarget(target)) return aggregateInstance.agentRef.runtime.v2Target.attributes
|
|
125
126
|
/** otherwise, the data belongs to the target (MFE) and should be attributed as such */
|
|
126
127
|
return target.attributes
|
|
127
128
|
}
|
|
@@ -147,16 +148,17 @@ export function getVersion2DuplicationAttributes (target, aggregateInstance) {
|
|
|
147
148
|
* @returns {boolean} returns true if the event should be duplicated for the target, false otherwise
|
|
148
149
|
*/
|
|
149
150
|
export function shouldDuplicate (target, aggregateInstance) {
|
|
150
|
-
return
|
|
151
|
+
return isMfeTarget(target) && !!supportsV2(aggregateInstance) && aggregateInstance.agentRef.init.api.register.duplicate_data_to_container
|
|
151
152
|
}
|
|
152
153
|
|
|
153
154
|
/**
|
|
154
155
|
* Finds the registered targets from the stack trace for a given agent reference.
|
|
155
156
|
* @param {*} agentRef The agent reference to use for finding targets.
|
|
156
|
-
* @returns {Array} An array of targets found from the stack trace. If no targets are found or allowed, returns an array
|
|
157
|
+
* @returns {Array} An array of targets found from the stack trace. If no targets are found or allowed, returns an array containing the container target.
|
|
157
158
|
*/
|
|
158
159
|
export function findTargetsFromStackTrace (agentRef) {
|
|
159
|
-
if (!
|
|
160
|
+
if (!agentRef?.runtime) return []
|
|
161
|
+
if (!isValid(true, agentRef) || !agentRef.runtime.registeredEntities?.length) return [agentRef.runtime.v2Target]
|
|
160
162
|
|
|
161
163
|
const targets = []
|
|
162
164
|
try {
|
|
@@ -170,15 +172,15 @@ export function findTargetsFromStackTrace (agentRef) {
|
|
|
170
172
|
}
|
|
171
173
|
|
|
172
174
|
const deduped = dedupeTargetsByInstance(targets)
|
|
173
|
-
if (!deduped.length) deduped.push(
|
|
175
|
+
if (!deduped.length) deduped.push(agentRef.runtime.v2Target) // if we can't find any targets from the stack trace, the container agent is the target
|
|
174
176
|
return deduped
|
|
175
177
|
}
|
|
176
178
|
|
|
177
179
|
/**
|
|
178
180
|
* Removes duplicate targets from an array, keyed by `target.instance`. This guards against the same canonical
|
|
179
181
|
* target re-entering the array via multiple matched stack-frame URLs (e.g. a recursive call whose stack contains the
|
|
180
|
-
* same file at multiple depths).
|
|
181
|
-
* naturally collapse to a single entry too, which is the desired behavior.
|
|
182
|
+
* same file at multiple depths). Multiple container-target entries (whose `instance` is the container agent's stable
|
|
183
|
+
* `agentIdentifier`) naturally collapse to a single entry too, which is the desired behavior.
|
|
182
184
|
* @param {Array} targets
|
|
183
185
|
* @returns {Array} deduped list of targets, preserving relative order of first occurrence
|
|
184
186
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Copyright 2020-
|
|
2
|
+
* Copyright 2020-2026 New Relic, Inc. All rights reserved.
|
|
3
3
|
* SPDX-License-Identifier: Apache-2.0
|
|
4
4
|
*/
|
|
5
5
|
|
|
@@ -24,16 +24,17 @@ const flag = `nr@wrapped:${contextId}`
|
|
|
24
24
|
* `document` (if in a browser scope). Adds custom events in context of a new emitter scoped only to these methods.
|
|
25
25
|
* @param {Object} sharedEE - The shared event emitter on which a new scoped
|
|
26
26
|
* event emitter will be based.
|
|
27
|
+
* @param {*} [agentRef] - The agent reference, used to attribute wrapped calls to the correct v2 target.
|
|
27
28
|
* @returns {Object} Scoped event emitter with a debug ID of `events`.
|
|
28
29
|
*/
|
|
29
|
-
export function wrapEvents (sharedEE) {
|
|
30
|
+
export function wrapEvents (sharedEE, agentRef) {
|
|
30
31
|
var ee = scopedEE(sharedEE)
|
|
31
32
|
|
|
32
33
|
// Notice if our wrapping never ran yet, the falsy NaN will not early return; but if it has,
|
|
33
34
|
// then we increment the count to track # of feats using this at runtime.
|
|
34
35
|
if (wrapped[ee.debugId]++) return ee
|
|
35
36
|
wrapped[ee.debugId] = 1 // otherwise, first feature to wrap events
|
|
36
|
-
var wrapFn = wfn(ee, true)
|
|
37
|
+
var wrapFn = wfn(ee, true, agentRef)
|
|
37
38
|
|
|
38
39
|
// Guard against instrumenting environments w/o necessary features
|
|
39
40
|
if ('getPrototypeOf' in Object) {
|
|
@@ -47,8 +47,8 @@ export function wrapFetch (sharedEE, agentRef) {
|
|
|
47
47
|
|
|
48
48
|
ee.on(prefix + 'end', function (err, res, targets) {
|
|
49
49
|
var ctx = this
|
|
50
|
-
//
|
|
51
|
-
ctx.targets = targets || [
|
|
50
|
+
// default target reports to container
|
|
51
|
+
ctx.targets = targets || [agentRef.runtime.v2Target]
|
|
52
52
|
if (res) {
|
|
53
53
|
var size = res.headers.get('content-length')
|
|
54
54
|
if (size !== null) {
|
|
@@ -88,7 +88,7 @@ export function createWrapperWithEmitter (emitter, always, agentRef) {
|
|
|
88
88
|
|
|
89
89
|
// certain wrappers can inform the function wrapper to evaluate the stack of the executed wrapped function to find targets of the execution
|
|
90
90
|
// (e.g. wrap-logger can inform this method to find try to find the MFE source of a console.log)
|
|
91
|
-
targets = evaluateStack ? findTargetsFromStackTrace(agentRef) : [
|
|
91
|
+
targets = evaluateStack ? findTargetsFromStackTrace(agentRef) : [agentRef?.runtime?.v2Target] // default target always maps to the container agent
|
|
92
92
|
|
|
93
93
|
if (typeof getContext === 'function') {
|
|
94
94
|
ctx = getContext(args, originalThis)
|