@newrelic/browser-agent 1.297.1-rc.0 → 1.297.1-rc.1

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.
Files changed (46) hide show
  1. package/dist/cjs/common/constants/env.cdn.js +1 -1
  2. package/dist/cjs/common/constants/env.npm.js +1 -1
  3. package/dist/cjs/common/wrap/wrap-function.js +9 -4
  4. package/dist/cjs/features/ajax/aggregate/index.js +10 -2
  5. package/dist/cjs/features/ajax/instrument/index.js +1 -0
  6. package/dist/cjs/features/jserrors/aggregate/index.js +9 -4
  7. package/dist/cjs/features/soft_navigations/aggregate/ajax-node.js +11 -3
  8. package/dist/cjs/features/soft_navigations/aggregate/index.js +38 -14
  9. package/dist/cjs/features/soft_navigations/aggregate/interaction.js +34 -20
  10. package/dist/cjs/features/soft_navigations/constants.js +8 -4
  11. package/dist/cjs/features/soft_navigations/instrument/index.js +9 -6
  12. package/dist/esm/common/constants/env.cdn.js +1 -1
  13. package/dist/esm/common/constants/env.npm.js +1 -1
  14. package/dist/esm/common/wrap/wrap-function.js +9 -4
  15. package/dist/esm/features/ajax/aggregate/index.js +10 -2
  16. package/dist/esm/features/ajax/instrument/index.js +1 -0
  17. package/dist/esm/features/jserrors/aggregate/index.js +9 -4
  18. package/dist/esm/features/soft_navigations/aggregate/ajax-node.js +11 -3
  19. package/dist/esm/features/soft_navigations/aggregate/index.js +39 -15
  20. package/dist/esm/features/soft_navigations/aggregate/interaction.js +35 -21
  21. package/dist/esm/features/soft_navigations/constants.js +7 -3
  22. package/dist/esm/features/soft_navigations/instrument/index.js +10 -7
  23. package/dist/types/common/wrap/wrap-function.d.ts.map +1 -1
  24. package/dist/types/features/ajax/aggregate/index.d.ts.map +1 -1
  25. package/dist/types/features/ajax/instrument/index.d.ts.map +1 -1
  26. package/dist/types/features/jserrors/aggregate/index.d.ts +1 -1
  27. package/dist/types/features/jserrors/aggregate/index.d.ts.map +1 -1
  28. package/dist/types/features/soft_navigations/aggregate/ajax-node.d.ts +2 -1
  29. package/dist/types/features/soft_navigations/aggregate/ajax-node.d.ts.map +1 -1
  30. package/dist/types/features/soft_navigations/aggregate/index.d.ts +1 -1
  31. package/dist/types/features/soft_navigations/aggregate/index.d.ts.map +1 -1
  32. package/dist/types/features/soft_navigations/aggregate/interaction.d.ts +6 -3
  33. package/dist/types/features/soft_navigations/aggregate/interaction.d.ts.map +1 -1
  34. package/dist/types/features/soft_navigations/constants.d.ts +4 -0
  35. package/dist/types/features/soft_navigations/constants.d.ts.map +1 -1
  36. package/dist/types/features/soft_navigations/instrument/index.d.ts.map +1 -1
  37. package/package.json +1 -1
  38. package/src/common/wrap/wrap-function.js +9 -4
  39. package/src/features/ajax/aggregate/index.js +10 -2
  40. package/src/features/ajax/instrument/index.js +1 -0
  41. package/src/features/jserrors/aggregate/index.js +10 -6
  42. package/src/features/soft_navigations/aggregate/ajax-node.js +8 -4
  43. package/src/features/soft_navigations/aggregate/index.js +39 -15
  44. package/src/features/soft_navigations/aggregate/interaction.js +33 -19
  45. package/src/features/soft_navigations/constants.js +5 -2
  46. package/src/features/soft_navigations/instrument/index.js +9 -8
@@ -6,7 +6,7 @@ import { addCustomAttributes, getAddStringContext, nullable, numeric } from '../
6
6
  import { NODE_TYPE } from '../constants';
7
7
  import { BelNode } from './bel-node';
8
8
  export class AjaxNode extends BelNode {
9
- constructor(ajaxEvent) {
9
+ constructor(ajaxEvent, ajaxContext) {
10
10
  super();
11
11
  this.belType = NODE_TYPE.AJAX;
12
12
  this.method = ajaxEvent.method;
@@ -20,8 +20,12 @@ export class AjaxNode extends BelNode {
20
20
  this.traceId = ajaxEvent.traceId;
21
21
  this.spanTimestamp = ajaxEvent.spanTimestamp;
22
22
  this.gql = ajaxEvent.gql;
23
- this.start = ajaxEvent.startTime; // 5000 --- 5500 --> 10500
23
+ this.start = ajaxEvent.startTime;
24
24
  this.end = ajaxEvent.endTime;
25
+ if (ajaxContext?.latestLongtaskEnd) {
26
+ this.callbackEnd = Math.max(ajaxContext.latestLongtaskEnd, this.end); // typically lt end if non-zero, but added clamping to end just in case
27
+ this.callbackDuration = this.callbackEnd - this.end; // callbackDuration is the time from ajax loaded to last long task observed from it
28
+ } else this.callbackEnd = this.end; // if no long task was observed, callbackEnd is the same as end
25
29
  }
26
30
  serialize(parentStartTimestamp, agentRef) {
27
31
  const addString = getAddStringContext(agentRef.runtime.obfuscator);
@@ -34,7 +38,11 @@ export class AjaxNode extends BelNode {
34
38
  // start relative to parent start (if part of first node in payload) or first parent start
35
39
  numeric(this.end - this.start),
36
40
  // end is relative to start
37
- numeric(this.callbackEnd), numeric(this.callbackDuration), addString(this.method), numeric(this.status), addString(this.domain), addString(this.path), numeric(this.txSize), numeric(this.rxSize), this.requestedWith, addString(this.nodeId), nullable(this.spanId, addString, true) + nullable(this.traceId, addString, true) + nullable(this.spanTimestamp, numeric)];
41
+ numeric(this.callbackEnd - this.end),
42
+ // callbackEnd is relative to end
43
+ numeric(this.callbackDuration),
44
+ // not relative
45
+ addString(this.method), numeric(this.status), addString(this.domain), addString(this.path), numeric(this.txSize), numeric(this.rxSize), this.requestedWith, addString(this.nodeId), nullable(this.spanId, addString, true) + nullable(this.traceId, addString, true) + nullable(this.spanTimestamp, numeric)];
38
46
  let allAttachedNodes = [];
39
47
  if (typeof this.gql === 'object') allAttachedNodes = addCustomAttributes(this.gql, addString);
40
48
  this.children.forEach(node => allAttachedNodes.push(node.serialize())); // no children is expected under ajax nodes at this time
@@ -8,7 +8,7 @@ import { single } from '../../../common/util/invoke';
8
8
  import { timeToFirstByte } from '../../../common/vitals/time-to-first-byte';
9
9
  import { FEATURE_NAMES } from '../../../loaders/features/features';
10
10
  import { AggregateBase } from '../../utils/aggregate-base';
11
- import { API_TRIGGER_NAME, FEATURE_NAME, INTERACTION_STATUS, INTERACTION_TRIGGERS, IPL_TRIGGER_NAME } from '../constants';
11
+ import { API_TRIGGER_NAME, FEATURE_NAME, INTERACTION_STATUS, INTERACTION_TRIGGERS, IPL_TRIGGER_NAME, NO_LONG_TASK_WINDOW, POPSTATE_MERGE_WINDOW, POPSTATE_TRIGGER } from '../constants';
12
12
  import { AjaxNode } from './ajax-node';
13
13
  import { InitialPageLoadInteraction } from './initial-page-load-interaction';
14
14
  import { Interaction } from './interaction';
@@ -40,7 +40,7 @@ export class Aggregate extends AggregateBase {
40
40
  });
41
41
  this.latestRouteSetByApi = null;
42
42
  this.interactionInProgress = null; // aside from the "page load" interaction, there can only ever be 1 ongoing at a time
43
- this.latestHistoryUrl = null;
43
+ this.latestHistoryUrl = window.location.href; // the initial url is needed to get a correct oldURL in the case that the first nav is triggered by 'popstate'
44
44
  this.harvestOpts.beforeUnload = () => this.interactionInProgress?.done(); // return any withheld ajax or jserr events so they can be sent with EoL harvest
45
45
 
46
46
  this.waitForFlags(['spa']).then(([spaOn]) => {
@@ -56,14 +56,25 @@ export class Aggregate extends AggregateBase {
56
56
  // By default, a complete UI driven interaction requires event -> URL change -> DOM mod in that exact order.
57
57
  registerHandler('newUIEvent', event => this.startUIInteraction(event.type, Math.floor(event.timeStamp), event.target), this.featureName, this.ee);
58
58
  registerHandler('newURL', (timestamp, url) => {
59
- // In the case of 'popstate' trigger, by the time the event fires, the URL has already changed, so we need to store what-will-be the *previous* URL for oldURL of next popstate ixn.
59
+ // The newURL always need to be tracked such that it becomes the oldURL of the next potential popstate ixn.
60
+ // Because for 'popstate' triggered newUIEVent, by the time the event fires, the page URL has already changed so the previous URL is lost if not recorded.
60
61
  this.latestHistoryUrl = url;
61
62
  this.interactionInProgress?.updateHistory(timestamp, url);
62
63
  }, this.featureName, this.ee);
63
64
  registerHandler('newDom', timestamp => {
64
65
  this.interactionInProgress?.updateDom(timestamp);
65
- if (this.interactionInProgress?.seenHistoryAndDomChange()) this.interactionInProgress.done();
66
+ this.interactionInProgress?.checkHistoryAndDomChange();
66
67
  }, this.featureName, this.ee);
68
+ this.ee.on('long-task', task => {
69
+ if (!this.interactionInProgress?.watchLongtaskTimer) return; // no ixn in progress or it's not yet in a pending-finish state, as indicated by the lack of a watchLongtask timeout
70
+ clearTimeout(this.interactionInProgress.watchLongtaskTimer);
71
+ // Provided there isn't another long task, the ixn span will be extended to include this long task that would finish the interaction.
72
+ this.interactionInProgress.customEnd = task.end;
73
+ this.interactionInProgress.watchLongtaskTimer = setTimeout(() => this.interactionInProgress.done(), NO_LONG_TASK_WINDOW);
74
+
75
+ // Report metric on frequency of ixn extension due to long task
76
+ this.reportSupportabilityMetric('SoftNav/Interaction/Extended');
77
+ });
67
78
  this.#registerApiHandlers();
68
79
  registerHandler('ajax', this.#handleAjaxEvent.bind(this), this.featureName, this.ee);
69
80
  registerHandler('jserror', this.#handleJserror.bind(this), this.featureName, this.ee);
@@ -82,9 +93,11 @@ export class Aggregate extends AggregateBase {
82
93
  startUIInteraction(eventName, startedAt, sourceElem) {
83
94
  // this is throttled by instrumentation so that it isn't excessively called
84
95
  if (this.interactionInProgress?.createdByApi) return; // api-started interactions cannot be disrupted aka cancelled by UI events (and the vice versa applies as well)
85
- if (this.interactionInProgress?.done() === false) return; // current in-progress is blocked from closing, e.g. by 'waitForEnd' api option
96
+ // Navs from interacting with the document will emit the UI event like click, followed by a popstate which should be squashed given some margin of time. This prevents it from cancelling the first UI ixn.
97
+ if (eventName === POPSTATE_TRIGGER && this.interactionInProgress?.trigger !== POPSTATE_TRIGGER && startedAt - this.interactionInProgress?.start <= POPSTATE_MERGE_WINDOW) return;
98
+ if (this.interactionInProgress?.done() === false) return; // current in-progress is blocked from closing if true, e.g. by 'waitForEnd' api option; notice this cancels/finishes existing in-progress ixn
86
99
 
87
- const oldURL = eventName === INTERACTION_TRIGGERS[3] ? this.latestHistoryUrl : undefined; // see related comment in 'newURL' handler above, 'popstate'
100
+ const oldURL = eventName === POPSTATE_TRIGGER ? this.latestHistoryUrl : undefined; // see related comment in 'newURL' handler above, 'popstate'
88
101
  this.interactionInProgress = new Interaction(eventName, startedAt, this.latestRouteSetByApi, oldURL);
89
102
  if (eventName === INTERACTION_TRIGGERS[0]) {
90
103
  // 'click'
@@ -147,22 +160,30 @@ export class Aggregate extends AggregateBase {
147
160
  /**
148
161
  * Handles or redirect ajax event based on the interaction, if any, that it's tied to.
149
162
  * @param {Object} event see Ajax feature's storeXhr function for object definition
163
+ * @param {Object} metadata reference to the ajax context, used to pass long task info
150
164
  */
151
- #handleAjaxEvent(event) {
165
+ #handleAjaxEvent(event, metadata) {
152
166
  const associatedInteraction = this.getInteractionFor(event.startTime);
153
167
  if (!associatedInteraction) {
154
168
  // no interaction was happening when this ajax started, so give it back to Ajax feature for processing
155
169
  handle('returnAjax', [event], undefined, FEATURE_NAMES.ajax, this.ee);
156
170
  } else {
157
- if (associatedInteraction.status === INTERACTION_STATUS.FIN) processAjax(event, associatedInteraction); // tack ajax onto the ixn object awaiting harvest
171
+ if (associatedInteraction.status === INTERACTION_STATUS.FIN) processAjax.call(this, event, metadata, associatedInteraction); // tack ajax onto the ixn object awaiting harvest
158
172
  else {
159
173
  // same thing as above, just at a later time -- if the interaction in progress is cancelled, just send the event back to ajax feat unmodified
160
- associatedInteraction.on('finished', () => processAjax(event, associatedInteraction));
174
+ associatedInteraction.on('finished', () => processAjax.call(this, event, metadata, associatedInteraction));
161
175
  associatedInteraction.on('cancelled', () => handle('returnAjax', [event], undefined, FEATURE_NAMES.ajax, this.ee));
162
176
  }
163
177
  }
164
- function processAjax(event, parentInteraction) {
165
- const newNode = new AjaxNode(event);
178
+ function processAjax(event, metadata, parentInteraction) {
179
+ const finalEnd = parentInteraction.end; // assume: by the time the 'finished' event occurs & this executes, the ixn end time accounts for any long task extension + lookback window exclusion
180
+ if (event.startTime > finalEnd) {
181
+ handle('returnAjax', [event], undefined, FEATURE_NAMES.ajax, this.ee); // falling outside the final span, returned as standalone
182
+ return;
183
+ }
184
+
185
+ // Metadata(ctx) should contain any long task end time associated with this XHR which should be up-to-date by the time the in-progress ixn & ajax children are being finalized for harvest.
186
+ const newNode = new AjaxNode(event, metadata);
166
187
  parentInteraction.addChild(newNode);
167
188
  }
168
189
  }
@@ -185,7 +206,7 @@ export class Aggregate extends AggregateBase {
185
206
  } else {
186
207
  // These callbacks may be added multiple times for an ixn, but just a single run will deal with all jserrors associated with the interaction.
187
208
  // As such, be cautious not to use the params object since that's tied to one specific jserror and won't affect the rest of them.
188
- associatedInteraction.on('finished', single(() => handle('softNavFlush', [associatedInteraction.id, true, associatedInteraction.customAttributes], undefined, FEATURE_NAMES.jserrors, this.ee)));
209
+ associatedInteraction.on('finished', single(() => handle('softNavFlush', [associatedInteraction.id, true, associatedInteraction.customAttributes, associatedInteraction.end], undefined, FEATURE_NAMES.jserrors, this.ee)));
189
210
  associatedInteraction.on('cancelled', single(() => handle('softNavFlush', [associatedInteraction.id, false, undefined], undefined, FEATURE_NAMES.jserrors, this.ee))); // don't take custom attrs from cancelled ixns
190
211
  }
191
212
  }
@@ -200,7 +221,7 @@ export class Aggregate extends AggregateBase {
200
221
  this.associatedInteraction = thisClass.getInteractionFor(time);
201
222
  if (this.associatedInteraction?.trigger === IPL_TRIGGER_NAME) this.associatedInteraction = null; // the api get-interaction method cannot target IPL
202
223
  if (!this.associatedInteraction) {
203
- // This new api-driven interaction will be the target of any subsequent .interaction() call, until it is closed by EITHER .end() OR the regular seenHistoryAndDomChange process.
224
+ // This new api-driven interaction will be the target of any subsequent .interaction() call, until it is closed by EITHER .end() OR the regular url>dom change process.
204
225
  this.associatedInteraction = thisClass.interactionInProgress = new Interaction(API_TRIGGER_NAME, time, thisClass.latestRouteSetByApi);
205
226
  thisClass.domObserver.observe(document.body, {
206
227
  attributes: true,
@@ -210,10 +231,13 @@ export class Aggregate extends AggregateBase {
210
231
  }); // start observing for DOM changes like a regular UI-driven interaction
211
232
  thisClass.setClosureHandlers();
212
233
  }
213
- if (waitForEnd === true) this.associatedInteraction.keepOpenUntilEndApi = true;
234
+ if (waitForEnd === true) {
235
+ this.associatedInteraction.keepOpenUntilEndApi = true;
236
+ clearTimeout(this.associatedInteraction.cancellationTimer); // get rid of the auto-cancel 30s timer for UI ixns when users specify waitForEnd manual override
237
+ }
214
238
  }, thisClass.featureName, thisClass.ee);
215
239
  registerHandler(INTERACTION_API + 'end', function (timeNow) {
216
- this.associatedInteraction.done(timeNow);
240
+ this.associatedInteraction.done(timeNow, true);
217
241
  }, thisClass.featureName, thisClass.ee);
218
242
  registerHandler(INTERACTION_API + 'save', function () {
219
243
  this.associatedInteraction.forceSave = true;
@@ -7,7 +7,7 @@ import { generateUuid } from '../../../common/ids/unique-id';
7
7
  import { addCustomAttributes, getAddStringContext, nullable, numeric } from '../../../common/serialize/bel-serializer';
8
8
  import { now } from '../../../common/timing/now';
9
9
  import { cleanURL } from '../../../common/url/clean-url';
10
- import { NODE_TYPE, INTERACTION_STATUS, INTERACTION_TYPE, API_TRIGGER_NAME, IPL_TRIGGER_NAME } from '../constants';
10
+ import { NODE_TYPE, INTERACTION_STATUS, INTERACTION_TYPE, API_TRIGGER_NAME, IPL_TRIGGER_NAME, NO_LONG_TASK_WINDOW } from '../constants';
11
11
  import { BelNode } from './bel-node';
12
12
 
13
13
  /**
@@ -29,7 +29,9 @@ export class Interaction extends BelNode {
29
29
  createdByApi = false;
30
30
  keepOpenUntilEndApi = false;
31
31
  onDone = [];
32
+ customEnd = 0;
32
33
  cancellationTimer;
34
+ watchLongtaskTimer;
33
35
  constructor(uiEvent, uiEventTimestamp, currentRouteKnown, currentUrl) {
34
36
  super();
35
37
  this.belType = NODE_TYPE.INTERACTION;
@@ -41,36 +43,48 @@ export class Interaction extends BelNode {
41
43
  if (this.trigger === API_TRIGGER_NAME) this.createdByApi = true;
42
44
  this.newURL = this.oldURL = currentUrl || globalScope?.location.href;
43
45
  }
44
- updateDom(timestamp) {
45
- this.domTimestamp = timestamp || now(); // default timestamp should be precise for accurate isActiveDuring calculations
46
- }
47
46
  updateHistory(timestamp, newUrl) {
48
- this.newURL = newUrl || '' + globalScope?.location;
47
+ if (this.domTimestamp > 0) return; // url is locked once ui>url>dom change sequence is seen
48
+ if (!newUrl || newUrl === this.oldURL) return; // url must be different for interaction heuristic to proceed
49
+ this.newURL = newUrl;
49
50
  this.historyTimestamp = timestamp || now();
50
51
  }
51
- seenHistoryAndDomChange() {
52
- return this.historyTimestamp > 0 && this.domTimestamp > this.historyTimestamp; // URL must change before DOM does
52
+ updateDom(timestamp) {
53
+ if (!this.historyTimestamp || timestamp < this.historyTimestamp) return; // dom change must come after (any) url change, though this can be updated multiple times, taking the last dom timestamp
54
+ this.domTimestamp = timestamp || now(); // default timestamp should be precise for accurate isActiveDuring calculations
55
+ }
56
+ checkHistoryAndDomChange() {
57
+ if (!(this.historyTimestamp > 0 && this.domTimestamp > this.historyTimestamp)) return false;
58
+ if (this.status === INTERACTION_STATUS.PF) return true; // indicate the finishing process has already started for this interaction
59
+ this.status = INTERACTION_STATUS.PF; // set for eventual harvest
60
+
61
+ // Once the fixed reqs for a nav has been met, start a X countdown timer that watches for any long task, if it doesn't already exist, before completing the interaction.
62
+ clearTimeout(this.cancellationTimer); // "pending-finish" ixns cannot be auto cancelled anymore
63
+ this.watchLongtaskTimer ??= setTimeout(() => this.done(), NO_LONG_TASK_WINDOW);
64
+ // Notice that by not providing a specific end time to `.done()`, the ixn will use the dom timestamp in the event of no long task, which is what we want.
65
+ return true;
53
66
  }
54
67
  on(event, cb) {
55
68
  if (!this.eventSubscription.has(event)) throw new Error('Cannot subscribe to non pre-defined events.');
56
69
  if (typeof cb !== 'function') throw new Error('Must supply function as callback.');
57
70
  this.eventSubscription.get(event).push(cb);
58
71
  }
59
- done(customEndTime) {
60
- // User could've mark this interaction--regardless UI or api started--as "don't close until .end() is called on it". Only .end provides a timestamp; the default flows do not.
61
- if (this.keepOpenUntilEndApi && customEndTime === undefined) return false;
72
+ done(customEndTime = this.customEnd, calledByApi = false) {
73
+ // User could've mark this interaction--regardless UI or api started--as "don't close until .end() is called on it".
74
+ if (this.keepOpenUntilEndApi && !calledByApi) return false;
62
75
  // If interaction is already closed, this is a no-op. However, returning true lets startUIInteraction know that it CAN start a new interaction, as this one is done.
63
- if (this.status !== INTERACTION_STATUS.IP) return true;
76
+ if (this.status === INTERACTION_STATUS.FIN || this.status === INTERACTION_STATUS.CAN) return true;
77
+ clearTimeout(this.cancellationTimer); // clean up timers in case this is called by any flow that doesn't already do so
78
+ clearTimeout(this.watchLongtaskTimer);
64
79
  this.onDone.forEach(apiProvidedCb => apiProvidedCb(this.customDataByApi)); // this interaction's .save or .ignore can still be set by these user provided callbacks for example
65
80
 
66
81
  if (this.forceIgnore) this.#cancel(); // .ignore() always has precedence over save actions
67
- else if (this.seenHistoryAndDomChange()) this.#finish(customEndTime); // then this should've already finished while it was the interactionInProgress, with a natural end time
82
+ else if (this.status === INTERACTION_STATUS.PF) this.#finish(customEndTime); // then this should've already finished while it was the interactionInProgress, with a natural end time
68
83
  else if (this.forceSave) this.#finish(customEndTime || performance.now()); // a manually saved ixn (did not fulfill conditions) must have a specified end time, if one wasn't provided
69
84
  else this.#cancel();
70
85
  return true;
71
86
  }
72
- #finish(customEndTime = 0) {
73
- clearTimeout(this.cancellationTimer);
87
+ #finish(customEndTime) {
74
88
  this.end = Math.max(this.domTimestamp, this.historyTimestamp, customEndTime);
75
89
  this.status = INTERACTION_STATUS.FIN;
76
90
 
@@ -79,7 +93,6 @@ export class Interaction extends BelNode {
79
93
  callbacks.forEach(fn => fn());
80
94
  }
81
95
  #cancel() {
82
- clearTimeout(this.cancellationTimer);
83
96
  this.status = INTERACTION_STATUS.CAN;
84
97
 
85
98
  // Run all the callbacks listening to this interaction's potential cancellation.
@@ -90,12 +103,13 @@ export class Interaction extends BelNode {
90
103
  /**
91
104
  * Given a timestamp, determine if it falls within this interaction's span, i.e. if this was the active interaction during that time.
92
105
  * For in-progress interactions, this only compares the time with the start of span. Cancelled interactions are not considered active at all.
106
+ * Pending-finish interactions are also considered still active wrt assigning ajax or jserrors to them during the wait period.
93
107
  * @param {DOMHighResTimeStamp} timestamp
94
108
  * @returns True or false boolean.
95
109
  */
96
110
  isActiveDuring(timestamp) {
97
- if (this.status === INTERACTION_STATUS.IP) return this.start <= timestamp;
98
- return this.status === INTERACTION_STATUS.FIN && this.start <= timestamp && this.end > timestamp;
111
+ if (this.status === INTERACTION_STATUS.IP || this.status === INTERACTION_STATUS.PF) return this.start <= timestamp;
112
+ return this.status === INTERACTION_STATUS.FIN && this.start <= timestamp && timestamp < this.end;
99
113
  }
100
114
 
101
115
  // Following are virtual properties overridden by a subclass:
@@ -123,10 +137,10 @@ export class Interaction extends BelNode {
123
137
  // the very 1st ixn does not require offset so it should fallback to a 0 while rest is offset by the very 1st ixn's start
124
138
  numeric(this.end - this.start),
125
139
  // end -- relative to start
126
- numeric(this.callbackEnd),
127
- // cbEnd -- relative to start; not used by BrowserInteraction events
128
- numeric(this.callbackDuration),
129
- // not relative
140
+ numeric(0),
141
+ // callbackEnd -- relative to start; not used by BrowserInteraction events so these are always 0
142
+ numeric(0),
143
+ // not relative; always 0 for BrowserInteraction
130
144
  addString(this.trigger), addString(cleanURL(this.initialPageURL, true)), addString(cleanURL(this.oldURL, true)), addString(cleanURL(this.newURL, true)), addString(this.customName), ixnType, nullable(this.queueTime, numeric, true) + nullable(this.appTime, numeric, true) + nullable(this.oldRoute, addString, true) + nullable(this.newRoute, addString, true) + addString(this.id), addString(this.nodeId), nullable(this.firstPaint, numeric, true) + nullable(this.firstContentfulPaint, numeric)];
131
145
  const customAttributes = {
132
146
  ...agentRef.info.jsAttributes,
@@ -7,13 +7,15 @@ export const INTERACTION_TRIGGERS = ['click',
7
7
  // e.g. user clicks link or the page back/forward buttons
8
8
  'keydown',
9
9
  // e.g. user presses left and right arrow key to switch between displayed photo gallery
10
- 'submit',
11
- // e.g. user clicks submit butotn or presses enter while editing a form field
12
- 'popstate' // history api is used to navigate back and forward
10
+ 'submit' // e.g. user clicks submit butotn or presses enter while editing a form field
13
11
  ];
12
+ export const POPSTATE_TRIGGER = 'popstate'; // e.g. user clicks browser back/forward button or history API is used programmatically
14
13
  export const API_TRIGGER_NAME = 'api';
15
14
  export const IPL_TRIGGER_NAME = 'initialPageLoad';
16
15
  export const FEATURE_NAME = FEATURE_NAMES.softNav;
16
+ export const NO_LONG_TASK_WINDOW = 5000; // purpose is to wait 5 seconds wherein no long task is detected
17
+ export const POPSTATE_MERGE_WINDOW = 500; // "coalesce" (discard) a popstate that happen within this period following an INTERACTION_TRIGGER opening ixn, e.g. click->popstate
18
+
17
19
  export const INTERACTION_TYPE = {
18
20
  INITIAL_PAGE_LOAD: '',
19
21
  ROUTE_CHANGE: 1,
@@ -27,6 +29,8 @@ export const NODE_TYPE = {
27
29
  };
28
30
  export const INTERACTION_STATUS = {
29
31
  IP: 'in progress',
32
+ PF: 'pending finish',
33
+ // interaction meets the hard criteria but is awaiting flexible conditions to fully finish
30
34
  FIN: 'finished',
31
35
  CAN: 'cancelled'
32
36
  };
@@ -9,7 +9,7 @@ import { windowAddEventListener } from '../../../common/event-listener/event-lis
9
9
  import { debounce } from '../../../common/util/invoke';
10
10
  import { wrapHistory } from '../../../common/wrap/wrap-history';
11
11
  import { InstrumentBase } from '../../utils/instrument-base';
12
- import { FEATURE_NAME, INTERACTION_TRIGGERS } from '../constants';
12
+ import { FEATURE_NAME, INTERACTION_TRIGGERS, POPSTATE_TRIGGER } from '../constants';
13
13
  import { now } from '../../../common/timing/now';
14
14
  import { setupInteractionAPI } from '../../../loaders/api/interaction';
15
15
 
@@ -30,19 +30,22 @@ export class Instrument extends InstrumentBase {
30
30
  if (!isBrowserScope || !gosNREUMOriginals().o.MO) return; // soft navigations is not supported outside web env or browsers without the mutation observer API
31
31
 
32
32
  const historyEE = wrapHistory(this.ee);
33
+ try {
34
+ this.removeOnAbort = new AbortController();
35
+ } catch (e) {}
33
36
  INTERACTION_TRIGGERS.forEach(trigger => {
34
37
  windowAddEventListener(trigger, evt => {
35
38
  processUserInteraction(evt);
36
- }, true);
39
+ }, true, this.removeOnAbort?.signal);
37
40
  });
38
41
  const trackURLChange = () => handle('newURL', [now(), '' + window.location], undefined, this.featureName, this.ee);
39
42
  historyEE.on('pushState-end', trackURLChange);
40
43
  historyEE.on('replaceState-end', trackURLChange);
41
- try {
42
- this.removeOnAbort = new AbortController();
43
- } catch (e) {}
44
- const trackURLChangeEvent = evt => handle('newURL', [evt.timeStamp, '' + window.location], undefined, this.featureName, this.ee);
45
- windowAddEventListener('popstate', trackURLChangeEvent, true, this.removeOnAbort?.signal);
44
+ windowAddEventListener(POPSTATE_TRIGGER, evt => {
45
+ // popstate is unique in that it serves as BOTH a UI event and a notification of URL change
46
+ processUserInteraction(evt);
47
+ handle('newURL', [evt.timeStamp, '' + window.location], undefined, this.featureName, this.ee);
48
+ }, true, this.removeOnAbort?.signal);
46
49
  let oncePerFrame = false; // attempt to reduce dom noice since the observer runs very frequently with below options
47
50
  const domObserver = new (gosNREUMOriginals().o.MO)((domChanges, observer) => {
48
51
  if (oncePerFrame) return;
@@ -1 +1 @@
1
- {"version":3,"file":"wrap-function.d.ts","sourceRoot":"","sources":["../../../../src/common/wrap/wrap-function.js"],"names":[],"mappings":"AA6BA;;;;;GAKG;AACH,mDAJW,MAAM,UACN,OAAO,YA+IjB;AAgBD;;;;;;;;GAQG;AACH,2BANW,MAAM,MACN,MAAM,YACN,MAAM,GAEJ,MAAM,CA2BlB;AArND,0BAA6C"}
1
+ {"version":3,"file":"wrap-function.d.ts","sourceRoot":"","sources":["../../../../src/common/wrap/wrap-function.js"],"names":[],"mappings":"AA8BA;;;;;GAKG;AACH,mDAJW,MAAM,UACN,OAAO,YAmJjB;AAgBD;;;;;;;;GAQG;AACH,2BANW,MAAM,MACN,MAAM,YACN,MAAM,GAEJ,MAAM,CA2BlB;AA1ND,0BAA6C"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/ajax/aggregate/index.js"],"names":[],"mappings":"AAcA;IACE,2BAAiC;IAEjC,2BA+BC;IA5BC,mBAAwB;IA8B1B,6FA0EC;IAED,iDA6CC;CACF;8BAlK6B,4BAA4B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/ajax/aggregate/index.js"],"names":[],"mappings":"AAeA;IACE,2BAAiC;IAEjC,2BAsCC;IAnCC,mBAAwB;IAqC1B,6FA0EC;IAED,iDA6CC;CACF;8BA1K6B,4BAA4B"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/ajax/instrument/index.js"],"names":[],"mappings":"AA6BA;IACE,2BAAiC;IACjC,2BAkCC;IA/BC,OAA0B;IAE1B,8DAAkF;CA8BrF;AAkWD,qCAA8B;+BArZC,6BAA6B;mBAFzC,uBAAuB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/ajax/instrument/index.js"],"names":[],"mappings":"AA6BA;IACE,2BAAiC;IACjC,2BAkCC;IA/BC,OAA0B;IAE1B,8DAAkF;CA8BrF;AAmWD,qCAA8B;+BAtZC,6BAA6B;mBAFzC,uBAAuB"}
@@ -42,7 +42,7 @@ export class Aggregate extends AggregateBase {
42
42
  */
43
43
  shouldAllowMainAgentToCapture(entityGuid: string): boolean;
44
44
  onInteractionDone(interaction: any, wasSaved: any): void;
45
- onSoftNavNotification(interactionId: any, wasFinished: any, softNavAttrs: any): void;
45
+ onSoftNavNotification(interactionId: any, wasFinished: any, softNavAttrs: any, interactionEndTime: any): void;
46
46
  #private;
47
47
  }
48
48
  export type StackInfo = import("./compute-stack-trace.js").StackInfo;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/jserrors/aggregate/index.js"],"names":[],"mappings":"AAyBA;;GAEG;AAEH;IACE,2BAAiC;IACjC,2BA4BC;IAzBC,kBAAuB;IACvB,eAAoB;IACpB,qBAA0B;IAC1B,2BAAgC;IAChC,qBAAwB;IAuB1B,oDAEC;IAED;;;MAcC;IAED;;;;;;OAMG;IACH,qCAHW,SAAS,GACP,MAAM,CAgBlB;IAED;;;;;;;;;;OAUG;IACH,gBATW,KAAK,GAAC,aAAa,QACnB,MAAM,aACN,OAAO,YAAC,qBACR,MAAM,YAAC,cACP,OAAO,YAAC,kBACR,MAAM,YAAC,+BAiHjB;IA4BD;;;;;MAKE;IACF,0CAHU,MAAM,GACJ,OAAO,CAIlB;IAGD,yDA6BC;IAED,qFAOC;;CACF;wBApRY,OAAO,0BAA0B,EAAE,SAAS;8BAT3B,4BAA4B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/jserrors/aggregate/index.js"],"names":[],"mappings":"AAyBA;;GAEG;AAEH;IACE,2BAAiC;IACjC,2BA4BC;IAzBC,kBAAuB;IACvB,eAAoB;IACpB,qBAA0B;IAC1B,2BAAgC;IAChC,qBAAwB;IAuB1B,oDAEC;IAED;;;MAcC;IAED;;;;;;OAMG;IACH,qCAHW,SAAS,GACP,MAAM,CAgBlB;IAED;;;;;;;;;;OAUG;IACH,gBATW,KAAK,GAAC,aAAa,QACnB,MAAM,aACN,OAAO,YAAC,qBACR,MAAM,YAAC,cACP,OAAO,YAAC,kBACR,MAAM,YAAC,+BAiHjB;IA4BD;;;;;MAKE;IACF,0CAHU,MAAM,GACJ,OAAO,CAIlB;IAGD,yDA6BC;IAED,8GAWC;;CACF;wBAxRY,OAAO,0BAA0B,EAAE,SAAS;8BAT3B,4BAA4B"}
@@ -1,5 +1,5 @@
1
1
  export class AjaxNode extends BelNode {
2
- constructor(ajaxEvent: any);
2
+ constructor(ajaxEvent: any, ajaxContext: any);
3
3
  belType: number;
4
4
  method: any;
5
5
  status: any;
@@ -12,6 +12,7 @@ export class AjaxNode extends BelNode {
12
12
  traceId: any;
13
13
  spanTimestamp: any;
14
14
  gql: any;
15
+ callbackEnd: any;
15
16
  serialize(parentStartTimestamp: any, agentRef: any): string;
16
17
  }
17
18
  import { BelNode } from './bel-node';
@@ -1 +1 @@
1
- {"version":3,"file":"ajax-node.d.ts","sourceRoot":"","sources":["../../../../../src/features/soft_navigations/aggregate/ajax-node.js"],"names":[],"mappings":"AAQA;IACE,4BAiBC;IAfC,gBAA6B;IAC7B,YAA8B;IAC9B,YAA8B;IAC9B,YAA8B;IAC9B,UAA0B;IAC1B,YAAmC;IACnC,YAAoC;IACpC,+BAAwD;IACxD,YAA8B;IAC9B,aAAgC;IAChC,mBAA4C;IAC5C,SAAwB;IAM1B,4DA+BC;CACF;wBAtDuB,YAAY"}
1
+ {"version":3,"file":"ajax-node.d.ts","sourceRoot":"","sources":["../../../../../src/features/soft_navigations/aggregate/ajax-node.js"],"names":[],"mappings":"AAQA;IACE,8CAqBC;IAnBC,gBAA6B;IAC7B,YAA8B;IAC9B,YAA8B;IAC9B,YAA8B;IAC9B,UAA0B;IAC1B,YAAmC;IACnC,YAAoC;IACpC,+BAAwD;IACxD,YAA8B;IAC9B,aAAgC;IAChC,mBAA4C;IAC5C,SAAwB;IAKtB,iBAAoE;IAKxE,4DA+BC;CACF;wBA1DuB,YAAY"}
@@ -8,7 +8,7 @@ export class Aggregate extends AggregateBase {
8
8
  initialPageLoadInteraction: InitialPageLoadInteraction;
9
9
  latestRouteSetByApi: any;
10
10
  interactionInProgress: Interaction | null;
11
- latestHistoryUrl: any;
11
+ latestHistoryUrl: string;
12
12
  serializer(eventBuffer: any): string;
13
13
  startUIInteraction(eventName: any, startedAt: any, sourceElem: any): void;
14
14
  setClosureHandlers(): void;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/soft_navigations/aggregate/index.js"],"names":[],"mappings":"AAeA;IACE,2BAAiC;IACjC;;OAsDC;IAjDC,2BAAwC;IACxC,iBAA8B;IAE9B,uDAA0E;IAe1E,yBAA+B;IAC/B,0CAAiC;IACjC,sBAA4B;IA+B9B,qCAUC;IAED,0EAiBC;IAED,2BAiBC;IAED;;;;;;;OAOG;IACH,6BAHW,mBAAmB,OAsB7B;;CA6FF;8BA1O6B,4BAA4B;2CAGf,iCAAiC;4BAChD,eAAe"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/soft_navigations/aggregate/index.js"],"names":[],"mappings":"AAeA;IACE,2BAAiC;IACjC;;OAiEC;IA5DC,2BAAwC;IACxC,iBAA8B;IAE9B,uDAA0E;IAe1E,yBAA+B;IAC/B,0CAAiC;IACjC,yBAA4C;IA0C9C,qCAUC;IAED,0EAmBC;IAED,2BAiBC;IAED;;;;;;;OAOG;IACH,6BAHW,mBAAmB,OAsB7B;;CAwGF;8BAlQ6B,4BAA4B;2CAGf,iCAAiC;4BAChD,eAAe"}
@@ -18,7 +18,9 @@ export class Interaction extends BelNode {
18
18
  createdByApi: boolean;
19
19
  keepOpenUntilEndApi: boolean;
20
20
  onDone: any[];
21
+ customEnd: number;
21
22
  cancellationTimer: any;
23
+ watchLongtaskTimer: any;
22
24
  belType: number;
23
25
  trigger: any;
24
26
  oldRoute: any;
@@ -27,14 +29,15 @@ export class Interaction extends BelNode {
27
29
  forceIgnore: boolean;
28
30
  newURL: any;
29
31
  oldURL: any;
30
- updateDom(timestamp: any): void;
31
32
  updateHistory(timestamp: any, newUrl: any): void;
32
- seenHistoryAndDomChange(): boolean;
33
+ updateDom(timestamp: any): void;
34
+ checkHistoryAndDomChange(): boolean;
33
35
  on(event: any, cb: any): void;
34
- done(customEndTime: any): boolean;
36
+ done(customEndTime?: number, calledByApi?: boolean): boolean;
35
37
  /**
36
38
  * Given a timestamp, determine if it falls within this interaction's span, i.e. if this was the active interaction during that time.
37
39
  * For in-progress interactions, this only compares the time with the start of span. Cancelled interactions are not considered active at all.
40
+ * Pending-finish interactions are also considered still active wrt assigning ajax or jserrors to them during the wait period.
38
41
  * @param {DOMHighResTimeStamp} timestamp
39
42
  * @returns True or false boolean.
40
43
  */
@@ -1 +1 @@
1
- {"version":3,"file":"interaction.d.ts","sourceRoot":"","sources":["../../../../../src/features/soft_navigations/aggregate/interaction.js"],"names":[],"mappings":"AAYA;;IAEI;AACJ;IAkBE,0FAaC;IA9BD,WAAmB;IACnB,uBAAgC;IAChC,gBAAU;IACV,qBAAqB;IACrB,oBAAoB;IACpB,eAAS;IACT,aAAO;IACP,cAAQ;IACR,+EAA+E;IAC/E,eAA8B;IAC9B,qBAAgB;IAChB,yBAAoB;IACpB,sBAAoB;IACpB,6BAA2B;IAC3B,cAAW;IACX,uBAAiB;IAIf,gBAAoC;IACpC,aAAsB;IAEtB,cAAiC;IACjC,wCAGE;IACF,mBAAyC;IAAxB,qBAAwB;IAEzC,YAAsE;IAAxD,YAAwD;IAGxE,gCAEC;IAED,iDAGC;IAED,mCAEC;IAED,8BAIC;IAED,kCAaC;IAqBD;;;;;OAKG;IACH,0BAHW,mBAAmB,WAM7B;IAGD,uBAAoB;IACpB,iCAA8B;IAC9B,sBAAmB;IAEnB;;;;;OAKG;IACH,qDAHW,KAAK,UAgDf;;CACF;wBA/JuB,YAAY"}
1
+ {"version":3,"file":"interaction.d.ts","sourceRoot":"","sources":["../../../../../src/features/soft_navigations/aggregate/interaction.js"],"names":[],"mappings":"AAYA;;IAEI;AACJ;IAoBE,0FAaC;IAhCD,WAAmB;IACnB,uBAAgC;IAChC,gBAAU;IACV,qBAAqB;IACrB,oBAAoB;IACpB,eAAS;IACT,aAAO;IACP,cAAQ;IACR,+EAA+E;IAC/E,eAA8B;IAC9B,qBAAgB;IAChB,yBAAoB;IACpB,sBAAoB;IACpB,6BAA2B;IAC3B,cAAW;IACX,kBAAa;IACb,uBAAiB;IACjB,wBAAkB;IAIhB,gBAAoC;IACpC,aAAsB;IAEtB,cAAiC;IACjC,wCAGE;IACF,mBAAyC;IAAxB,qBAAwB;IAEzC,YAAsE;IAAxD,YAAwD;IAGxE,iDAKC;IAED,gCAGC;IAED,oCAUC;IAED,8BAIC;IAED,6DAeC;IAmBD;;;;;;OAMG;IACH,0BAHW,mBAAmB,WAM7B;IAGD,uBAAoB;IACpB,iCAA8B;IAC9B,sBAAmB;IAEnB;;;;;OAKG;IACH,qDAHW,KAAK,UAgDf;;CACF;wBA7KuB,YAAY"}
@@ -1,7 +1,10 @@
1
1
  export const INTERACTION_TRIGGERS: string[];
2
+ export const POPSTATE_TRIGGER: "popstate";
2
3
  export const API_TRIGGER_NAME: "api";
3
4
  export const IPL_TRIGGER_NAME: "initialPageLoad";
4
5
  export const FEATURE_NAME: string;
6
+ export const NO_LONG_TASK_WINDOW: 5000;
7
+ export const POPSTATE_MERGE_WINDOW: 500;
5
8
  export namespace INTERACTION_TYPE {
6
9
  let INITIAL_PAGE_LOAD: string;
7
10
  let ROUTE_CHANGE: number;
@@ -15,6 +18,7 @@ export namespace NODE_TYPE {
15
18
  }
16
19
  export namespace INTERACTION_STATUS {
17
20
  let IP: string;
21
+ let PF: string;
18
22
  let FIN: string;
19
23
  let CAN: string;
20
24
  }
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/features/soft_navigations/constants.js"],"names":[],"mappings":"AAMA,4CAKC;AACD,+BAAgC,KAAK,CAAA;AACrC,+BAAgC,iBAAiB,CAAA;AAEjD,kCAAiD"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/features/soft_navigations/constants.js"],"names":[],"mappings":"AAMA,4CAIC;AACD,+BAAgC,UAAU,CAAA;AAC1C,+BAAgC,KAAK,CAAA;AACrC,+BAAgC,iBAAiB,CAAA;AAEjD,kCAAiD;AACjD,kCAAmC,IAAI,CAAA;AACvC,oCAAqC,GAAG,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/soft_navigations/instrument/index.js"],"names":[],"mappings":"AAsBA;IACE,2BAAiC;IACjC,2BAiDC;IA5BG,2CAA0C;CA6B/C;AAED,wCAAiC;+BAlEF,6BAA6B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/soft_navigations/instrument/index.js"],"names":[],"mappings":"AAsBA;IACE,2BAAiC;IACjC,2BAkDC;IAxCG,2CAA0C;CAyC/C;AAED,wCAAiC;+BAnEF,6BAA6B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newrelic/browser-agent",
3
- "version": "1.297.1-rc.0",
3
+ "version": "1.297.1-rc.1",
4
4
  "private": false,
5
5
  "author": "New Relic Browser Agent Team <browser-agent@newrelic.com>",
6
6
  "description": "New Relic Browser Agent",
@@ -11,6 +11,7 @@ import { ee } from '../event-emitter/contextual-ee'
11
11
  import { bundleId } from '../ids/bundle-id'
12
12
 
13
13
  export const flag = `nr@original:${bundleId}`
14
+ const LONG_TASK_THRESHOLD = 50
14
15
 
15
16
  /**
16
17
  * A convenience alias of `hasOwnProperty`.
@@ -95,7 +96,7 @@ export function createWrapperWithEmitter (emitter, always) {
95
96
  safeEmit(prefix + 'start', [args, originalThis, methodName], ctx, bubble)
96
97
 
97
98
  const fnStartTime = performance.now()
98
- let fnEndTime = fnStartTime
99
+ let fnEndTime
99
100
  try {
100
101
  result = fn.apply(originalThis, args)
101
102
  fnEndTime = performance.now()
@@ -109,16 +110,20 @@ export function createWrapperWithEmitter (emitter, always) {
109
110
  } finally {
110
111
  const duration = fnEndTime - fnStartTime
111
112
  const task = {
113
+ start: fnStartTime,
114
+ end: fnEndTime,
112
115
  duration,
113
- isLongTask: duration >= 50,
116
+ isLongTask: duration >= LONG_TASK_THRESHOLD,
114
117
  methodName,
115
118
  thrownError
116
119
  // could add more properties here later if needed by downstream features
117
120
  }
118
121
  // standalone long task message
119
- if (task.isLongTask) safeEmit('long-task', [task], ctx, bubble)
122
+ if (task.isLongTask) {
123
+ safeEmit('long-task', [task, originalThis], ctx, bubble)
124
+ }
120
125
  // -end message also includes the task execution info
121
- safeEmit(prefix + 'end', [args, originalThis, result, task], ctx, bubble)
126
+ safeEmit(prefix + 'end', [args, originalThis, result], ctx, bubble)
122
127
  }
123
128
  }
124
129
  }
@@ -11,6 +11,7 @@ import { FEATURE_NAMES } from '../../../loaders/features/features'
11
11
  import { AggregateBase } from '../../utils/aggregate-base'
12
12
  import { parseGQL } from './gql'
13
13
  import { nullable, numeric, getAddStringContext, addCustomAttributes } from '../../../common/serialize/bel-serializer'
14
+ import { gosNREUMOriginals } from '../../../common/window/nreum'
14
15
 
15
16
  export class Aggregate extends AggregateBase {
16
17
  static featureName = FEATURE_NAME
@@ -45,6 +46,13 @@ export class Aggregate extends AggregateBase {
45
46
  classThis.storeXhr(...arguments, this) // this switches the context back to the class instance while passing the NR context as an argument -- see "ctx" in storeXhr
46
47
  }, this.featureName, this.ee)
47
48
 
49
+ this.ee.on('long-task', (task, originator) => {
50
+ if (originator instanceof gosNREUMOriginals().o.XHR) { // any time a long task from XHR callback is observed, update the end time for soft nav use
51
+ const xhrMetadata = this.ee.context(originator)
52
+ xhrMetadata.latestLongtaskEnd = task.end
53
+ }
54
+ })
55
+
48
56
  this.waitForFlags(([])).then(() => this.drain())
49
57
  }
50
58
 
@@ -113,8 +121,8 @@ export class Aggregate extends AggregateBase {
113
121
  if (event.gql) this.reportSupportabilityMetric('Ajax/Events/GraphQL/Bytes-Added', stringify(event.gql).length)
114
122
 
115
123
  const softNavInUse = Boolean(this.agentRef.features?.[FEATURE_NAMES.softNav])
116
- if (softNavInUse) { // For newer soft nav (when running), pass the event to it for evaluation -- either part of an interaction or is given back
117
- handle('ajax', [event], undefined, FEATURE_NAMES.softNav, this.ee)
124
+ if (softNavInUse) { // For newer soft nav (when running), pass the event w/ info to it for evaluation -- either part of an interaction or is given back
125
+ handle('ajax', [event, ctx], undefined, FEATURE_NAMES.softNav, this.ee)
118
126
  } else if (ctx.spaNode) { // For old spa (when running), if the ajax happened inside an interaction, hold it until the interaction finishes
119
127
  const interactionId = ctx.spaNode.interaction.id
120
128
  this.underSpaEvents[interactionId] ??= []
@@ -96,6 +96,7 @@ function subscribeToEvents (agentRef, ee, handler, dt) {
96
96
  ctx.loadCaptureCalled = false
97
97
  ctx.params = this.params || {}
98
98
  ctx.metrics = this.metrics || {}
99
+ ctx.latestLongtaskEnd = 0
99
100
 
100
101
  xhr.addEventListener('load', function (event) {
101
102
  captureXhrData(ctx, xhr)
@@ -43,8 +43,8 @@ export class Aggregate extends AggregateBase {
43
43
 
44
44
  register('err', (...args) => this.storeError(...args), this.featureName, this.ee)
45
45
  register('ierr', (...args) => this.storeError(...args), this.featureName, this.ee)
46
- register('softNavFlush', (interactionId, wasFinished, softNavAttrs) =>
47
- this.onSoftNavNotification(interactionId, wasFinished, softNavAttrs), this.featureName, this.ee) // when an ixn is done or cancelled
46
+ register('softNavFlush', (interactionId, wasFinished, softNavAttrs, interactionEndTime) =>
47
+ this.onSoftNavNotification(interactionId, wasFinished, softNavAttrs, interactionEndTime), this.featureName, this.ee) // when an ixn is done or cancelled
48
48
 
49
49
  this.harvestOpts.aggregatorTypes = ['err', 'ierr', 'xhr'] // the types in EventAggregator this feature cares about
50
50
 
@@ -292,12 +292,16 @@ export class Aggregate extends AggregateBase {
292
292
  delete this.bufferedErrorsUnderSpa[interaction.id]
293
293
  }
294
294
 
295
- onSoftNavNotification (interactionId, wasFinished, softNavAttrs) {
295
+ onSoftNavNotification (interactionId, wasFinished, softNavAttrs, interactionEndTime) {
296
296
  if (this.blocked) return
297
297
 
298
- this.bufferedErrorsUnderSpa[interactionId]?.forEach(jsErrorEvent =>
299
- this.#storeJserrorForHarvest(jsErrorEvent, wasFinished, softNavAttrs) // this should not modify the re-used softNavAttrs contents
300
- )
298
+ this.bufferedErrorsUnderSpa[interactionId]?.forEach(jsErrorEvent => { // this should not modify the re-used softNavAttrs contents
299
+ if (!wasFinished) return this.#storeJserrorForHarvest(jsErrorEvent, false, softNavAttrs)
300
+
301
+ const startTime = jsErrorEvent[3].time // in storeError fn, the newMetrics obj contains the time passed to & used by SN to seek the ixn
302
+ if (startTime > interactionEndTime) return this.#storeJserrorForHarvest(jsErrorEvent, false, softNavAttrs) // disassociate any error that ultimately falls outside the final ixn span
303
+ return this.#storeJserrorForHarvest(jsErrorEvent, true, softNavAttrs)
304
+ })
301
305
  delete this.bufferedErrorsUnderSpa[interactionId] // wipe the list of jserrors so they aren't duplicated by another call to the same id
302
306
  }
303
307
  }