@crimson-education/browser-logger 5.0.1 → 5.0.3

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 (66) hide show
  1. package/README.md +72 -94
  2. package/lib/index.d.ts +1 -1
  3. package/lib/index.d.ts.map +1 -1
  4. package/lib/index.js +23 -46
  5. package/lib/index.js.map +1 -1
  6. package/lib/logger/consoleTransport.d.ts +1 -1
  7. package/lib/logger/consoleTransport.d.ts.map +1 -1
  8. package/lib/logger/consoleTransport.js +16 -22
  9. package/lib/logger/consoleTransport.js.map +1 -1
  10. package/lib/logger/datadogTransport.d.ts +1 -1
  11. package/lib/logger/datadogTransport.d.ts.map +1 -1
  12. package/lib/logger/datadogTransport.js +4 -8
  13. package/lib/logger/datadogTransport.js.map +1 -1
  14. package/lib/logger/index.js +29 -49
  15. package/lib/logger/index.js.map +1 -1
  16. package/lib/logger/index.test.js +16 -18
  17. package/lib/logger/index.test.js.map +1 -1
  18. package/lib/logger/utils.js +4 -9
  19. package/lib/logger/utils.js.map +1 -1
  20. package/lib/reporters/datadogReporter.d.ts +13 -1
  21. package/lib/reporters/datadogReporter.d.ts.map +1 -1
  22. package/lib/reporters/datadogReporter.js +122 -49
  23. package/lib/reporters/datadogReporter.js.map +1 -1
  24. package/lib/reporters/gtmReporter.d.ts +1 -1
  25. package/lib/reporters/gtmReporter.d.ts.map +1 -1
  26. package/lib/reporters/gtmReporter.js +1 -5
  27. package/lib/reporters/gtmReporter.js.map +1 -1
  28. package/lib/reporters/index.js +46 -71
  29. package/lib/reporters/index.js.map +1 -1
  30. package/lib/reporters/logReporter.js +24 -34
  31. package/lib/reporters/logReporter.js.map +1 -1
  32. package/lib/reporters/posthogReporter.d.ts +1 -1
  33. package/lib/reporters/posthogReporter.d.ts.map +1 -1
  34. package/lib/reporters/posthogReporter.js +46 -55
  35. package/lib/reporters/posthogReporter.js.map +1 -1
  36. package/lib/reporters/posthogReporter.test.js +21 -23
  37. package/lib/reporters/posthogReporter.test.js.map +1 -1
  38. package/lib/types/index.js +2 -18
  39. package/lib/types/index.js.map +1 -1
  40. package/lib/types/logger.d.ts +3 -3
  41. package/lib/types/logger.d.ts.map +1 -1
  42. package/lib/types/logger.js +2 -5
  43. package/lib/types/logger.js.map +1 -1
  44. package/lib/types/reporter.d.ts +6 -12
  45. package/lib/types/reporter.d.ts.map +1 -1
  46. package/lib/types/reporter.js +1 -2
  47. package/lib/utils.js +1 -5
  48. package/lib/utils.js.map +1 -1
  49. package/lib/utils.test.js +2 -4
  50. package/lib/utils.test.js.map +1 -1
  51. package/package.json +16 -16
  52. package/src/index.ts +0 -6
  53. package/src/reporters/datadogReporter.ts +133 -22
  54. package/src/reporters/posthogReporter.test.ts +6 -1
  55. package/src/reporters/posthogReporter.ts +6 -1
  56. package/src/types/reporter.ts +0 -7
  57. package/lib/reporters/amplifyReporter.d.ts +0 -86
  58. package/lib/reporters/amplifyReporter.d.ts.map +0 -1
  59. package/lib/reporters/amplifyReporter.js +0 -225
  60. package/lib/reporters/amplifyReporter.js.map +0 -1
  61. package/lib/reporters/amplifyReporter.test.d.ts +0 -2
  62. package/lib/reporters/amplifyReporter.test.d.ts.map +0 -1
  63. package/lib/reporters/amplifyReporter.test.js +0 -51
  64. package/lib/reporters/amplifyReporter.test.js.map +0 -1
  65. package/src/reporters/amplifyReporter.test.ts +0 -61
  66. package/src/reporters/amplifyReporter.ts +0 -344
@@ -1,52 +1,33 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
- Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.logger = exports.createLogger = exports.setLogLevel = exports.globalLogLevel = exports.logTransports = exports.globalMetadata = void 0;
18
1
  /* eslint-disable prefer-rest-params */
19
- const types_1 = require("../types");
20
- const utils_1 = require("../utils");
21
- const consoleTransport_1 = require("./consoleTransport");
22
- const utils_2 = require("./utils");
23
- __exportStar(require("./consoleTransport"), exports);
24
- __exportStar(require("./datadogTransport"), exports);
25
- exports.globalMetadata = {};
26
- exports.logTransports = [(0, consoleTransport_1.consoleTransport)()];
2
+ import { LogLevel } from '../types';
3
+ import { filterReporterMetadata } from '../utils';
4
+ import { consoleTransport } from './consoleTransport';
5
+ import { getLogMessage, isAboveLevel } from './utils';
6
+ export * from './consoleTransport';
7
+ export * from './datadogTransport';
8
+ export const globalMetadata = {};
9
+ export const logTransports = [consoleTransport()];
10
+ export let globalLogLevel;
27
11
  /**
28
12
  * Sets the global log level.
29
13
  */
30
- function setLogLevel(level) {
31
- exports.globalLogLevel = level !== null && level !== void 0 ? level : undefined;
14
+ export function setLogLevel(level) {
15
+ globalLogLevel = level ?? undefined;
32
16
  }
33
- exports.setLogLevel = setLogLevel;
34
17
  /**
35
18
  * Creates a Logger Instance.
36
19
  */
37
- function createLogger(options = {}) {
38
- var _a;
39
- const rootMetadata = (_a = options.metadata) !== null && _a !== void 0 ? _a : {};
20
+ export function createLogger(options = {}) {
21
+ const rootMetadata = options.metadata ?? {};
40
22
  const logger = {
41
23
  // impl loosely based on Winston Logger's dynamic log function
42
24
  // https://github.com/winstonjs/winston/blob/master/lib/winston/logger.js
43
25
  log() {
44
- var _a, _b;
45
26
  let logInfo;
46
27
  // Optimize for the hotpath of logging JSON literals
47
28
  if (arguments.length === 1) {
48
29
  logInfo = {
49
- level: types_1.LogLevel.Info,
30
+ level: LogLevel.Info,
50
31
  ...arguments[0],
51
32
  };
52
33
  }
@@ -56,7 +37,7 @@ function createLogger(options = {}) {
56
37
  if (message && typeof message === 'object') {
57
38
  logInfo = {
58
39
  ...message,
59
- level: (_a = message.level) !== null && _a !== void 0 ? _a : level,
40
+ level: message.level ?? level,
60
41
  };
61
42
  }
62
43
  else {
@@ -77,7 +58,7 @@ function createLogger(options = {}) {
77
58
  message,
78
59
  };
79
60
  if (meta.message) {
80
- logInfo.message = `${(0, utils_2.getLogMessage)(logInfo.message)} ${(0, utils_2.getLogMessage)(meta.message)}`;
61
+ logInfo.message = `${getLogMessage(logInfo.message)} ${getLogMessage(meta.message)}`;
81
62
  }
82
63
  if (meta.stack) {
83
64
  logInfo.stack = meta.stack;
@@ -92,27 +73,27 @@ function createLogger(options = {}) {
92
73
  }
93
74
  }
94
75
  // Check if we should log this message
95
- const minLevel = exports.globalLogLevel !== null && exports.globalLogLevel !== void 0 ? exports.globalLogLevel : options.logLevel;
96
- if (minLevel && !(0, utils_2.isAboveLevel)(logInfo.level, minLevel)) {
76
+ const minLevel = globalLogLevel ?? options.logLevel;
77
+ if (minLevel && !isAboveLevel(logInfo.level, minLevel)) {
97
78
  return logger;
98
79
  }
99
80
  // Add timestamp and root metadata.
100
81
  // Ensure there is a message property.
101
82
  logInfo = {
102
- ...exports.globalMetadata,
83
+ ...globalMetadata,
103
84
  ...rootMetadata,
104
85
  timestamp: new Date().toISOString(),
105
86
  ...logInfo,
106
- message: (_b = logInfo.message) !== null && _b !== void 0 ? _b : '',
87
+ message: logInfo.message ?? '',
107
88
  };
108
- for (const transport of exports.logTransports) {
89
+ for (const transport of logTransports) {
109
90
  if (transport.logLevel) {
110
- if (!(0, utils_2.isAboveLevel)(logInfo.level, transport.logLevel)) {
91
+ if (!isAboveLevel(logInfo.level, transport.logLevel)) {
111
92
  continue;
112
93
  }
113
94
  }
114
95
  transport.log({
115
- ...(0, utils_1.filterReporterMetadata)(logInfo, transport),
96
+ ...filterReporterMetadata(logInfo, transport),
116
97
  // These would break the transport if excluded.
117
98
  level: logInfo.level,
118
99
  message: logInfo.message,
@@ -130,19 +111,18 @@ function createLogger(options = {}) {
130
111
  logger: this,
131
112
  done: ({ message, level, metadata } = {}) => {
132
113
  const duration = new Date().getTime() - start.getTime();
133
- logger.log(level !== null && level !== void 0 ? level : types_1.LogLevel.Info, message !== null && message !== void 0 ? message : 'Timer Completed', { duration, ...(metadata !== null && metadata !== void 0 ? metadata : {}) });
114
+ logger.log(level ?? LogLevel.Info, message ?? 'Timer Completed', { duration, ...(metadata ?? {}) });
134
115
  return true;
135
116
  },
136
117
  };
137
118
  },
138
119
  // Forward the log levels into the log function, essentially shortcuts.
139
- debug: (...args) => logger.log(types_1.LogLevel.Debug, ...args),
140
- info: (...args) => logger.log(types_1.LogLevel.Info, ...args),
141
- warn: (...args) => logger.log(types_1.LogLevel.Warn, ...args),
142
- error: (...args) => logger.log(types_1.LogLevel.Error, ...args),
120
+ debug: (...args) => logger.log(LogLevel.Debug, ...args),
121
+ info: (...args) => logger.log(LogLevel.Info, ...args),
122
+ warn: (...args) => logger.log(LogLevel.Warn, ...args),
123
+ error: (...args) => logger.log(LogLevel.Error, ...args),
143
124
  };
144
125
  return logger;
145
126
  }
146
- exports.createLogger = createLogger;
147
- exports.logger = createLogger();
127
+ export const logger = createLogger();
148
128
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/logger/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAAA,uCAAuC;AACvC,oCAA8G;AAC9G,oCAAkD;AAClD,yDAAsD;AACtD,mCAAsD;AAEtD,qDAAmC;AACnC,qDAAmC;AAEtB,QAAA,cAAc,GAAa,EAAE,CAAC;AAE9B,QAAA,aAAa,GAAoB,CAAC,IAAA,mCAAgB,GAAE,CAAC,CAAC;AAGnE;;GAEG;AACH,SAAgB,WAAW,CAAC,KAAsB;IAChD,sBAAc,GAAG,KAAK,aAAL,KAAK,cAAL,KAAK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,IAAI,CAAC;gBACd,CAAC;aACF,CAAC;QACJ,CAAC;QACD,uEAAuE;QACvE,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC;QACvD,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC;QACrD,IAAI,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC;QACrD,KAAK,EAAE,CAAC,GAAG,IAAI,EAAE,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,GAAG,IAAI,CAAC;KACxD,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,CAAC,MAAM,MAAM,GAAG,YAAY,EAAE,CAAC"}
@@ -1,33 +1,31 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const _1 = require(".");
4
- const __1 = require("..");
5
- const reporters_1 = require("../reporters");
6
- const types_1 = require("../types");
1
+ import { createLogger, setLogLevel as setGlobalLogLevel, logTransports, consoleTransport } from '.';
2
+ import { init } from '..';
3
+ import { addMetadata, setUser } from '../reporters';
4
+ import { LogLevel } from '../types';
7
5
  // This isn't actually asserting anything.
8
6
  // But it ensures that the logs look correct, and no errors get thrown.
9
7
  describe('logger', () => {
10
- const logger = (0, _1.createLogger)({
8
+ const logger = createLogger({
11
9
  metadata: {
12
10
  service: 'test',
13
11
  },
14
12
  });
15
13
  // Manually set the log transports.
16
- _1.logTransports.length = 0;
17
- const transport = (0, _1.consoleTransport)({
14
+ logTransports.length = 0;
15
+ const transport = consoleTransport({
18
16
  // So we can see everything.
19
17
  ignoreMetadataPatterns: [],
20
18
  });
21
- _1.logTransports.push(transport);
19
+ logTransports.push(transport);
22
20
  it('should log', async () => {
23
21
  logger.log({
24
22
  level: 'info',
25
23
  message: 'data',
26
24
  });
27
25
  logger.log({ data: 'obj' });
28
- logger.log(types_1.LogLevel.Debug, 'level, message', { data: 'obj' });
29
- logger.log(types_1.LogLevel.Debug, 'level, message, metadata', { data: 'obj' });
30
- (0, __1.init)({
26
+ logger.log(LogLevel.Debug, 'level, message', { data: 'obj' });
27
+ logger.log(LogLevel.Debug, 'level, message, metadata', { data: 'obj' });
28
+ init({
31
29
  service: 'test-service',
32
30
  environment: 'test',
33
31
  version: 'no-version',
@@ -41,17 +39,17 @@ describe('logger', () => {
41
39
  const timer = logger.startTimer();
42
40
  await new Promise((resolve) => setTimeout(resolve, 1000));
43
41
  timer.done({ message: 'timer done', metadata: { id: 1 } });
44
- (0, _1.setLogLevel)(types_1.LogLevel.Info);
45
- (0, reporters_1.addMetadata)({ global: 'metadata' });
42
+ setGlobalLogLevel(LogLevel.Info);
43
+ addMetadata({ global: 'metadata' });
46
44
  logger.debug('You should not see this');
47
45
  logger.info('You should see this with { global: "metadata" }');
48
- (0, _1.setLogLevel)(null);
49
- (0, reporters_1.setUser)({
46
+ setGlobalLogLevel(null);
47
+ setUser({
50
48
  id: '123',
51
49
  email: 'test@example.com',
52
50
  });
53
51
  logger.debug('debug call, user metadata');
54
- transport.logLevel = types_1.LogLevel.Info;
52
+ transport.logLevel = LogLevel.Info;
55
53
  logger.debug('You should not see this');
56
54
  logger.info('You should see this');
57
55
  transport.logLevel = undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"index.test.js","sourceRoot":"","sources":["../../src/logger/index.test.ts"],"names":[],"mappings":";;AAAA,wBAAoG;AACpG,0BAA0B;AAC1B,4CAAoD;AACpD,oCAAoC;AAEpC,0CAA0C;AAC1C,uEAAuE;AACvE,QAAQ,CAAC,QAAQ,EAAE,GAAG,EAAE;IACtB,MAAM,MAAM,GAAG,IAAA,eAAY,EAAC;QAC1B,QAAQ,E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AC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;QAC1D,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,YAAY,EAAE,QAAQ,EAAE,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC;QAE3D,iBAAiB,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;QACjC,WAAW,CAAC,EAAE,MAAM,EAAE,UAAU,EAAE,CAAC,CAAC;QAEpC,MAAM,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;QACxC,MAAM,CAAC,IAAI,CAAC,iDAAiD,CAAC,CAAC;QAE/D,iBAAiB,CAAC,IAAI,CAAC,CAAC;QACxB,OAAO,CAAC;YACN,EAAE,EAAE,KAAK;YACT,KAAK,EAAE,kBAAkB;SAC1B,CAAC,CAAC;QAEH,MAAM,CAAC,KAAK,CAAC,2BAA2B,CAAC,CAAC;QAE1C,SAAS,CAAC,QAAQ,GAAG,QAAQ,CAAC,IAAI,CAAC;QACnC,MAAM,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;QACxC,MAAM,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC;QACnC,SAAS,CAAC,QAAQ,GAAG,SAAS,CAAC;IACjC,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -1,24 +1,20 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getLogMessage = exports.isAboveLevel = void 0;
4
- const types_1 = require("../types");
1
+ import { LogLevel } from '../types';
5
2
  /**
6
3
  * Checks if a log level is above the global log level.
7
4
  * @param level The log level to check
8
5
  * @param checkLevel THe log level to check against
9
6
  * @returns Is above the checkLevel?
10
7
  */
11
- function isAboveLevel(level, checkLevel) {
12
- const levels = [types_1.LogLevel.Debug, types_1.LogLevel.Info, types_1.LogLevel.Warn, types_1.LogLevel.Error];
8
+ export function isAboveLevel(level, checkLevel) {
9
+ const levels = [LogLevel.Debug, LogLevel.Info, LogLevel.Warn, LogLevel.Error];
13
10
  return levels.indexOf(level) >= levels.indexOf(checkLevel);
14
11
  }
15
- exports.isAboveLevel = isAboveLevel;
16
12
  /**
17
13
  * Ensures a message output is a string.
18
14
  * @param message The message to assert is/convert to a string
19
15
  * @returns The message as a string
20
16
  */
21
- function getLogMessage(message) {
17
+ export function getLogMessage(message) {
22
18
  if (typeof message === 'string') {
23
19
  return message;
24
20
  }
@@ -28,5 +24,4 @@ function getLogMessage(message) {
28
24
  }
29
25
  return String(message);
30
26
  }
31
- exports.getLogMessage = getLogMessage;
32
27
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/logger/utils.ts"],"names":[],"mappings":";;;AAAA,oCAAoC;AAEpC;;;;;GAKG;AACH,SAAgB,YAAY,CAAC,KAAe,EAAE,UAAoB;IAChE,MAAM,MAAM,GAAG,CAAC,gBAAQ,CAAC,KAAK,EAAE,gBAAQ,CAAC,IAAI,EAAE,gBAAQ,CAAC,IAAI,EAAE,gBAAQ,CAAC,KAAK,CAAC,CAAC;IAC9E,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AAC7D,CAAC;AAHD,oCAGC;AAED;;;;GAIG;AACH,SAAgB,aAAa,CAAC,OAAY;IACxC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QAC/B,OAAO,OAAO,CAAC;KAChB;IACD,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,EAAE;QACnD,MAAM,IAAI,GAAG,EAAE,GAAG,OAAO,EAAE,CAAC;QAC5B,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;KAC7B;IACD,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC;AACzB,CAAC;AATD,sCASC"}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/logger/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,UAAU,CAAC;AAEpC;;;;;GAKG;AACH,MAAM,UAAU,YAAY,CAAC,KAAe,EAAE,UAAoB;IAChE,MAAM,MAAM,GAAG,CAAC,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC9E,OAAO,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;AAC7D,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,aAAa,CAAC,OAAY;IACxC,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE;QAC/B,OAAO,OAAO,CAAC;KAChB;IACD,IAAI,OAAO,OAAO,KAAK,QAAQ,IAAI,OAAO,KAAK,IAAI,EAAE;QACnD,MAAM,IAAI,GAAG,EAAE,GAAG,OAAO,EAAE,CAAC;QAC5B,OAAO,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;KAC7B;IACD,OAAO,MAAM,CAAC,OAAO,CAAC,CAAC;AACzB,CAAC"}
@@ -23,11 +23,14 @@ export interface DatadogReporterConfig extends ReporterConfigBase {
23
23
  * @deprecated Prefer using the dedicated `logSampleRate`, `rumSampleRate`, and `replaySampleRate` options.
24
24
  */
25
25
  sampleRate?: number;
26
+ sessionSampleRate?: number;
27
+ sessionReplaySampleRate?: number;
26
28
  /**
27
29
  * Sampling rate for browser log collection. Defaults to 100, meaning every log message is sent to Datadog.
28
30
  */
29
31
  logSampleRate?: number;
30
32
  /**
33
+ * @deprecated Prefer using `sessionSampleRate`.
31
34
  * Sampling rate for RUM session collection. Defaults to 100, meaning every browser session is tracked.
32
35
  *
33
36
  * RUM can be used to track things like core web vitals.
@@ -36,6 +39,7 @@ export interface DatadogReporterConfig extends ReporterConfigBase {
36
39
  */
37
40
  rumSampleRate?: number;
38
41
  /**
42
+ * @deprecated Prefer using `sessionReplaySampleRate`.
39
43
  * Applied after the RUM sample rate, and controls the percentage of sessions tracked as Browser RUM & Session Replay.
40
44
  * It defaults to 100, so every session is tracked as Browser RUM & Session Replay by default.
41
45
  *
@@ -47,10 +51,17 @@ export interface DatadogReporterConfig extends ReporterConfigBase {
47
51
  */
48
52
  useSecureSessionCookie?: boolean;
49
53
  /**
54
+ * @deprecated Prefer using `usePartitionedCrossSiteSessionCookie`.
50
55
  * Use a secure cross-site session cookie.
51
56
  * This allows the RUM Browser SDK to run when the site is loaded from another one (iframe). Implies `useSecureSessionCookie`
52
57
  */
53
58
  useCrossSiteSessionCookie?: boolean;
59
+ /**
60
+ * Use a partitioned secure cross-site session cookie. This allows the RUM Browser SDK to run when the site is loaded from another one (iframe). Implies `useSecureSessionCookie`.
61
+ * Important: If you are using the RUM and Logs Browser SDKs, this option must be configured with identical values
62
+ * @default false
63
+ */
64
+ usePartitionedCrossSiteSessionCookie?: boolean;
54
65
  /**
55
66
  * Preserve the session across subdomains for the same site.
56
67
  */
@@ -100,7 +111,8 @@ export interface DatadogReporterConfig extends ReporterConfigBase {
100
111
  /**
101
112
  * A list of request origins used to inject tracing headers, to be able to connect RUM and backend tracing.
102
113
  */
103
- allowedTracingOrigins?: (string | RegExp)[];
114
+ allowedTrackingOrigins?: (string | RegExp)[];
115
+ allowedTracingUrls?: (string | RegExp)[];
104
116
  /**
105
117
  * Enables action tracking for user interactions. This enables the Heatmap tab within Datadog
106
118
  */
@@ -1 +1 @@
1
- {"version":3,"file":"datadogReporter.d.ts","sourceRoot":"","sources":["../../src/reporters/datadogReporter.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EAMT,WAAW,EACX,kBAAkB,EAEnB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAA4B,qBAAqB,EAAE,MAAM,uBAAuB,CAAC;AACxF,OAAO,EAAc,mBAAmB,EAAE,oBAAoB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ACH,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAE1B;;OAEG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;IAEjC;;;;OAIG;IACH,yBAAyB,CAAC,EAAE,OAAO,CAAC;IAEpC;;;;OAIG;IACH,oCAAoC,CAAC,EAAE,OAAO,CAAC;IAE/C;;OAEG;IACH,4BAA4B,CAAC,EAAE,OAAO,CAAC;IAEvC;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;OAEG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B;;;OAGG;IACH,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;;OAGG;IACH,mBAAmB,CAAC,EAAE,MAAM,CAAC;IAC7B;;OAEG;IACH,UAAU,CAAC,EAAE,oBAAoB,CAAC,YAAY,CAAC,CAAC;IAEhD;;;OAGG;IACH,YAAY,CAAC,EAAE,OAAO,GAAG,yBAAyB,CAAC;IACnD;;OAEG;IACH,cAAc,CAAC,EAAE,qBAAqB,CAAC,YAAY,CAAC,CAAC;IAErD;;;;OAIG;IACH,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAC1C;;OAEG;IACH,sBAAsB,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IAC7C,kBAAkB,CAAC,EAAE,CAAC,MAAM,GAAG,MAAM,CAAC,EAAE,CAAC;IACzC;;OAEG;IACH,qBAAqB,CAAC,EAAE,OAAO,CAAC;IAEhC;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,WAAW,EAAE,CAAC;CACtC;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,WAAW,EAAE,MAAM,EAAE,qBAAqB,GAAG,SAAS,CAuI3F"}
@@ -1,66 +1,141 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.datadogReporter = void 0;
4
- const browser_logs_1 = require("@datadog/browser-logs");
5
- const browser_rum_1 = require("@datadog/browser-rum");
6
- const logger_1 = require("../logger");
7
- const datadogTransport_1 = require("../logger/datadogTransport");
8
- function datadogReporter(info, config) {
9
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t;
1
+ import { datadogLogs, HandlerType } from '@datadog/browser-logs';
2
+ import { datadogRum } from '@datadog/browser-rum';
3
+ import { logTransports } from '../logger';
4
+ import { datadogTransport } from '../logger/datadogTransport';
5
+ // User frustration detection for Datadog Gen2
6
+ class DatadogFrustrationDetector {
7
+ config;
8
+ frustrationEvents = [];
9
+ FRUSTRATION_THRESHOLD = 3; // Number of events to trigger frustration
10
+ FRUSTRATION_WINDOW = 5000; // Time window in ms
11
+ constructor(config) {
12
+ this.config = config;
13
+ if (config.trackFrustrations) {
14
+ this.setupFrustrationDetection();
15
+ }
16
+ }
17
+ setupFrustrationDetection() {
18
+ // Track rapid clicks (potential frustration)
19
+ let clickCount = 0;
20
+ let lastClickTime = 0;
21
+ document.addEventListener('click', () => {
22
+ const now = Date.now();
23
+ if (now - lastClickTime < 1000) {
24
+ // Rapid clicks within 1 second
25
+ clickCount++;
26
+ if (clickCount >= 3) {
27
+ this.recordFrustrationEvent('rapid_clicks');
28
+ clickCount = 0;
29
+ }
30
+ }
31
+ else {
32
+ clickCount = 1;
33
+ }
34
+ lastClickTime = now;
35
+ });
36
+ // Track form errors (potential frustration)
37
+ document.addEventListener('invalid', () => {
38
+ this.recordFrustrationEvent('form_validation_error');
39
+ });
40
+ // Track 404 errors (potential frustration)
41
+ window.addEventListener('error', (event) => {
42
+ if (event.message.includes('404') || event.message.includes('Not Found')) {
43
+ this.recordFrustrationEvent('page_not_found');
44
+ }
45
+ });
46
+ // Track network errors (potential frustration)
47
+ window.addEventListener('unhandledrejection', (event) => {
48
+ if (event.reason && typeof event.reason === 'object' && 'status' in event.reason) {
49
+ const status = event.reason.status;
50
+ if (status >= 400) {
51
+ this.recordFrustrationEvent('network_error');
52
+ }
53
+ }
54
+ });
55
+ }
56
+ recordFrustrationEvent(type) {
57
+ const now = Date.now();
58
+ this.frustrationEvents.push({ type, timestamp: now });
59
+ // Clean old events outside the window
60
+ this.frustrationEvents = this.frustrationEvents.filter((event) => now - event.timestamp < this.FRUSTRATION_WINDOW);
61
+ // Check if we have enough events to trigger frustration
62
+ if (this.frustrationEvents.length >= this.FRUSTRATION_THRESHOLD) {
63
+ this.triggerFrustrationDetection();
64
+ }
65
+ }
66
+ triggerFrustrationDetection() {
67
+ const frustrationData = {
68
+ frustrationType: 'user_frustration_detected',
69
+ frustrationEvents: this.frustrationEvents.map((e) => e.type),
70
+ frustrationCount: this.frustrationEvents.length,
71
+ pageUrl: window.location.href,
72
+ timestamp: new Date().toISOString(),
73
+ };
74
+ // Send frustration event to Datadog
75
+ if (typeof datadogRum !== 'undefined') {
76
+ datadogRum.addAction('User Frustration Detected', frustrationData);
77
+ }
78
+ // Clear events after reporting
79
+ this.frustrationEvents = [];
80
+ }
81
+ }
82
+ export function datadogReporter(info, config) {
10
83
  const isLocalhost = window.location.hostname === 'localhost';
11
84
  // Don't forward error logs by default, do enable the log transport by default
12
85
  // forwardErrorsToLogs incorrectly is called forwardConsoleLogs, this is for backwards compatibility
13
- const forwardErrorsToLogs = (_a = config.forwardConsoleLogs) !== null && _a !== void 0 ? _a : false;
86
+ const forwardErrorsToLogs = config.forwardConsoleLogs ?? false;
14
87
  const enableLogTransport = config.logTransport !== false;
15
88
  // Only init datadog logs if something is using it.
16
- if (forwardErrorsToLogs !== true && enableLogTransport !== true) {
17
- browser_logs_1.datadogLogs.init({
89
+ if (forwardErrorsToLogs === true || enableLogTransport === true) {
90
+ datadogLogs.init({
18
91
  site: config.site,
19
- proxyUrl: config.proxyUrl,
20
92
  clientToken: config.clientToken,
21
93
  service: info.service,
22
94
  env: info.environment,
23
- version: (_b = config.version) !== null && _b !== void 0 ? _b : info.version,
24
- sampleRate: (_d = (_c = config.logSampleRate) !== null && _c !== void 0 ? _c : config.sampleRate) !== null && _d !== void 0 ? _d : 100,
95
+ version: config.version ?? info.version,
25
96
  beforeSend: config.beforeLogsSend,
26
- useSecureSessionCookie: (_e = config.useSecureSessionCookie) !== null && _e !== void 0 ? _e : !isLocalhost,
27
- useCrossSiteSessionCookie: (_f = config.useCrossSiteSessionCookie) !== null && _f !== void 0 ? _f : false,
97
+ usePartitionedCrossSiteSessionCookie: config.usePartitionedCrossSiteSessionCookie,
98
+ useSecureSessionCookie: config.useSecureSessionCookie ?? !isLocalhost,
99
+ // Note: useCrossSiteSessionCookie is not available in newer Datadog versions
28
100
  trackSessionAcrossSubdomains: config.trackSessionAcrossSubdomains,
29
101
  forwardErrorsToLogs,
102
+ allowedTrackingOrigins: config.allowedTrackingOrigins,
30
103
  });
31
- browser_logs_1.datadogLogs.logger.setHandler(browser_logs_1.HandlerType.http);
104
+ datadogLogs.logger.setHandler(HandlerType.http);
32
105
  }
33
106
  // Add the datadog log transport
34
107
  if (enableLogTransport) {
35
- logger_1.logTransports.push((0, datadogTransport_1.datadogTransport)(typeof config.logTransport === 'boolean' ? {} : config.logTransport));
108
+ logTransports.push(datadogTransport(typeof config.logTransport === 'boolean' ? {} : config.logTransport));
36
109
  }
37
- browser_rum_1.datadogRum.init({
110
+ datadogRum.init({
38
111
  enableExperimentalFeatures: ['feature_flags'],
39
112
  site: config.site,
40
- proxyUrl: config.proxyUrl,
41
113
  clientToken: config.clientToken,
42
114
  applicationId: config.applicationId,
43
115
  service: info.service,
44
116
  env: info.environment,
45
- version: (_g = config.version) !== null && _g !== void 0 ? _g : info.version,
46
- sampleRate: (_j = (_h = config.rumSampleRate) !== null && _h !== void 0 ? _h : config.sampleRate) !== null && _j !== void 0 ? _j : 100,
47
- replaySampleRate: (_k = config.replaySampleRate) !== null && _k !== void 0 ? _k : 100,
48
- useSecureSessionCookie: (_l = config.useSecureSessionCookie) !== null && _l !== void 0 ? _l : !isLocalhost,
49
- useCrossSiteSessionCookie: (_m = config.useCrossSiteSessionCookie) !== null && _m !== void 0 ? _m : false,
117
+ version: config.version ?? info.version,
118
+ usePartitionedCrossSiteSessionCookie: config.usePartitionedCrossSiteSessionCookie,
119
+ // Use correct Datadog v6 SDK options
120
+ sessionSampleRate: config.sessionSampleRate ?? config.rumSampleRate ?? config.sampleRate ?? 100,
121
+ sessionReplaySampleRate: config.sessionReplaySampleRate ?? config.replaySampleRate ?? 100,
122
+ // Track interactions (Note: trackFrustrations is not available in Datadog v6)
123
+ trackUserInteractions: config.trackUserInteractions ?? config.trackInteractions ?? false,
124
+ useSecureSessionCookie: config.useSecureSessionCookie ?? !isLocalhost,
125
+ // Note: useCrossSiteSessionCookie is not available in newer Datadog versions
50
126
  trackSessionAcrossSubdomains: config.trackSessionAcrossSubdomains,
51
- trackInteractions: (_o = config.trackInteractions) !== null && _o !== void 0 ? _o : false,
52
- trackFrustrations: (_p = config.trackFrustrations) !== null && _p !== void 0 ? _p : false,
53
- trackViewsManually: (_q = config.trackViewsManually) !== null && _q !== void 0 ? _q : false,
54
- actionNameAttribute: (_r = config.actionNameAttribute) !== null && _r !== void 0 ? _r : 'data-analytics-name',
127
+ trackViewsManually: config.trackViewsManually ?? false,
128
+ actionNameAttribute: config.actionNameAttribute ?? 'data-analytics-name',
55
129
  beforeSend: config.beforeSend,
56
- defaultPrivacyLevel: (_s = config.defaultPrivacyLevel) !== null && _s !== void 0 ? _s : 'mask-user-input',
57
- allowedTracingOrigins: config.allowedTracingOrigins,
58
- trackUserInteractions: (_t = config.trackUserInteractions) !== null && _t !== void 0 ? _t : false,
130
+ defaultPrivacyLevel: config.defaultPrivacyLevel ?? 'mask-user-input',
131
+ allowedTracingUrls: config.allowedTracingUrls ?? config.allowedTrackingOrigins,
59
132
  excludedActivityUrls: config.excludedActivityUrls,
60
133
  });
134
+ // Initialize frustration detector
135
+ new DatadogFrustrationDetector(config);
61
136
  const reporter = {
62
137
  trackEvent: function (event) {
63
- browser_rum_1.datadogRum.addAction(event.message, {
138
+ datadogRum.addAction(event.message, {
64
139
  level: event.level,
65
140
  ...event.metadata,
66
141
  ...event.tags,
@@ -68,7 +143,7 @@ function datadogReporter(info, config) {
68
143
  });
69
144
  },
70
145
  addBreadcrumb: function (breadcrumb) {
71
- browser_rum_1.datadogRum.addAction(breadcrumb.message, {
146
+ datadogRum.addAction(breadcrumb.message, {
72
147
  ...breadcrumb.metadata,
73
148
  category: breadcrumb.category,
74
149
  });
@@ -76,30 +151,29 @@ function datadogReporter(info, config) {
76
151
  addMetadata: function (metadata) {
77
152
  for (const [key, value] of Object.entries(metadata)) {
78
153
  if (value !== null) {
79
- browser_rum_1.datadogRum.addRumGlobalContext(key, value);
154
+ datadogRum.setGlobalContextProperty(key, value);
80
155
  // Note, this will add duplicate context data in logs.
81
156
  // But this is valuable for logs ingested outside of the browser logger.
82
- browser_logs_1.datadogLogs.addLoggerGlobalContext(key, value);
157
+ datadogLogs.setGlobalContextProperty(key, value);
83
158
  }
84
159
  else {
85
- browser_rum_1.datadogRum.removeRumGlobalContext(key);
160
+ datadogRum.removeGlobalContextProperty(key);
86
161
  // But this is valuable for logs ingested outside of the browser logger.
87
- browser_logs_1.datadogLogs.removeLoggerGlobalContext(key);
162
+ datadogLogs.removeGlobalContextProperty(key);
88
163
  }
89
164
  }
90
165
  },
91
166
  setUser: function (user) {
92
- var _a;
93
167
  if (user) {
94
- browser_rum_1.datadogRum.setUser({
168
+ datadogRum.setUser({
95
169
  ...user,
96
170
  id: user.id,
97
171
  email: user.email,
98
- name: (_a = user.name) !== null && _a !== void 0 ? _a : user.email,
172
+ name: user.name ?? user.email,
99
173
  });
100
174
  }
101
175
  else {
102
- browser_rum_1.datadogRum.removeUser();
176
+ datadogRum.setUser({});
103
177
  }
104
178
  },
105
179
  setRouteName: function (routeName) {
@@ -107,26 +181,25 @@ function datadogReporter(info, config) {
107
181
  },
108
182
  setPageName: function (pageName) {
109
183
  if (config.trackViewsManually) {
110
- browser_rum_1.datadogRum.startView(pageName);
184
+ datadogRum.startView(pageName);
111
185
  }
112
186
  else {
113
187
  reporter.addMetadata({ pageName });
114
188
  }
115
189
  },
116
190
  reportError: function (error, metadata) {
117
- browser_rum_1.datadogRum.addError(error, metadata);
191
+ datadogRum.addError(error, metadata);
118
192
  },
119
193
  reportFeatureFlag: function (flag) {
120
- browser_rum_1.datadogRum.addFeatureFlagEvaluation(flag.name, flag.value);
194
+ datadogRum.addFeatureFlagEvaluation(flag.name, flag.value);
121
195
  },
122
196
  recordSession: function () {
123
- browser_rum_1.datadogRum.startSessionReplayRecording();
197
+ datadogRum.startSessionReplayRecording();
124
198
  },
125
199
  recordSessionStop: function () {
126
- browser_rum_1.datadogRum.stopSessionReplayRecording();
200
+ datadogRum.stopSessionReplayRecording();
127
201
  },
128
202
  };
129
203
  return reporter;
130
204
  }
131
- exports.datadogReporter = datadogReporter;
132
205
  //# sourceMappingURL=datadogReporter.js.map