@newrelic/browser-agent 1.254.0 → 1.254.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.
- package/CHANGELOG.md +7 -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/timing/time-keeper.js +13 -18
- package/dist/cjs/features/page_view_event/aggregate/index.js +4 -3
- package/dist/esm/common/constants/env.cdn.js +1 -1
- package/dist/esm/common/constants/env.npm.js +1 -1
- package/dist/esm/common/timing/time-keeper.js +13 -18
- package/dist/esm/features/page_view_event/aggregate/index.js +4 -3
- package/dist/types/common/timing/time-keeper.d.ts +8 -2
- package/dist/types/common/timing/time-keeper.d.ts.map +1 -1
- package/dist/types/features/page_view_event/aggregate/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/common/timing/time-keeper.js +13 -19
- package/src/features/page_view_event/aggregate/index.js +5 -2
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,13 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [1.254.1](https://github.com/newrelic/newrelic-browser-agent/compare/v1.254.0...v1.254.1) (2024-03-26)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Bug Fixes
|
|
10
|
+
|
|
11
|
+
* Server Timing - Remove reliance on performance API ([#930](https://github.com/newrelic/newrelic-browser-agent/issues/930)) ([250efcd](https://github.com/newrelic/newrelic-browser-agent/commit/250efcd3bf0a730adbb9d5c45be0bf2f71189664))
|
|
12
|
+
|
|
6
13
|
## [1.254.0](https://github.com/newrelic/newrelic-browser-agent/compare/v1.253.0...v1.254.0) (2024-03-25)
|
|
7
14
|
|
|
8
15
|
|
|
@@ -12,7 +12,7 @@ exports.VERSION = exports.RRWEB_VERSION = exports.DIST_METHOD = exports.BUILD_EN
|
|
|
12
12
|
/**
|
|
13
13
|
* Exposes the version of the agent
|
|
14
14
|
*/
|
|
15
|
-
const VERSION = exports.VERSION = "1.254.
|
|
15
|
+
const VERSION = exports.VERSION = "1.254.1";
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Exposes the build type of the agent
|
|
@@ -12,7 +12,7 @@ exports.VERSION = exports.RRWEB_VERSION = exports.DIST_METHOD = exports.BUILD_EN
|
|
|
12
12
|
/**
|
|
13
13
|
* Exposes the version of the agent
|
|
14
14
|
*/
|
|
15
|
-
const VERSION = exports.VERSION = "1.254.
|
|
15
|
+
const VERSION = exports.VERSION = "1.254.1";
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Exposes the build type of the agent
|
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.TimeKeeper = void 0;
|
|
7
7
|
var _nreum = require("../window/nreum");
|
|
8
|
-
var _runtime = require("../constants/runtime");
|
|
9
8
|
var _config = require("../config/config");
|
|
10
9
|
/**
|
|
11
10
|
* Class used to adjust the timestamp of harvested data to New Relic server time. This
|
|
@@ -41,28 +40,16 @@ class TimeKeeper {
|
|
|
41
40
|
/**
|
|
42
41
|
* Process a rum request to calculate NR server time.
|
|
43
42
|
* @param rumRequest {XMLHttpRequest} The xhr for the rum request
|
|
44
|
-
* @param
|
|
43
|
+
* @param startTime {number} The start time of the RUM request
|
|
44
|
+
* @param endTime {number} The end time of the RUM request
|
|
45
45
|
*/
|
|
46
|
-
processRumRequest(rumRequest,
|
|
46
|
+
processRumRequest(rumRequest, startTime, endTime) {
|
|
47
47
|
const responseDateHeader = rumRequest.getResponseHeader('Date');
|
|
48
48
|
if (!responseDateHeader) {
|
|
49
49
|
throw new Error('Missing date header on rum response.');
|
|
50
50
|
}
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
-
throw new Error('Missing rum request performance entry.');
|
|
54
|
-
}
|
|
55
|
-
let medianRumOffset = 0;
|
|
56
|
-
let serverOffset = 0;
|
|
57
|
-
if (typeof resourceEntries[0].responseStart === 'number' && resourceEntries[0].responseStart !== 0) {
|
|
58
|
-
// Cors is enabled and we can make a more accurate calculation of NR server time
|
|
59
|
-
medianRumOffset = (resourceEntries[0].responseStart - resourceEntries[0].requestStart) / 2;
|
|
60
|
-
serverOffset = Math.floor(resourceEntries[0].requestStart + medianRumOffset);
|
|
61
|
-
} else {
|
|
62
|
-
// Cors is disabled or erred, we need to use a less accurate calculation
|
|
63
|
-
medianRumOffset = (resourceEntries[0].responseEnd - resourceEntries[0].fetchStart) / 2;
|
|
64
|
-
serverOffset = Math.floor(resourceEntries[0].fetchStart + medianRumOffset);
|
|
65
|
-
}
|
|
51
|
+
const medianRumOffset = (endTime - startTime) / 2;
|
|
52
|
+
const serverOffset = Math.floor(startTime + medianRumOffset);
|
|
66
53
|
|
|
67
54
|
// Corrected page origin time
|
|
68
55
|
this.#correctedOriginTime = Math.floor(Date.parse(responseDateHeader) - serverOffset);
|
|
@@ -90,5 +77,13 @@ class TimeKeeper {
|
|
|
90
77
|
correctAbsoluteTimestamp(timestamp) {
|
|
91
78
|
return Math.floor(timestamp - this.#localTimeDiff);
|
|
92
79
|
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Returns the current time offset from page origin.
|
|
83
|
+
* @return {number}
|
|
84
|
+
*/
|
|
85
|
+
now() {
|
|
86
|
+
return Math.floor(performance.now());
|
|
87
|
+
}
|
|
93
88
|
}
|
|
94
89
|
exports.TimeKeeper = TimeKeeper;
|
|
@@ -116,6 +116,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
|
|
|
116
116
|
}
|
|
117
117
|
queryParameters.fp = _firstPaint.firstPaint.current.value;
|
|
118
118
|
queryParameters.fcp = _firstContentfulPaint.firstContentfulPaint.current.value;
|
|
119
|
+
const rumStartTime = this.timeKeeper.now();
|
|
119
120
|
harvester.send({
|
|
120
121
|
endpoint: 'rum',
|
|
121
122
|
payload: {
|
|
@@ -130,16 +131,16 @@ class Aggregate extends _aggregateBase.AggregateBase {
|
|
|
130
131
|
let {
|
|
131
132
|
status,
|
|
132
133
|
responseText,
|
|
133
|
-
xhr
|
|
134
|
-
fullUrl
|
|
134
|
+
xhr
|
|
135
135
|
} = _ref3;
|
|
136
|
+
const rumEndTime = this.timeKeeper.now();
|
|
136
137
|
if (status >= 400 || status === 0) {
|
|
137
138
|
// Adding retry logic for the rum call will be a separate change
|
|
138
139
|
this.ee.abort();
|
|
139
140
|
return;
|
|
140
141
|
}
|
|
141
142
|
try {
|
|
142
|
-
this.timeKeeper.processRumRequest(xhr,
|
|
143
|
+
this.timeKeeper.processRumRequest(xhr, rumStartTime, rumEndTime);
|
|
143
144
|
} catch (error) {
|
|
144
145
|
(0, _handle.handle)(_constants2.SUPPORTABILITY_METRIC_CHANNEL, ['PVE/NRTime/Calculation/Failed'], undefined, _features.FEATURE_NAMES.metrics, this.ee);
|
|
145
146
|
(0, _drain.drain)(this.agentIdentifier, _features.FEATURE_NAMES.metrics, true);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { gosNREUM } from '../window/nreum';
|
|
2
|
-
import { globalScope } from '../constants/runtime';
|
|
3
2
|
import { getRuntime } from '../config/config';
|
|
4
3
|
|
|
5
4
|
/**
|
|
@@ -36,28 +35,16 @@ export class TimeKeeper {
|
|
|
36
35
|
/**
|
|
37
36
|
* Process a rum request to calculate NR server time.
|
|
38
37
|
* @param rumRequest {XMLHttpRequest} The xhr for the rum request
|
|
39
|
-
* @param
|
|
38
|
+
* @param startTime {number} The start time of the RUM request
|
|
39
|
+
* @param endTime {number} The end time of the RUM request
|
|
40
40
|
*/
|
|
41
|
-
processRumRequest(rumRequest,
|
|
41
|
+
processRumRequest(rumRequest, startTime, endTime) {
|
|
42
42
|
const responseDateHeader = rumRequest.getResponseHeader('Date');
|
|
43
43
|
if (!responseDateHeader) {
|
|
44
44
|
throw new Error('Missing date header on rum response.');
|
|
45
45
|
}
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
throw new Error('Missing rum request performance entry.');
|
|
49
|
-
}
|
|
50
|
-
let medianRumOffset = 0;
|
|
51
|
-
let serverOffset = 0;
|
|
52
|
-
if (typeof resourceEntries[0].responseStart === 'number' && resourceEntries[0].responseStart !== 0) {
|
|
53
|
-
// Cors is enabled and we can make a more accurate calculation of NR server time
|
|
54
|
-
medianRumOffset = (resourceEntries[0].responseStart - resourceEntries[0].requestStart) / 2;
|
|
55
|
-
serverOffset = Math.floor(resourceEntries[0].requestStart + medianRumOffset);
|
|
56
|
-
} else {
|
|
57
|
-
// Cors is disabled or erred, we need to use a less accurate calculation
|
|
58
|
-
medianRumOffset = (resourceEntries[0].responseEnd - resourceEntries[0].fetchStart) / 2;
|
|
59
|
-
serverOffset = Math.floor(resourceEntries[0].fetchStart + medianRumOffset);
|
|
60
|
-
}
|
|
46
|
+
const medianRumOffset = (endTime - startTime) / 2;
|
|
47
|
+
const serverOffset = Math.floor(startTime + medianRumOffset);
|
|
61
48
|
|
|
62
49
|
// Corrected page origin time
|
|
63
50
|
this.#correctedOriginTime = Math.floor(Date.parse(responseDateHeader) - serverOffset);
|
|
@@ -85,4 +72,12 @@ export class TimeKeeper {
|
|
|
85
72
|
correctAbsoluteTimestamp(timestamp) {
|
|
86
73
|
return Math.floor(timestamp - this.#localTimeDiff);
|
|
87
74
|
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Returns the current time offset from page origin.
|
|
78
|
+
* @return {number}
|
|
79
|
+
*/
|
|
80
|
+
now() {
|
|
81
|
+
return Math.floor(performance.now());
|
|
82
|
+
}
|
|
88
83
|
}
|
|
@@ -108,6 +108,7 @@ export class Aggregate extends AggregateBase {
|
|
|
108
108
|
}
|
|
109
109
|
queryParameters.fp = firstPaint.current.value;
|
|
110
110
|
queryParameters.fcp = firstContentfulPaint.current.value;
|
|
111
|
+
const rumStartTime = this.timeKeeper.now();
|
|
111
112
|
harvester.send({
|
|
112
113
|
endpoint: 'rum',
|
|
113
114
|
payload: {
|
|
@@ -122,16 +123,16 @@ export class Aggregate extends AggregateBase {
|
|
|
122
123
|
let {
|
|
123
124
|
status,
|
|
124
125
|
responseText,
|
|
125
|
-
xhr
|
|
126
|
-
fullUrl
|
|
126
|
+
xhr
|
|
127
127
|
} = _ref3;
|
|
128
|
+
const rumEndTime = this.timeKeeper.now();
|
|
128
129
|
if (status >= 400 || status === 0) {
|
|
129
130
|
// Adding retry logic for the rum call will be a separate change
|
|
130
131
|
this.ee.abort();
|
|
131
132
|
return;
|
|
132
133
|
}
|
|
133
134
|
try {
|
|
134
|
-
this.timeKeeper.processRumRequest(xhr,
|
|
135
|
+
this.timeKeeper.processRumRequest(xhr, rumStartTime, rumEndTime);
|
|
135
136
|
} catch (error) {
|
|
136
137
|
handle(SUPPORTABILITY_METRIC_CHANNEL, ['PVE/NRTime/Calculation/Failed'], undefined, FEATURE_NAMES.metrics, this.ee);
|
|
137
138
|
drain(this.agentIdentifier, FEATURE_NAMES.metrics, true);
|
|
@@ -10,9 +10,10 @@ export class TimeKeeper {
|
|
|
10
10
|
/**
|
|
11
11
|
* Process a rum request to calculate NR server time.
|
|
12
12
|
* @param rumRequest {XMLHttpRequest} The xhr for the rum request
|
|
13
|
-
* @param
|
|
13
|
+
* @param startTime {number} The start time of the RUM request
|
|
14
|
+
* @param endTime {number} The end time of the RUM request
|
|
14
15
|
*/
|
|
15
|
-
processRumRequest(rumRequest: XMLHttpRequest,
|
|
16
|
+
processRumRequest(rumRequest: XMLHttpRequest, startTime: number, endTime: number): void;
|
|
16
17
|
/**
|
|
17
18
|
* Converts a page origin relative time to an absolute timestamp
|
|
18
19
|
* corrected to NR server time.
|
|
@@ -26,6 +27,11 @@ export class TimeKeeper {
|
|
|
26
27
|
* @return {number} Corrected unix/epoch timestamp
|
|
27
28
|
*/
|
|
28
29
|
correctAbsoluteTimestamp(timestamp: number): number;
|
|
30
|
+
/**
|
|
31
|
+
* Returns the current time offset from page origin.
|
|
32
|
+
* @return {number}
|
|
33
|
+
*/
|
|
34
|
+
now(): number;
|
|
29
35
|
#private;
|
|
30
36
|
}
|
|
31
37
|
//# sourceMappingURL=time-keeper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"time-keeper.d.ts","sourceRoot":"","sources":["../../../../src/common/timing/time-keeper.js"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"time-keeper.d.ts","sourceRoot":"","sources":["../../../../src/common/timing/time-keeper.js"],"names":[],"mappings":"AAGA;;;;GAIG;AACH;IAoBE,iEAKC;IATD,wBAEC;IASD,sCAEC;IAED;;;;;OAKG;IACH,8BAJsB,cAAc,aACf,MAAM,WACR,MAAM,QAkBxB;IAED;;;;;OAKG;IACH,uCAHwB,MAAM,GACjB,MAAM,CAIlB;IAED;;;;OAIG;IACH,oCAHqB,MAAM,GACf,MAAM,CAIjB;IAED;;;OAGG;IACH,OAFY,MAAM,CAIjB;;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/page_view_event/aggregate/index.js"],"names":[],"mappings":"AAkBA;IACE,2BAA2C;IAC3C,mDAoBC;IAjBC,wBAAwB;IACxB,8BAA8B;IAC9B,8BAA8B;IAiBhC,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/features/page_view_event/aggregate/index.js"],"names":[],"mappings":"AAkBA;IACE,2BAA2C;IAC3C,mDAoBC;IAjBC,wBAAwB;IACxB,8BAA8B;IAC9B,8BAA8B;IAiBhC,gBA+FC;CACF;8BAjI6B,4BAA4B"}
|
package/package.json
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { gosNREUM } from '../window/nreum'
|
|
2
|
-
import { globalScope } from '../constants/runtime'
|
|
3
2
|
import { getRuntime } from '../config/config'
|
|
4
3
|
|
|
5
4
|
/**
|
|
@@ -41,30 +40,17 @@ export class TimeKeeper {
|
|
|
41
40
|
/**
|
|
42
41
|
* Process a rum request to calculate NR server time.
|
|
43
42
|
* @param rumRequest {XMLHttpRequest} The xhr for the rum request
|
|
44
|
-
* @param
|
|
43
|
+
* @param startTime {number} The start time of the RUM request
|
|
44
|
+
* @param endTime {number} The end time of the RUM request
|
|
45
45
|
*/
|
|
46
|
-
processRumRequest (rumRequest,
|
|
46
|
+
processRumRequest (rumRequest, startTime, endTime) {
|
|
47
47
|
const responseDateHeader = rumRequest.getResponseHeader('Date')
|
|
48
48
|
if (!responseDateHeader) {
|
|
49
49
|
throw new Error('Missing date header on rum response.')
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
throw new Error('Missing rum request performance entry.')
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
let medianRumOffset = 0
|
|
58
|
-
let serverOffset = 0
|
|
59
|
-
if (typeof resourceEntries[0].responseStart === 'number' && resourceEntries[0].responseStart !== 0) {
|
|
60
|
-
// Cors is enabled and we can make a more accurate calculation of NR server time
|
|
61
|
-
medianRumOffset = (resourceEntries[0].responseStart - resourceEntries[0].requestStart) / 2
|
|
62
|
-
serverOffset = Math.floor(resourceEntries[0].requestStart + medianRumOffset)
|
|
63
|
-
} else {
|
|
64
|
-
// Cors is disabled or erred, we need to use a less accurate calculation
|
|
65
|
-
medianRumOffset = (resourceEntries[0].responseEnd - resourceEntries[0].fetchStart) / 2
|
|
66
|
-
serverOffset = Math.floor(resourceEntries[0].fetchStart + medianRumOffset)
|
|
67
|
-
}
|
|
52
|
+
const medianRumOffset = (endTime - startTime) / 2
|
|
53
|
+
const serverOffset = Math.floor(startTime + medianRumOffset)
|
|
68
54
|
|
|
69
55
|
// Corrected page origin time
|
|
70
56
|
this.#correctedOriginTime = Math.floor(Date.parse(responseDateHeader) - serverOffset)
|
|
@@ -93,4 +79,12 @@ export class TimeKeeper {
|
|
|
93
79
|
correctAbsoluteTimestamp (timestamp) {
|
|
94
80
|
return Math.floor(timestamp - this.#localTimeDiff)
|
|
95
81
|
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Returns the current time offset from page origin.
|
|
85
|
+
* @return {number}
|
|
86
|
+
*/
|
|
87
|
+
now () {
|
|
88
|
+
return Math.floor(performance.now())
|
|
89
|
+
}
|
|
96
90
|
}
|
|
@@ -100,11 +100,14 @@ export class Aggregate extends AggregateBase {
|
|
|
100
100
|
queryParameters.fp = firstPaint.current.value
|
|
101
101
|
queryParameters.fcp = firstContentfulPaint.current.value
|
|
102
102
|
|
|
103
|
+
const rumStartTime = this.timeKeeper.now()
|
|
103
104
|
harvester.send({
|
|
104
105
|
endpoint: 'rum',
|
|
105
106
|
payload: { qs: queryParameters, body },
|
|
106
107
|
opts: { needResponse: true, sendEmptyBody: true },
|
|
107
|
-
cbFinished: ({ status, responseText, xhr
|
|
108
|
+
cbFinished: ({ status, responseText, xhr }) => {
|
|
109
|
+
const rumEndTime = this.timeKeeper.now()
|
|
110
|
+
|
|
108
111
|
if (status >= 400 || status === 0) {
|
|
109
112
|
// Adding retry logic for the rum call will be a separate change
|
|
110
113
|
this.ee.abort()
|
|
@@ -112,7 +115,7 @@ export class Aggregate extends AggregateBase {
|
|
|
112
115
|
}
|
|
113
116
|
|
|
114
117
|
try {
|
|
115
|
-
this.timeKeeper.processRumRequest(xhr,
|
|
118
|
+
this.timeKeeper.processRumRequest(xhr, rumStartTime, rumEndTime)
|
|
116
119
|
} catch (error) {
|
|
117
120
|
handle(SUPPORTABILITY_METRIC_CHANNEL, ['PVE/NRTime/Calculation/Failed'], undefined, FEATURE_NAMES.metrics, this.ee)
|
|
118
121
|
drain(this.agentIdentifier, FEATURE_NAMES.metrics, true)
|