@newrelic/browser-agent 1.302.0-rc.8 → 1.302.0-rc.9

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 (32) 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/features/generic_events/aggregate/index.js +2 -2
  4. package/dist/cjs/interfaces/registered-entity.js +11 -0
  5. package/dist/cjs/loaders/api/measure.js +36 -35
  6. package/dist/cjs/loaders/api/register-api-types.js +1 -0
  7. package/dist/cjs/loaders/api/register.js +8 -0
  8. package/dist/cjs/loaders/api-base.js +1 -1
  9. package/dist/esm/common/constants/env.cdn.js +1 -1
  10. package/dist/esm/common/constants/env.npm.js +1 -1
  11. package/dist/esm/features/generic_events/aggregate/index.js +2 -2
  12. package/dist/esm/interfaces/registered-entity.js +11 -0
  13. package/dist/esm/loaders/api/measure.js +35 -35
  14. package/dist/esm/loaders/api/register-api-types.js +1 -0
  15. package/dist/esm/loaders/api/register.js +8 -0
  16. package/dist/esm/loaders/api-base.js +1 -1
  17. package/dist/types/interfaces/registered-entity.d.ts +18 -0
  18. package/dist/types/interfaces/registered-entity.d.ts.map +1 -1
  19. package/dist/types/loaders/api/measure.d.ts +3 -0
  20. package/dist/types/loaders/api/measure.d.ts.map +1 -1
  21. package/dist/types/loaders/api/register-api-types.d.ts +9 -0
  22. package/dist/types/loaders/api/register-api-types.d.ts.map +1 -1
  23. package/dist/types/loaders/api/register.d.ts.map +1 -1
  24. package/dist/types/loaders/api-base.d.ts +7 -2
  25. package/dist/types/loaders/api-base.d.ts.map +1 -1
  26. package/package.json +1 -1
  27. package/src/features/generic_events/aggregate/index.js +2 -2
  28. package/src/interfaces/registered-entity.js +11 -0
  29. package/src/loaders/api/measure.js +34 -33
  30. package/src/loaders/api/register-api-types.js +1 -0
  31. package/src/loaders/api/register.js +2 -0
  32. package/src/loaders/api-base.js +1 -1
@@ -17,7 +17,7 @@ exports.VERSION = exports.RRWEB_VERSION = exports.RRWEB_PACKAGE_NAME = exports.D
17
17
  /**
18
18
  * Exposes the version of the agent
19
19
  */
20
- const VERSION = exports.VERSION = "1.302.0-rc.8";
20
+ const VERSION = exports.VERSION = "1.302.0-rc.9";
21
21
 
22
22
  /**
23
23
  * Exposes the build type of the agent
@@ -17,7 +17,7 @@ exports.VERSION = exports.RRWEB_VERSION = exports.RRWEB_PACKAGE_NAME = exports.D
17
17
  /**
18
18
  * Exposes the version of the agent
19
19
  */
20
- const VERSION = exports.VERSION = "1.302.0-rc.8";
20
+ const VERSION = exports.VERSION = "1.302.0-rc.9";
21
21
 
22
22
  /**
23
23
  * Exposes the build type of the agent
@@ -238,7 +238,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
238
238
  }
239
239
  }, this.featureName, this.ee);
240
240
  }
241
- (0, _registerHandler.registerHandler)('api-measure', (args, n) => {
241
+ (0, _registerHandler.registerHandler)('api-measure', (args, n, target) => {
242
242
  const {
243
243
  start,
244
244
  duration,
@@ -252,7 +252,7 @@ class Aggregate extends _aggregateBase.AggregateBase {
252
252
  entryDuration: duration,
253
253
  entryType: 'measure'
254
254
  };
255
- this.addEvent(event);
255
+ this.addEvent(event, target);
256
256
  }, this.featureName, this.ee);
257
257
  this.drain();
258
258
  });
@@ -64,6 +64,17 @@ class RegisteredEntity {
64
64
  (0, _console.warn)(35, 'recordCustomEvent');
65
65
  }
66
66
 
67
+ /**
68
+ * Measures a task that is recorded as a BrowserPerformance event.
69
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/measure/}
70
+ * @param {string} name The name of the task
71
+ * @param {{start: number, end: number, duration: number, customAttributes: object}} [options] An object used to control the way the measure API operates
72
+ * @returns {{start: number, end: number, duration: number, customAttributes: object}} Measurement details
73
+ */
74
+ measure(name, options) {
75
+ (0, _console.warn)(35, 'measure');
76
+ }
77
+
67
78
  /**
68
79
  * Adds a user-defined attribute name and value to subsequent events on the page for the registered target. Note -- the persist flag does not work with the register API.
69
80
  * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setcustomattribute/}
@@ -3,6 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
+ exports.measure = measure;
6
7
  exports.setupMeasureAPI = setupMeasureAPI;
7
8
  var _handle = require("../../common/event-emitter/handle");
8
9
  var _now = require("../../common/timing/now");
@@ -16,45 +17,45 @@ var _sharedHandlers = require("./sharedHandlers");
16
17
  */
17
18
 
18
19
  function setupMeasureAPI(agent) {
19
- (0, _sharedHandlers.setupAPI)(_constants.MEASURE, function (name, options) {
20
- const n = (0, _now.now)();
21
- const {
22
- start,
23
- end,
24
- customAttributes
25
- } = options || {};
26
- const returnObj = {
27
- customAttributes: customAttributes || {}
28
- };
29
- if (typeof returnObj.customAttributes !== 'object' || typeof name !== 'string' || name.length === 0) {
30
- (0, _console.warn)(57);
31
- return;
32
- }
20
+ (0, _sharedHandlers.setupAPI)(_constants.MEASURE, (name, options) => measure(name, options, agent), agent);
21
+ }
22
+ function measure(name, options, agentRef, target, timestamp = (0, _now.now)()) {
23
+ const {
24
+ start,
25
+ end,
26
+ customAttributes
27
+ } = options || {};
28
+ const returnObj = {
29
+ customAttributes: customAttributes || {}
30
+ };
31
+ if (typeof returnObj.customAttributes !== 'object' || typeof name !== 'string' || name.length === 0) {
32
+ (0, _console.warn)(57);
33
+ return;
34
+ }
33
35
 
34
- /**
36
+ /**
35
37
  * getValueFromTiming - Helper function to extract a numeric value from a supplied option.
36
38
  * @param {Number|PerformanceMark} [timing] The timing value
37
39
  * @param {Number} [d] The default value to return if timing is invalid
38
40
  * @returns {Number} The timing value or the default value
39
41
  */
40
- const getValueFromTiming = (timing, d) => {
41
- if (timing == null) return d;
42
- if (typeof timing === 'number') return timing;
43
- if (timing instanceof PerformanceMark) return timing.startTime;
44
- return Number.NaN;
45
- };
46
- returnObj.start = getValueFromTiming(start, 0);
47
- returnObj.end = getValueFromTiming(end, n);
48
- if (Number.isNaN(returnObj.start) || Number.isNaN(returnObj.end)) {
49
- (0, _console.warn)(57);
50
- return;
51
- }
52
- returnObj.duration = returnObj.end - returnObj.start;
53
- if (returnObj.duration < 0) {
54
- (0, _console.warn)(58);
55
- return;
56
- }
57
- (0, _handle.handle)(_constants.prefix + _constants.MEASURE, [returnObj, name], undefined, _features.FEATURE_NAMES.genericEvents, agent.ee);
58
- return returnObj;
59
- }, agent);
42
+ const getValueFromTiming = (timing, d) => {
43
+ if (timing == null) return d;
44
+ if (typeof timing === 'number') return timing;
45
+ if (timing instanceof PerformanceMark) return timing.startTime;
46
+ return Number.NaN;
47
+ };
48
+ returnObj.start = getValueFromTiming(start, 0);
49
+ returnObj.end = getValueFromTiming(end, timestamp);
50
+ if (Number.isNaN(returnObj.start) || Number.isNaN(returnObj.end)) {
51
+ (0, _console.warn)(57);
52
+ return;
53
+ }
54
+ returnObj.duration = returnObj.end - returnObj.start;
55
+ if (returnObj.duration < 0) {
56
+ (0, _console.warn)(58);
57
+ return;
58
+ }
59
+ (0, _handle.handle)(_constants.prefix + _constants.MEASURE, [returnObj, name, target], undefined, _features.FEATURE_NAMES.genericEvents, agentRef.ee);
60
+ return returnObj;
60
61
  }
@@ -14,6 +14,7 @@ exports.default = void 0;
14
14
  * @property {(message: string, options?: { customAttributes?: object, level?: 'ERROR' | 'TRACE' | 'DEBUG' | 'INFO' | 'WARN'}) => void} log - Capture a log for the registered entity.
15
15
  * @property {(error: Error | string, customAttributes?: object) => void} noticeError - Notice an error for the registered entity.
16
16
  * @property {(eventType: string, attributes?: Object) => void} recordCustomEvent - Record a custom event for the registered entity.
17
+ * @property {(eventType: string, options?: {start: number, end: number, duration: number, customAttributes: object}) => {{start: number, end: number, duration: number, customAttributes: object}}} measure - Measures a task that is recorded as a BrowserPerformance event.
17
18
  * @property {(value: string | null) => void} setApplicationVersion - Add an application.version attribute to all outgoing data for the registered entity.
18
19
  * @property {(name: string, value: string | number | boolean | null, persist?: boolean) => void} setCustomAttribute - Add a custom attribute to outgoing data for the registered entity.
19
20
  * @property {(value: string | null) => void} setUserId - Add an enduser.id attribute to all outgoing API data for the registered entity.
@@ -17,6 +17,7 @@ var _log = require("./log");
17
17
  var _addPageAction = require("./addPageAction");
18
18
  var _noticeError = require("./noticeError");
19
19
  var _invoke = require("../../common/util/invoke");
20
+ var _measure = require("./measure");
20
21
  var _recordCustomEvent = require("./recordCustomEvent");
21
22
  /**
22
23
  * Copyright 2020-2025 New Relic, Inc. All rights reserved.
@@ -101,6 +102,13 @@ function buildRegisterApi(agentRef, target) {
101
102
  ...(options.customAttributes || {})
102
103
  }
103
104
  }, agentRef], target),
105
+ measure: (name, options = {}) => report(_measure.measure, [name, {
106
+ ...options,
107
+ customAttributes: {
108
+ ...attrs,
109
+ ...(options.customAttributes || {})
110
+ }
111
+ }, agentRef], target),
104
112
  noticeError: (error, attributes = {}) => report(_noticeError.noticeError, [error, {
105
113
  ...attrs,
106
114
  ...attributes
@@ -224,7 +224,7 @@ class ApiBase {
224
224
  * Measures a task that is recorded as a BrowserPerformance event.
225
225
  * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/measure/}
226
226
  * @param {string} name The name of the task
227
- * @param {object?} options An object used to control the way the measure API operates
227
+ * @param {{start: number, end: number, duration: number, customAttributes: object}} [options] An object used to control the way the measure API operates
228
228
  * @returns {{start: number, end: number, duration: number, customAttributes: object}} Measurement details
229
229
  */
230
230
  measure(name, options) {
@@ -11,7 +11,7 @@
11
11
  /**
12
12
  * Exposes the version of the agent
13
13
  */
14
- export const VERSION = "1.302.0-rc.8";
14
+ export const VERSION = "1.302.0-rc.9";
15
15
 
16
16
  /**
17
17
  * Exposes the build type of the agent
@@ -11,7 +11,7 @@
11
11
  /**
12
12
  * Exposes the version of the agent
13
13
  */
14
- export const VERSION = "1.302.0-rc.8";
14
+ export const VERSION = "1.302.0-rc.9";
15
15
 
16
16
  /**
17
17
  * Exposes the build type of the agent
@@ -231,7 +231,7 @@ export class Aggregate extends AggregateBase {
231
231
  }
232
232
  }, this.featureName, this.ee);
233
233
  }
234
- registerHandler('api-measure', (args, n) => {
234
+ registerHandler('api-measure', (args, n, target) => {
235
235
  const {
236
236
  start,
237
237
  duration,
@@ -245,7 +245,7 @@ export class Aggregate extends AggregateBase {
245
245
  entryDuration: duration,
246
246
  entryType: 'measure'
247
247
  };
248
- this.addEvent(event);
248
+ this.addEvent(event, target);
249
249
  }, this.featureName, this.ee);
250
250
  this.drain();
251
251
  });
@@ -58,6 +58,17 @@ export class RegisteredEntity {
58
58
  warn(35, 'recordCustomEvent');
59
59
  }
60
60
 
61
+ /**
62
+ * Measures a task that is recorded as a BrowserPerformance event.
63
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/measure/}
64
+ * @param {string} name The name of the task
65
+ * @param {{start: number, end: number, duration: number, customAttributes: object}} [options] An object used to control the way the measure API operates
66
+ * @returns {{start: number, end: number, duration: number, customAttributes: object}} Measurement details
67
+ */
68
+ measure(name, options) {
69
+ warn(35, 'measure');
70
+ }
71
+
61
72
  /**
62
73
  * Adds a user-defined attribute name and value to subsequent events on the page for the registered target. Note -- the persist flag does not work with the register API.
63
74
  * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setcustomattribute/}
@@ -9,45 +9,45 @@ import { FEATURE_NAMES } from '../features/features';
9
9
  import { prefix, MEASURE } from './constants';
10
10
  import { setupAPI } from './sharedHandlers';
11
11
  export function setupMeasureAPI(agent) {
12
- setupAPI(MEASURE, function (name, options) {
13
- const n = now();
14
- const {
15
- start,
16
- end,
17
- customAttributes
18
- } = options || {};
19
- const returnObj = {
20
- customAttributes: customAttributes || {}
21
- };
22
- if (typeof returnObj.customAttributes !== 'object' || typeof name !== 'string' || name.length === 0) {
23
- warn(57);
24
- return;
25
- }
12
+ setupAPI(MEASURE, (name, options) => measure(name, options, agent), agent);
13
+ }
14
+ export function measure(name, options, agentRef, target, timestamp = now()) {
15
+ const {
16
+ start,
17
+ end,
18
+ customAttributes
19
+ } = options || {};
20
+ const returnObj = {
21
+ customAttributes: customAttributes || {}
22
+ };
23
+ if (typeof returnObj.customAttributes !== 'object' || typeof name !== 'string' || name.length === 0) {
24
+ warn(57);
25
+ return;
26
+ }
26
27
 
27
- /**
28
+ /**
28
29
  * getValueFromTiming - Helper function to extract a numeric value from a supplied option.
29
30
  * @param {Number|PerformanceMark} [timing] The timing value
30
31
  * @param {Number} [d] The default value to return if timing is invalid
31
32
  * @returns {Number} The timing value or the default value
32
33
  */
33
- const getValueFromTiming = (timing, d) => {
34
- if (timing == null) return d;
35
- if (typeof timing === 'number') return timing;
36
- if (timing instanceof PerformanceMark) return timing.startTime;
37
- return Number.NaN;
38
- };
39
- returnObj.start = getValueFromTiming(start, 0);
40
- returnObj.end = getValueFromTiming(end, n);
41
- if (Number.isNaN(returnObj.start) || Number.isNaN(returnObj.end)) {
42
- warn(57);
43
- return;
44
- }
45
- returnObj.duration = returnObj.end - returnObj.start;
46
- if (returnObj.duration < 0) {
47
- warn(58);
48
- return;
49
- }
50
- handle(prefix + MEASURE, [returnObj, name], undefined, FEATURE_NAMES.genericEvents, agent.ee);
51
- return returnObj;
52
- }, agent);
34
+ const getValueFromTiming = (timing, d) => {
35
+ if (timing == null) return d;
36
+ if (typeof timing === 'number') return timing;
37
+ if (timing instanceof PerformanceMark) return timing.startTime;
38
+ return Number.NaN;
39
+ };
40
+ returnObj.start = getValueFromTiming(start, 0);
41
+ returnObj.end = getValueFromTiming(end, timestamp);
42
+ if (Number.isNaN(returnObj.start) || Number.isNaN(returnObj.end)) {
43
+ warn(57);
44
+ return;
45
+ }
46
+ returnObj.duration = returnObj.end - returnObj.start;
47
+ if (returnObj.duration < 0) {
48
+ warn(58);
49
+ return;
50
+ }
51
+ handle(prefix + MEASURE, [returnObj, name, target], undefined, FEATURE_NAMES.genericEvents, agentRef.ee);
52
+ return returnObj;
53
53
  }
@@ -9,6 +9,7 @@
9
9
  * @property {(message: string, options?: { customAttributes?: object, level?: 'ERROR' | 'TRACE' | 'DEBUG' | 'INFO' | 'WARN'}) => void} log - Capture a log for the registered entity.
10
10
  * @property {(error: Error | string, customAttributes?: object) => void} noticeError - Notice an error for the registered entity.
11
11
  * @property {(eventType: string, attributes?: Object) => void} recordCustomEvent - Record a custom event for the registered entity.
12
+ * @property {(eventType: string, options?: {start: number, end: number, duration: number, customAttributes: object}) => {{start: number, end: number, duration: number, customAttributes: object}}} measure - Measures a task that is recorded as a BrowserPerformance event.
12
13
  * @property {(value: string | null) => void} setApplicationVersion - Add an application.version attribute to all outgoing data for the registered entity.
13
14
  * @property {(name: string, value: string | number | boolean | null, persist?: boolean) => void} setCustomAttribute - Add a custom attribute to outgoing data for the registered entity.
14
15
  * @property {(value: string | null) => void} setUserId - Add an enduser.id attribute to all outgoing API data for the registered entity.
@@ -14,6 +14,7 @@ import { log } from './log';
14
14
  import { addPageAction } from './addPageAction';
15
15
  import { noticeError } from './noticeError';
16
16
  import { single } from '../../common/util/invoke';
17
+ import { measure } from './measure';
17
18
  import { recordCustomEvent } from './recordCustomEvent';
18
19
 
19
20
  /**
@@ -94,6 +95,13 @@ export function buildRegisterApi(agentRef, target) {
94
95
  ...(options.customAttributes || {})
95
96
  }
96
97
  }, agentRef], target),
98
+ measure: (name, options = {}) => report(measure, [name, {
99
+ ...options,
100
+ customAttributes: {
101
+ ...attrs,
102
+ ...(options.customAttributes || {})
103
+ }
104
+ }, agentRef], target),
97
105
  noticeError: (error, attributes = {}) => report(noticeError, [error, {
98
106
  ...attrs,
99
107
  ...attributes
@@ -218,7 +218,7 @@ export class ApiBase {
218
218
  * Measures a task that is recorded as a BrowserPerformance event.
219
219
  * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/measure/}
220
220
  * @param {string} name The name of the task
221
- * @param {object?} options An object used to control the way the measure API operates
221
+ * @param {{start: number, end: number, duration: number, customAttributes: object}} [options] An object used to control the way the measure API operates
222
222
  * @returns {{start: number, end: number, duration: number, customAttributes: object}} Measurement details
223
223
  */
224
224
  measure(name, options) {
@@ -32,6 +32,24 @@ export class RegisteredEntity {
32
32
  * @param {Object} [attributes] JSON object with one or more key/value pairs. For example: {key:"value"}.
33
33
  */
34
34
  recordCustomEvent(eventType: string, attributes?: Object): void;
35
+ /**
36
+ * Measures a task that is recorded as a BrowserPerformance event.
37
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/measure/}
38
+ * @param {string} name The name of the task
39
+ * @param {{start: number, end: number, duration: number, customAttributes: object}} [options] An object used to control the way the measure API operates
40
+ * @returns {{start: number, end: number, duration: number, customAttributes: object}} Measurement details
41
+ */
42
+ measure(name: string, options?: {
43
+ start: number;
44
+ end: number;
45
+ duration: number;
46
+ customAttributes: object;
47
+ }): {
48
+ start: number;
49
+ end: number;
50
+ duration: number;
51
+ customAttributes: object;
52
+ };
35
53
  /**
36
54
  * Adds a user-defined attribute name and value to subsequent events on the page for the registered target. Note -- the persist flag does not work with the register API.
37
55
  * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setcustomattribute/}
@@ -1 +1 @@
1
- {"version":3,"file":"registered-entity.d.ts","sourceRoot":"","sources":["../../../src/interfaces/registered-entity.js"],"names":[],"mappings":"AAMA;;;;GAIG;AAEH;;;;;;GAMG;AACH;IAOE;;;OAGG;IACH,kBAFW,sBAAsB,EAShC;IAjBD,kCAAkC;IAClC,UADW,mBAAmB,CAI7B;IAeD;;;;;OAKG;IACH,oBAHW,MAAM,eACN,MAAM,QAKhB;IAED;;;;;SAKK;IACL,6BAHa,MAAM,eACN,MAAM,QAIlB;IAED;;;;;;OAMG;IACH,yBAJW,MAAM,SACN,MAAM,GAAC,MAAM,GAAC,OAAO,GAAC,IAAI,YAC1B,OAAO,QAKjB;IAED;;;;;OAKG;IACH,mBAHW,KAAK,GAAC,MAAM,qBACZ,MAAM,QAKhB;IAED;;;;OAIG;IACH,iBAFW,MAAM,GAAC,IAAI,QAKrB;IAED;;;;;;;OAOG;IACH,6BAJW,MAAM,GAAC,IAAI,QAOrB;IAED;;;;;MAKE;IACF,aAHW,MAAM,YACN;QAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,GAAC,OAAO,GAAC,OAAO,GAAC,MAAM,GAAC,MAAM,CAAA;KAAC,QAKpF;CACF;0BA7GY,OAAO,mCAAmC,EAAE,WAAW;kCACvD,OAAO,mCAAmC,EAAE,mBAAmB;qCAC/D,OAAO,mCAAmC,EAAE,sBAAsB"}
1
+ {"version":3,"file":"registered-entity.d.ts","sourceRoot":"","sources":["../../../src/interfaces/registered-entity.js"],"names":[],"mappings":"AAMA;;;;GAIG;AAEH;;;;;;GAMG;AACH;IAOE;;;OAGG;IACH,kBAFW,sBAAsB,EAShC;IAjBD,kCAAkC;IAClC,UADW,mBAAmB,CAI7B;IAeD;;;;;OAKG;IACH,oBAHW,MAAM,eACN,MAAM,QAKhB;IAED;;;;;SAKK;IACL,6BAHa,MAAM,eACN,MAAM,QAIlB;IAED;;;;;;OAMG;IACH,cAJW,MAAM,YACN;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,gBAAgB,EAAE,MAAM,CAAA;KAAC,GACtE;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,gBAAgB,EAAE,MAAM,CAAA;KAAC,CAIpF;IAED;;;;;;OAMG;IACH,yBAJW,MAAM,SACN,MAAM,GAAC,MAAM,GAAC,OAAO,GAAC,IAAI,YAC1B,OAAO,QAKjB;IAED;;;;;OAKG;IACH,mBAHW,KAAK,GAAC,MAAM,qBACZ,MAAM,QAKhB;IAED;;;;OAIG;IACH,iBAFW,MAAM,GAAC,IAAI,QAKrB;IAED;;;;;;;OAOG;IACH,6BAJW,MAAM,GAAC,IAAI,QAOrB;IAED;;;;;MAKE;IACF,aAHW,MAAM,YACN;QAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,GAAC,OAAO,GAAC,OAAO,GAAC,MAAM,GAAC,MAAM,CAAA;KAAC,QAKpF;CACF;0BAxHY,OAAO,mCAAmC,EAAE,WAAW;kCACvD,OAAO,mCAAmC,EAAE,mBAAmB;qCAC/D,OAAO,mCAAmC,EAAE,sBAAsB"}
@@ -1,2 +1,5 @@
1
1
  export function setupMeasureAPI(agent: any): void;
2
+ export function measure(name: any, options: any, agentRef: any, target: any, timestamp?: number): {
3
+ customAttributes: any;
4
+ } | undefined;
2
5
  //# sourceMappingURL=measure.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"measure.d.ts","sourceRoot":"","sources":["../../../../src/loaders/api/measure.js"],"names":[],"mappings":"AAWA,kDAyCC"}
1
+ {"version":3,"file":"measure.d.ts","sourceRoot":"","sources":["../../../../src/loaders/api/measure.js"],"names":[],"mappings":"AAWA,kDAEC;AAED;;cAsCC"}
@@ -20,6 +20,15 @@ export type RegisterAPI = {
20
20
  * - Record a custom event for the registered entity.
21
21
  */
22
22
  recordCustomEvent: (eventType: string, attributes?: Object) => void;
23
+ /**
24
+ * {start: number, end: number, duration: number, customAttributes: object}}} measure - Measures a task that is recorded as a BrowserPerformance event.
25
+ */
26
+ "": (eventType: string, options?: {
27
+ start: number;
28
+ end: number;
29
+ duration: number;
30
+ customAttributes: object;
31
+ }) => {};
23
32
  /**
24
33
  * - Add an application.version attribute to all outgoing data for the registered entity.
25
34
  */
@@ -1 +1 @@
1
- {"version":3,"file":"register-api-types.d.ts","sourceRoot":"","sources":["../../../../src/loaders/api/register-api-types.js"],"names":[],"mappings":";;;;;;mBAOc,CAAC,IAAI,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,KAAK,IAAI;;;;SAC3C,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAE,gBAAgB,CAAC,EAAE,MAAM,CAAC;Q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AAI;;;;QAChD,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,gBAAgB,EAAE,MAAM,CAAA;KAAC,KAAK,EAAC;;;;2BAC5G,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI;;;;wBAC9B,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,EAAE,OAAO,CAAC,EAAE,OAAO,KAAK,IAAI;;;;eAClF,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI;;;;cAC9B,mBAAmB;;;;;;QAKnB,MAAM,GAAC,MAAM;;;;UACb,MAAM;;;;;;sBAKN,MAAM;;;;YAEjB;QAA0B,UAAU,EAAzB,MAAM;QACS,EAAE,EAAjB,MAAM;QACS,IAAI,EAAnB,MAAM;KACnB"}
@@ -1 +1 @@
1
- {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../../../src/loaders/api/register.js"],"names":[],"mappings":"AAkBA;;GAEG;AAEH;;;;GAIG;AACH,mDAIC;AAED;;;;;;;;;;GAUG;AACH,2CARW,MAAM,UAGd;IAAwB,UAAU;IACX,EAAE,EAAjB,MAAM;IACS,IAAI,EAAnB,MAAM;CACd,GAAU,WAAW,CAoGvB;0BA3HY,OAAO,sBAAsB,EAAE,WAAW"}
1
+ {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../../../src/loaders/api/register.js"],"names":[],"mappings":"AAmBA;;GAEG;AAEH;;;;GAIG;AACH,mDAIC;AAED;;;;;;;;;;GAUG;AACH,2CARW,MAAM,UAGd;IAAwB,UAAU;IACX,EAAE,EAAjB,MAAM;IACS,IAAI,EAAnB,MAAM;CACd,GAAU,WAAW,CAqGvB;0BA5HY,OAAO,sBAAsB,EAAE,WAAW"}
@@ -164,10 +164,15 @@ export class ApiBase {
164
164
  * Measures a task that is recorded as a BrowserPerformance event.
165
165
  * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/measure/}
166
166
  * @param {string} name The name of the task
167
- * @param {object?} options An object used to control the way the measure API operates
167
+ * @param {{start: number, end: number, duration: number, customAttributes: object}} [options] An object used to control the way the measure API operates
168
168
  * @returns {{start: number, end: number, duration: number, customAttributes: object}} Measurement details
169
169
  */
170
- measure(name: string, options: object | null): {
170
+ measure(name: string, options?: {
171
+ start: number;
172
+ end: number;
173
+ duration: number;
174
+ customAttributes: object;
175
+ }): {
171
176
  start: number;
172
177
  end: number;
173
178
  duration: number;
@@ -1 +1 @@
1
- {"version":3,"file":"api-base.d.ts","sourceRoot":"","sources":["../../../src/loaders/api-base.js"],"names":[],"mappings":"AAOA;;GAEG;AACH;IAQE;;;;;OAKG;IACH,oBAHW,MAAM,eACN,MAAM,OAIhB;IAED;;;;;;;;OAQG;IACH,iBAHW,OAAO,0BAA0B,EAAE,sBAAsB,GAC1D,OAAO,0BAA0B,EAAE,WAAW,CAIvD;IAED;;;;;OAKG;IACH,6BAHW,MAAM,eACN,MAAM,OAIhB;IAED;;;;;OAKG;IACH,sBAHW,MAAM,SACN,MAAM,OAIhB;IAED;;;;;;OAMG;IACH,yBAJW,MAAM,SACN,MAAM,GAAC,MAAM,GAAC,OAAO,GAAC,IAAI,YAC1B,OAAO,OAIjB;IAED;;;;;OAKG;IACH,mBAHW,KAAK,GAAC,MAAM,qBACZ,MAAM,OAIhB;IAED;;;;OAIG;IACH,iBAFW,MAAM,GAAC,IAAI,OAIrB;IAED;;;;;;;OAOG;IACH,6BAJW,MAAM,GAAC,IAAI,OAMrB;IAED;;;;OAIG;IACH,0BAFW,CAAC,KAAK,EAAE,KAAK,GAAC,MAAM,KAAK,OAAO,GAAG;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,OAI9D;IAED;;;;;OAKG;IACH,iBAHW,MAAM,MACN,MAAM,OAIhB;IAED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AAuB,UAAU;KACjC,GAAU,mBAAmB,CAM/B;IAED;;;;;;MAME;IACF,mBAJW,MAAM,gBACN,MAAM,YACN;QAAC,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAAC,KAAK,CAAC,EAAE,OAAO,GAAC,OAAO,GAAC,OAAO,GAAC,MAAM,GAAC,MAAM,CAAA;KAAC,OAIpF;IAED;;;;;;OAMG;IACH,cAJW,MAAM,YACN;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,gBAAgB,EAAE,MAAM,CAAA;KAAC,GACtE;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAC;QAAC,gBAAgB,EAAE,MAAM,CAAA;KAAC,CAIpF;IAED;;;;;OAKG;IACH,gBAFW,OAAO,OAAC,OAIlB;;CACF;kCArOY,OAAO,yBAAyB,EAAE,mBAAmB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@newrelic/browser-agent",
3
- "version": "1.302.0-rc.8",
3
+ "version": "1.302.0-rc.9",
4
4
  "private": false,
5
5
  "author": "New Relic Browser Agent Team <browser-agent@newrelic.com>",
6
6
  "description": "New Relic Browser Agent",
@@ -227,7 +227,7 @@ export class Aggregate extends AggregateBase {
227
227
  }, this.featureName, this.ee)
228
228
  }
229
229
 
230
- registerHandler('api-measure', (args, n) => {
230
+ registerHandler('api-measure', (args, n, target) => {
231
231
  const { start, duration, customAttributes } = args
232
232
 
233
233
  const event = {
@@ -239,7 +239,7 @@ export class Aggregate extends AggregateBase {
239
239
  entryType: 'measure'
240
240
  }
241
241
 
242
- this.addEvent(event)
242
+ this.addEvent(event, target)
243
243
  }, this.featureName, this.ee)
244
244
 
245
245
  this.drain()
@@ -58,6 +58,17 @@ export class RegisteredEntity {
58
58
  warn(35, 'recordCustomEvent')
59
59
  }
60
60
 
61
+ /**
62
+ * Measures a task that is recorded as a BrowserPerformance event.
63
+ * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/measure/}
64
+ * @param {string} name The name of the task
65
+ * @param {{start: number, end: number, duration: number, customAttributes: object}} [options] An object used to control the way the measure API operates
66
+ * @returns {{start: number, end: number, duration: number, customAttributes: object}} Measurement details
67
+ */
68
+ measure (name, options) {
69
+ warn(35, 'measure')
70
+ }
71
+
61
72
  /**
62
73
  * Adds a user-defined attribute name and value to subsequent events on the page for the registered target. Note -- the persist flag does not work with the register API.
63
74
  * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/setcustomattribute/}
@@ -10,44 +10,45 @@ import { prefix, MEASURE } from './constants'
10
10
  import { setupAPI } from './sharedHandlers'
11
11
 
12
12
  export function setupMeasureAPI (agent) {
13
- setupAPI(MEASURE, function (name, options) {
14
- const n = now()
15
- const { start, end, customAttributes } = options || {}
16
- const returnObj = { customAttributes: customAttributes || {} }
13
+ setupAPI(MEASURE, (name, options) => measure(name, options, agent), agent)
14
+ }
15
+
16
+ export function measure (name, options, agentRef, target, timestamp = now()) {
17
+ const { start, end, customAttributes } = options || {}
18
+ const returnObj = { customAttributes: customAttributes || {} }
17
19
 
18
- if (typeof returnObj.customAttributes !== 'object' || typeof name !== 'string' || name.length === 0) {
19
- warn(57)
20
- return
21
- }
20
+ if (typeof returnObj.customAttributes !== 'object' || typeof name !== 'string' || name.length === 0) {
21
+ warn(57)
22
+ return
23
+ }
22
24
 
23
- /**
25
+ /**
24
26
  * getValueFromTiming - Helper function to extract a numeric value from a supplied option.
25
27
  * @param {Number|PerformanceMark} [timing] The timing value
26
28
  * @param {Number} [d] The default value to return if timing is invalid
27
29
  * @returns {Number} The timing value or the default value
28
30
  */
29
- const getValueFromTiming = (timing, d) => {
30
- if (timing == null) return d
31
- if (typeof timing === 'number') return timing
32
- if (timing instanceof PerformanceMark) return timing.startTime
33
- return Number.NaN
34
- }
35
-
36
- returnObj.start = getValueFromTiming(start, 0)
37
- returnObj.end = getValueFromTiming(end, n)
38
- if (Number.isNaN(returnObj.start) || Number.isNaN(returnObj.end)) {
39
- warn(57)
40
- return
41
- }
42
-
43
- returnObj.duration = returnObj.end - returnObj.start
44
- if (returnObj.duration < 0) {
45
- warn(58)
46
- return
47
- }
48
-
49
- handle(prefix + MEASURE, [returnObj, name], undefined, FEATURE_NAMES.genericEvents, agent.ee)
50
-
51
- return returnObj
52
- }, agent)
31
+ const getValueFromTiming = (timing, d) => {
32
+ if (timing == null) return d
33
+ if (typeof timing === 'number') return timing
34
+ if (timing instanceof PerformanceMark) return timing.startTime
35
+ return Number.NaN
36
+ }
37
+
38
+ returnObj.start = getValueFromTiming(start, 0)
39
+ returnObj.end = getValueFromTiming(end, timestamp)
40
+ if (Number.isNaN(returnObj.start) || Number.isNaN(returnObj.end)) {
41
+ warn(57)
42
+ return
43
+ }
44
+
45
+ returnObj.duration = returnObj.end - returnObj.start
46
+ if (returnObj.duration < 0) {
47
+ warn(58)
48
+ return
49
+ }
50
+
51
+ handle(prefix + MEASURE, [returnObj, name, target], undefined, FEATURE_NAMES.genericEvents, agentRef.ee)
52
+
53
+ return returnObj
53
54
  }
@@ -9,6 +9,7 @@
9
9
  * @property {(message: string, options?: { customAttributes?: object, level?: 'ERROR' | 'TRACE' | 'DEBUG' | 'INFO' | 'WARN'}) => void} log - Capture a log for the registered entity.
10
10
  * @property {(error: Error | string, customAttributes?: object) => void} noticeError - Notice an error for the registered entity.
11
11
  * @property {(eventType: string, attributes?: Object) => void} recordCustomEvent - Record a custom event for the registered entity.
12
+ * @property {(eventType: string, options?: {start: number, end: number, duration: number, customAttributes: object}) => {{start: number, end: number, duration: number, customAttributes: object}}} measure - Measures a task that is recorded as a BrowserPerformance event.
12
13
  * @property {(value: string | null) => void} setApplicationVersion - Add an application.version attribute to all outgoing data for the registered entity.
13
14
  * @property {(name: string, value: string | number | boolean | null, persist?: boolean) => void} setCustomAttribute - Add a custom attribute to outgoing data for the registered entity.
14
15
  * @property {(value: string | null) => void} setUserId - Add an enduser.id attribute to all outgoing API data for the registered entity.
@@ -14,6 +14,7 @@ import { log } from './log'
14
14
  import { addPageAction } from './addPageAction'
15
15
  import { noticeError } from './noticeError'
16
16
  import { single } from '../../common/util/invoke'
17
+ import { measure } from './measure'
17
18
  import { recordCustomEvent } from './recordCustomEvent'
18
19
 
19
20
  /**
@@ -79,6 +80,7 @@ export function buildRegisterApi (agentRef, target) {
79
80
  const api = {
80
81
  addPageAction: (name, attributes = {}) => report(addPageAction, [name, { ...attrs, ...attributes }, agentRef], target),
81
82
  log: (message, options = {}) => report(log, [message, { ...options, customAttributes: { ...attrs, ...(options.customAttributes || {}) } }, agentRef], target),
83
+ measure: (name, options = {}) => report(measure, [name, { ...options, customAttributes: { ...attrs, ...(options.customAttributes || {}) } }, agentRef], target),
82
84
  noticeError: (error, attributes = {}) => report(noticeError, [error, { ...attrs, ...attributes }, agentRef], target),
83
85
  recordCustomEvent: (eventType, attributes = {}) => report(recordCustomEvent, [eventType, { ...attrs, ...attributes }, agentRef], target),
84
86
  setApplicationVersion: (value) => setLocalValue('application.version', value),
@@ -219,7 +219,7 @@ export class ApiBase {
219
219
  * Measures a task that is recorded as a BrowserPerformance event.
220
220
  * {@link https://docs.newrelic.com/docs/browser/new-relic-browser/browser-apis/measure/}
221
221
  * @param {string} name The name of the task
222
- * @param {object?} options An object used to control the way the measure API operates
222
+ * @param {{start: number, end: number, duration: number, customAttributes: object}} [options] An object used to control the way the measure API operates
223
223
  * @returns {{start: number, end: number, duration: number, customAttributes: object}} Measurement details
224
224
  */
225
225
  measure (name, options) {