@grafana/faro-core 1.0.5 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/README.md +43 -0
  2. package/dist/bundle/faro-core.iife.js +1 -1
  3. package/dist/cjs/api/exceptions/initialize.js +3 -1
  4. package/dist/cjs/api/exceptions/initialize.js.map +1 -1
  5. package/dist/cjs/api/exceptions/types.js.map +1 -1
  6. package/dist/cjs/api/logs/types.js.map +1 -1
  7. package/dist/cjs/config/const.js +6 -1
  8. package/dist/cjs/config/const.js.map +1 -1
  9. package/dist/cjs/config/index.js +2 -1
  10. package/dist/cjs/config/index.js.map +1 -1
  11. package/dist/cjs/config/types.js.map +1 -1
  12. package/dist/cjs/globalObject/globalObject.js +7 -1
  13. package/dist/cjs/globalObject/globalObject.js.map +1 -1
  14. package/dist/cjs/index.js +3 -2
  15. package/dist/cjs/index.js.map +1 -1
  16. package/dist/cjs/testUtils/mockConfig.js +2 -0
  17. package/dist/cjs/testUtils/mockConfig.js.map +1 -1
  18. package/dist/cjs/testUtils/mockTransport.js +4 -3
  19. package/dist/cjs/testUtils/mockTransport.js.map +1 -1
  20. package/dist/cjs/transports/base.js +3 -0
  21. package/dist/cjs/transports/base.js.map +1 -1
  22. package/dist/cjs/transports/batchExecutor.js +83 -0
  23. package/dist/cjs/transports/batchExecutor.js.map +1 -0
  24. package/dist/cjs/transports/const.js.map +1 -1
  25. package/dist/cjs/transports/index.js.map +1 -1
  26. package/dist/cjs/transports/initialize.js +69 -14
  27. package/dist/cjs/transports/initialize.js.map +1 -1
  28. package/dist/cjs/transports/types.js.map +1 -1
  29. package/dist/cjs/transports/utils.js +65 -6
  30. package/dist/cjs/transports/utils.js.map +1 -1
  31. package/dist/cjs/version.js +1 -1
  32. package/dist/cjs/version.js.map +1 -1
  33. package/dist/esm/api/exceptions/initialize.js +3 -1
  34. package/dist/esm/api/exceptions/initialize.js.map +1 -1
  35. package/dist/esm/api/exceptions/types.js.map +1 -1
  36. package/dist/esm/api/logs/types.js.map +1 -1
  37. package/dist/esm/config/const.js +5 -0
  38. package/dist/esm/config/const.js.map +1 -1
  39. package/dist/esm/config/index.js +1 -1
  40. package/dist/esm/config/index.js.map +1 -1
  41. package/dist/esm/config/types.js.map +1 -1
  42. package/dist/esm/globalObject/globalObject.js +7 -1
  43. package/dist/esm/globalObject/globalObject.js.map +1 -1
  44. package/dist/esm/index.js +1 -1
  45. package/dist/esm/index.js.map +1 -1
  46. package/dist/esm/testUtils/mockConfig.js +2 -0
  47. package/dist/esm/testUtils/mockConfig.js.map +1 -1
  48. package/dist/esm/testUtils/mockTransport.js +4 -3
  49. package/dist/esm/testUtils/mockTransport.js.map +1 -1
  50. package/dist/esm/transports/base.js +3 -0
  51. package/dist/esm/transports/base.js.map +1 -1
  52. package/dist/esm/transports/batchExecutor.js +67 -0
  53. package/dist/esm/transports/batchExecutor.js.map +1 -0
  54. package/dist/esm/transports/const.js.map +1 -1
  55. package/dist/esm/transports/index.js.map +1 -1
  56. package/dist/esm/transports/initialize.js +66 -12
  57. package/dist/esm/transports/initialize.js.map +1 -1
  58. package/dist/esm/transports/types.js.map +1 -1
  59. package/dist/esm/transports/utils.js +41 -3
  60. package/dist/esm/transports/utils.js.map +1 -1
  61. package/dist/esm/version.js +1 -1
  62. package/dist/esm/version.js.map +1 -1
  63. package/dist/spec/core/src/api/exceptions/initialize.js +3 -1
  64. package/dist/spec/core/src/api/exceptions/initialize.js.map +1 -1
  65. package/dist/spec/core/src/api/exceptions/initialize.test.js +13 -0
  66. package/dist/spec/core/src/api/exceptions/initialize.test.js.map +1 -1
  67. package/dist/spec/core/src/api/exceptions/types.js.map +1 -1
  68. package/dist/spec/core/src/api/logs/initialize.test.js +1 -1
  69. package/dist/spec/core/src/api/logs/initialize.test.js.map +1 -1
  70. package/dist/spec/core/src/api/logs/types.js.map +1 -1
  71. package/dist/spec/core/src/config/const.js +6 -1
  72. package/dist/spec/core/src/config/const.js.map +1 -1
  73. package/dist/spec/core/src/config/index.js +2 -1
  74. package/dist/spec/core/src/config/index.js.map +1 -1
  75. package/dist/spec/core/src/config/types.js.map +1 -1
  76. package/dist/spec/core/src/globalObject/globalObject.js +7 -1
  77. package/dist/spec/core/src/globalObject/globalObject.js.map +1 -1
  78. package/dist/spec/core/src/index.js +3 -2
  79. package/dist/spec/core/src/index.js.map +1 -1
  80. package/dist/spec/core/src/testUtils/mockConfig.js +2 -0
  81. package/dist/spec/core/src/testUtils/mockConfig.js.map +1 -1
  82. package/dist/spec/core/src/testUtils/mockTransport.js +4 -3
  83. package/dist/spec/core/src/testUtils/mockTransport.js.map +1 -1
  84. package/dist/spec/core/src/transports/base.js +3 -0
  85. package/dist/spec/core/src/transports/base.js.map +1 -1
  86. package/dist/spec/core/src/transports/batchExecutor.js +83 -0
  87. package/dist/spec/core/src/transports/batchExecutor.js.map +1 -0
  88. package/dist/spec/core/src/transports/batchExecutor.test.js +179 -0
  89. package/dist/spec/core/src/transports/batchExecutor.test.js.map +1 -0
  90. package/dist/spec/core/src/transports/const.js.map +1 -1
  91. package/dist/spec/core/src/transports/index.js.map +1 -1
  92. package/dist/spec/core/src/transports/initialize.js +69 -14
  93. package/dist/spec/core/src/transports/initialize.js.map +1 -1
  94. package/dist/spec/core/src/transports/transports.test.js +68 -3
  95. package/dist/spec/core/src/transports/transports.test.js.map +1 -1
  96. package/dist/spec/core/src/transports/types.js.map +1 -1
  97. package/dist/spec/core/src/transports/utils.js +65 -6
  98. package/dist/spec/core/src/transports/utils.js.map +1 -1
  99. package/dist/spec/core/src/transports/utils.test.js +216 -0
  100. package/dist/spec/core/src/transports/utils.test.js.map +1 -0
  101. package/dist/spec/core/src/version.js +1 -1
  102. package/dist/spec/core/src/version.js.map +1 -1
  103. package/dist/types/api/exceptions/types.d.ts +3 -0
  104. package/dist/types/api/logs/types.d.ts +2 -2
  105. package/dist/types/config/const.d.ts +5 -0
  106. package/dist/types/config/index.d.ts +1 -1
  107. package/dist/types/config/types.d.ts +3 -2
  108. package/dist/types/core/src/api/exceptions/types.d.ts +3 -0
  109. package/dist/types/core/src/api/logs/types.d.ts +2 -2
  110. package/dist/types/core/src/config/const.d.ts +5 -0
  111. package/dist/types/core/src/config/index.d.ts +1 -1
  112. package/dist/types/core/src/config/types.d.ts +3 -2
  113. package/dist/types/core/src/globalObject/globalObject.d.ts +1 -1
  114. package/dist/types/core/src/index.d.ts +2 -2
  115. package/dist/types/core/src/testUtils/mockTransport.d.ts +3 -2
  116. package/dist/types/core/src/transports/base.d.ts +2 -1
  117. package/dist/types/core/src/transports/batchExecutor.d.ts +16 -0
  118. package/dist/types/core/src/transports/batchExecutor.test.d.ts +1 -0
  119. package/dist/types/core/src/transports/const.d.ts +2 -1
  120. package/dist/types/core/src/transports/index.d.ts +1 -1
  121. package/dist/types/core/src/transports/types.d.ts +9 -0
  122. package/dist/types/core/src/transports/utils.d.ts +4 -1
  123. package/dist/types/core/src/transports/utils.test.d.ts +1 -0
  124. package/dist/types/core/src/version.d.ts +1 -1
  125. package/dist/types/globalObject/globalObject.d.ts +1 -1
  126. package/dist/types/index.d.ts +2 -2
  127. package/dist/types/testUtils/mockTransport.d.ts +3 -2
  128. package/dist/types/transports/base.d.ts +2 -1
  129. package/dist/types/transports/batchExecutor.d.ts +16 -0
  130. package/dist/types/transports/const.d.ts +2 -1
  131. package/dist/types/transports/index.d.ts +1 -1
  132. package/dist/types/transports/types.d.ts +9 -0
  133. package/dist/types/transports/utils.d.ts +4 -1
  134. package/dist/types/version.d.ts +1 -1
  135. package/package.json +7 -3
@@ -11,6 +11,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
12
  exports.initializeTransports = exports.createBeforeSendHookFromIgnorePatterns = exports.shouldIgnoreEvent = void 0;
13
13
  var utils_1 = require("../utils");
14
+ var batchExecutor_1 = require("./batchExecutor");
14
15
  var const_1 = require("./const");
15
16
  function shouldIgnoreEvent(patterns, msg) {
16
17
  return patterns.some(function (pattern) {
@@ -32,6 +33,7 @@ function createBeforeSendHookFromIgnorePatterns(patterns) {
32
33
  }
33
34
  exports.createBeforeSendHookFromIgnorePatterns = createBeforeSendHookFromIgnorePatterns;
34
35
  function initializeTransports(unpatchedConsole, internalLogger, config, metas) {
36
+ var _a;
35
37
  internalLogger.debug('Initializing transports');
36
38
  var transports = [];
37
39
  var paused = config.paused;
@@ -80,28 +82,80 @@ function initializeTransports(unpatchedConsole, internalLogger, config, metas) {
80
82
  }
81
83
  });
82
84
  };
83
- var execute = function (item) {
84
- if (!paused) {
85
- var actualItem = item;
86
- for (var _i = 0, beforeSendHooks_1 = beforeSendHooks; _i < beforeSendHooks_1.length; _i++) {
87
- var hook = beforeSendHooks_1[_i];
88
- var modified = hook(actualItem);
89
- if (modified === null) {
90
- return;
91
- }
92
- actualItem = modified;
85
+ var applyBeforeSendHooks = function (items) {
86
+ var filteredItems = items;
87
+ for (var _i = 0, beforeSendHooks_1 = beforeSendHooks; _i < beforeSendHooks_1.length; _i++) {
88
+ var hook = beforeSendHooks_1[_i];
89
+ var modified = filteredItems.map(hook).filter(Boolean);
90
+ if (modified.length === 0) {
91
+ return [];
92
+ }
93
+ filteredItems = modified;
94
+ }
95
+ return filteredItems;
96
+ };
97
+ var batchedSend = function (items) {
98
+ var filteredItems = applyBeforeSendHooks(items);
99
+ if (filteredItems.length === 0) {
100
+ return;
101
+ }
102
+ for (var _i = 0, transports_1 = transports; _i < transports_1.length; _i++) {
103
+ var transport = transports_1[_i];
104
+ internalLogger.debug("Transporting item using ".concat(transport.name, "\n"), filteredItems);
105
+ if (transport.isBatched()) {
106
+ transport.send(filteredItems);
93
107
  }
94
- for (var _a = 0, transports_1 = transports; _a < transports_1.length; _a++) {
95
- var transport = transports_1[_a];
96
- internalLogger.debug("Transporting item using ".concat(transport.name, "\n"), actualItem);
97
- transport.send(actualItem);
108
+ }
109
+ };
110
+ var instantSend = function (item) {
111
+ var _a;
112
+ var filteredItem = applyBeforeSendHooks([item])[0];
113
+ if (filteredItem === undefined) {
114
+ return;
115
+ }
116
+ for (var _i = 0, transports_2 = transports; _i < transports_2.length; _i++) {
117
+ var transport = transports_2[_i];
118
+ internalLogger.debug("Transporting item using ".concat(transport.name, "\n"), filteredItem);
119
+ if (!transport.isBatched()) {
120
+ transport.send(filteredItem);
98
121
  }
122
+ else if (!((_a = config.batching) === null || _a === void 0 ? void 0 : _a.enabled)) {
123
+ transport.send([filteredItem]);
124
+ }
125
+ }
126
+ };
127
+ var batchExecutor;
128
+ if ((_a = config.batching) === null || _a === void 0 ? void 0 : _a.enabled) {
129
+ batchExecutor = new batchExecutor_1.BatchExecutor(batchedSend, {
130
+ sendTimeout: config.batching.sendTimeout,
131
+ itemLimit: config.batching.itemLimit,
132
+ paused: paused,
133
+ });
134
+ }
135
+ // Send a signal to the appropriate transports
136
+ //
137
+ // 1. If SDK is paused, early return
138
+ // 2. If batching is not enabled send the signal to all transports
139
+ // instantly.
140
+ // 3i. If batching is enabled, enqueue the signal
141
+ // 3ii. Send the signal instantly to all un-batched transports
142
+ var execute = function (item) {
143
+ var _a;
144
+ if (paused) {
145
+ return;
146
+ }
147
+ if (!((_a = config.batching) === null || _a === void 0 ? void 0 : _a.enabled)) {
148
+ instantSend(item);
149
+ return;
99
150
  }
151
+ batchExecutor === null || batchExecutor === void 0 ? void 0 : batchExecutor.addItem(item);
152
+ instantSend(item);
100
153
  };
101
154
  var getBeforeSendHooks = function () { return __spreadArray([], beforeSendHooks, true); };
102
155
  var isPaused = function () { return paused; };
103
156
  var pause = function () {
104
157
  internalLogger.debug('Pausing transports');
158
+ batchExecutor === null || batchExecutor === void 0 ? void 0 : batchExecutor.pause();
105
159
  paused = true;
106
160
  };
107
161
  var remove = function () {
@@ -129,6 +183,7 @@ function initializeTransports(unpatchedConsole, internalLogger, config, metas) {
129
183
  };
130
184
  var unpause = function () {
131
185
  internalLogger.debug('Unpausing transports');
186
+ batchExecutor === null || batchExecutor === void 0 ? void 0 : batchExecutor.start();
132
187
  paused = false;
133
188
  };
134
189
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../src/transports/initialize.ts"],"names":[],"mappings":";;;;;;;;;;;;AAKA,kCAAoC;AAEpC,iCAA4C;AAG5C,SAAgB,iBAAiB,CAAC,QAAkB,EAAE,GAAW;IAC/D,OAAO,QAAQ,CAAC,IAAI,CAAC,UAAC,OAAO;QAC3B,OAAO,IAAA,gBAAQ,EAAC,OAAO,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;IAC1E,CAAC,CAAC,CAAC;AACL,CAAC;AAJD,8CAIC;AAED,SAAgB,sCAAsC,CAAC,QAAkB;IACvE,OAAO,UAAC,IAAI;QACV,IAAI,IAAI,CAAC,IAAI,KAAK,yBAAiB,CAAC,SAAS,IAAI,IAAI,CAAC,OAAO,EAAE;YAC7D,IAAM,GAAG,GAAG,IAAI,CAAC,OAAyB,CAAC;YAC3C,IAAM,GAAG,GAAG,UAAG,GAAG,CAAC,IAAI,eAAK,GAAG,CAAC,KAAK,CAAE,CAAC;YAExC,IAAI,iBAAiB,CAAC,QAAQ,EAAE,GAAG,CAAC,EAAE;gBACpC,OAAO,IAAI,CAAC;aACb;SACF;QAED,OAAO,IAAI,CAAC;IACd,CAAC,CAAC;AACJ,CAAC;AAbD,wFAaC;AAED,SAAgB,oBAAoB,CAClC,gBAAkC,EAClC,cAA8B,EAC9B,MAAc,EACd,KAAY;IAEZ,cAAc,CAAC,KAAK,CAAC,yBAAyB,CAAC,CAAC;IAEhD,IAAM,UAAU,GAAgB,EAAE,CAAC;IAEnC,IAAI,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;IAE3B,IAAI,eAAe,GAAqB,EAAE,CAAC;IAE3C,IAAM,GAAG,GAAsB;QAAC,uBAAgB;aA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,UAAC,iBAAiB;YAC3C,cAAc,CAAC,KAAK,CAAC,qBAAa,iBAAiB,CAAC,IAAI,iBAAa,CAAC,CAAC;YAEvE,IAAM,sBAAsB,GAAG,UAAU,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC;YAErE,IAAI,sBAAsB,KAAK,CAAC,CAAC,EAAE;gBACjC,cAAc,CAAC,IAAI,CAAC,sBAAc,iBAAiB,CAAC,IAAI,oBAAgB,CAAC,CAAC;gBAE1E,OAAO;aACR;YAED,UAAU,CAAC,MAAM,CAAC,sBAAsB,EAAE,CAAC,CAAC,CAAC;QAC/C,CAAC,CAAC,CAAC;IACL,CAAC,CAAC;IAEF,IAAM,qBAAqB,GAAwC;QAAC,iCAA0B;aAA1B,UAA0B,EAA1B,qBAA0B,EAA1B,IAA0B;YAA1B,4CAA0B;;QAC5F,eAAe,CAAC,MAAM,CAAC,UAAC,cAAc,IAAK,OAAA,CAAC,uBAAuB,CAAC,QAAQ,CAAC,cAAc,CAAC,EAAjD,CAAiD,CAAC,CAAC;IAChG,CAAC,CAAC;IAEF,IAAM,OAAO,GAA0B;QACrC,cAAc,CAAC,KAAK,CAAC,sBAAsB,CAAC,CAAC;QAE7C,MAAM,GAAG,KAAK,CAAC;IACjB,CAAC,CAAC;IAEF,OAAO;QACL,GAAG,KAAA;QACH,kBAAkB,oBAAA;QAClB,uBAAuB,yBAAA;QACvB,kBAAkB,oBAAA;QAClB,OAAO,SAAA;QACP,QAAQ,UAAA;QACR,KAAK,OAAA;QACL,MAAM,QAAA;QACN,qBAAqB,uBAAA;QACrB,IAAI,UAAU;YACZ,yBAAW,UAAU,QAAE;QACzB,CAAC;QACD,OAAO,SAAA;KACR,CAAC;AACJ,CAAC;AApID,oDAoIC","sourcesContent":["import type { ExceptionEvent } from '../api';\nimport type { Config, Patterns } from '../config';\nimport type { InternalLogger } from '../internalLogger';\nimport type { Metas } from '../metas';\nimport type { UnpatchedConsole } from '../unpatchedConsole';\nimport { isString } from '../utils';\n\nimport { TransportItemType } from './const';\nimport type { BeforeSendHook, Transport, Transports } from './types';\n\nexport function shouldIgnoreEvent(patterns: Patterns, msg: string): boolean {\n return patterns.some((pattern) => {\n return isString(pattern) ? msg.includes(pattern) : !!msg.match(pattern);\n });\n}\n\nexport function createBeforeSendHookFromIgnorePatterns(patterns: Patterns): BeforeSendHook {\n return (item) => {\n if (item.type === TransportItemType.EXCEPTION && item.payload) {\n const evt = item.payload as ExceptionEvent;\n const msg = `${evt.type}: ${evt.value}`;\n\n if (shouldIgnoreEvent(patterns, msg)) {\n return null;\n }\n }\n\n return item;\n };\n}\n\nexport function initializeTransports(\n unpatchedConsole: UnpatchedConsole,\n internalLogger: InternalLogger,\n config: Config,\n metas: Metas\n): Transports {\n internalLogger.debug('Initializing transports');\n\n const transports: Transport[] = [];\n\n let paused = config.paused;\n\n let beforeSendHooks: BeforeSendHook[] = [];\n\n const add: Transports['add'] = (...newTransports) => {\n internalLogger.debug('Adding transports');\n\n newTransports.forEach((newTransport) => {\n internalLogger.debug(`Adding \"${newTransport.name}\" transport`);\n\n const exists = transports.some((existingTransport) => existingTransport === newTransport);\n\n if (exists) {\n internalLogger.warn(`Transport ${newTransport.name} is already added`);\n\n return;\n }\n\n newTransport.unpatchedConsole = unpatchedConsole;\n newTransport.internalLogger = internalLogger;\n newTransport.config = config;\n newTransport.metas = metas;\n\n transports.push(newTransport);\n });\n };\n\n const addBeforeSendHooks: Transports['addBeforeSendHooks'] = (...newBeforeSendHooks) => {\n internalLogger.debug('Adding beforeSendHooks\\n', beforeSendHooks);\n\n newBeforeSendHooks.forEach((beforeSendHook) => {\n if (beforeSendHook) {\n beforeSendHooks.push(beforeSendHook);\n }\n });\n };\n\n const addIgnoreErrorsPatterns: Transports['addIgnoreErrorsPatterns'] = (...ignoreErrorsPatterns) => {\n internalLogger.debug('Adding ignoreErrorsPatterns\\n', ignoreErrorsPatterns);\n\n ignoreErrorsPatterns.forEach((ignoreErrorsPattern) => {\n if (ignoreErrorsPattern) {\n beforeSendHooks.push(createBeforeSendHookFromIgnorePatterns(ignoreErrorsPattern));\n }\n });\n };\n\n const execute: Transports['execute'] = (item) => {\n if (!paused) {\n let actualItem = item;\n\n for (const hook of beforeSendHooks) {\n const modified = hook(actualItem);\n\n if (modified === null) {\n return;\n }\n\n actualItem = modified;\n }\n\n for (const transport of transports) {\n internalLogger.debug(`Transporting item using ${transport.name}\\n`, actualItem);\n\n transport.send(actualItem);\n }\n }\n };\n\n const getBeforeSendHooks: Transports['getBeforeSendHooks'] = () => [...beforeSendHooks];\n\n const isPaused: Transports['isPaused'] = () => paused;\n\n const pause: Transports['pause'] = () => {\n internalLogger.debug('Pausing transports');\n\n paused = true;\n };\n\n const remove: Transports['remove'] = (...transportsToRemove) => {\n internalLogger.debug('Removing transports');\n\n transportsToRemove.forEach((transportToRemove) => {\n internalLogger.debug(`Removing \"${transportToRemove.name}\" transport`);\n\n const existingTransportIndex = transports.indexOf(transportToRemove);\n\n if (existingTransportIndex === -1) {\n internalLogger.warn(`Transport \"${transportToRemove.name}\" is not added`);\n\n return;\n }\n\n transports.splice(existingTransportIndex, 1);\n });\n };\n\n const removeBeforeSendHooks: Transports['removeBeforeSendHooks'] = (...beforeSendHooksToRemove) => {\n beforeSendHooks.filter((beforeSendHook) => !beforeSendHooksToRemove.includes(beforeSendHook));\n };\n\n const unpause: Transports['unpause'] = () => {\n internalLogger.debug('Unpausing transports');\n\n paused = false;\n };\n\n return {\n add,\n addBeforeSendHooks,\n addIgnoreErrorsPatterns,\n getBeforeSendHooks,\n execute,\n isPaused,\n pause,\n remove,\n removeBeforeSendHooks,\n get transports() {\n return [...transports];\n },\n unpause,\n };\n}\n"]}
1
+ {"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../src/transports/initialize.ts"],"names":[],"mappings":";;;;;;;;;;;;AAMA,kCAAoC;AAEpC,iDAAgD;AAChD,iCAA4C;AAG5C,SAAgB,iBAAiB,CAAC,QAAkB,EAAE,GAAW;IAC/D,OAAO,QAAQ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,UAAU;YACZ,yBAAW,UAAU,QAAE;QACzB,CAAC;QACD,OAAO,SAAA;KACR,CAAC;AACJ,CAAC;AA7LD,oDA6LC","sourcesContent":["import type { TransportItem } from '..';\nimport type { ExceptionEvent } from '../api';\nimport type { Config, Patterns } from '../config';\nimport type { InternalLogger } from '../internalLogger';\nimport type { Metas } from '../metas';\nimport type { UnpatchedConsole } from '../unpatchedConsole';\nimport { isString } from '../utils';\n\nimport { BatchExecutor } from './batchExecutor';\nimport { TransportItemType } from './const';\nimport type { BeforeSendHook, Transport, Transports } from './types';\n\nexport function shouldIgnoreEvent(patterns: Patterns, msg: string): boolean {\n return patterns.some((pattern) => {\n return isString(pattern) ? msg.includes(pattern) : !!msg.match(pattern);\n });\n}\n\nexport function createBeforeSendHookFromIgnorePatterns(patterns: Patterns): BeforeSendHook {\n return (item: TransportItem) => {\n if (item.type === TransportItemType.EXCEPTION && item.payload) {\n const evt = item.payload as ExceptionEvent;\n const msg = `${evt.type}: ${evt.value}`;\n\n if (shouldIgnoreEvent(patterns, msg)) {\n return null;\n }\n }\n\n return item;\n };\n}\n\nexport function initializeTransports(\n unpatchedConsole: UnpatchedConsole,\n internalLogger: InternalLogger,\n config: Config,\n metas: Metas\n): Transports {\n internalLogger.debug('Initializing transports');\n\n const transports: Transport[] = [];\n\n let paused = config.paused;\n\n let beforeSendHooks: BeforeSendHook[] = [];\n\n const add: Transports['add'] = (...newTransports) => {\n internalLogger.debug('Adding transports');\n\n newTransports.forEach((newTransport) => {\n internalLogger.debug(`Adding \"${newTransport.name}\" transport`);\n\n const exists = transports.some((existingTransport) => existingTransport === newTransport);\n\n if (exists) {\n internalLogger.warn(`Transport ${newTransport.name} is already added`);\n\n return;\n }\n\n newTransport.unpatchedConsole = unpatchedConsole;\n newTransport.internalLogger = internalLogger;\n newTransport.config = config;\n newTransport.metas = metas;\n\n transports.push(newTransport);\n });\n };\n\n const addBeforeSendHooks: Transports['addBeforeSendHooks'] = (...newBeforeSendHooks) => {\n internalLogger.debug('Adding beforeSendHooks\\n', beforeSendHooks);\n\n newBeforeSendHooks.forEach((beforeSendHook) => {\n if (beforeSendHook) {\n beforeSendHooks.push(beforeSendHook);\n }\n });\n };\n\n const addIgnoreErrorsPatterns: Transports['addIgnoreErrorsPatterns'] = (...ignoreErrorsPatterns) => {\n internalLogger.debug('Adding ignoreErrorsPatterns\\n', ignoreErrorsPatterns);\n\n ignoreErrorsPatterns.forEach((ignoreErrorsPattern) => {\n if (ignoreErrorsPattern) {\n beforeSendHooks.push(createBeforeSendHookFromIgnorePatterns(ignoreErrorsPattern));\n }\n });\n };\n\n const applyBeforeSendHooks = (items: TransportItem[]): TransportItem[] => {\n let filteredItems = items;\n for (const hook of beforeSendHooks) {\n const modified = filteredItems.map(hook).filter(Boolean) as TransportItem[];\n\n if (modified.length === 0) {\n return [];\n }\n\n filteredItems = modified;\n }\n return filteredItems;\n };\n\n const batchedSend = (items: TransportItem[]) => {\n const filteredItems = applyBeforeSendHooks(items);\n\n if (filteredItems.length === 0) {\n return;\n }\n\n for (const transport of transports) {\n internalLogger.debug(`Transporting item using ${transport.name}\\n`, filteredItems);\n if (transport.isBatched()) {\n transport.send(filteredItems);\n }\n }\n };\n\n const instantSend = (item: TransportItem) => {\n const [filteredItem] = applyBeforeSendHooks([item]);\n\n if (filteredItem === undefined) {\n return;\n }\n\n for (const transport of transports) {\n internalLogger.debug(`Transporting item using ${transport.name}\\n`, filteredItem);\n if (!transport.isBatched()) {\n transport.send(filteredItem);\n } else if (!config.batching?.enabled) {\n transport.send([filteredItem]);\n }\n }\n };\n\n let batchExecutor: BatchExecutor | undefined;\n\n if (config.batching?.enabled) {\n batchExecutor = new BatchExecutor(batchedSend, {\n sendTimeout: config.batching.sendTimeout,\n itemLimit: config.batching.itemLimit,\n paused,\n });\n }\n\n // Send a signal to the appropriate transports\n //\n // 1. If SDK is paused, early return\n // 2. If batching is not enabled send the signal to all transports\n // instantly.\n // 3i. If batching is enabled, enqueue the signal\n // 3ii. Send the signal instantly to all un-batched transports\n const execute: Transports['execute'] = (item) => {\n if (paused) {\n return;\n }\n\n if (!config.batching?.enabled) {\n instantSend(item);\n return;\n }\n\n batchExecutor?.addItem(item);\n instantSend(item);\n };\n\n const getBeforeSendHooks: Transports['getBeforeSendHooks'] = () => [...beforeSendHooks];\n\n const isPaused: Transports['isPaused'] = () => paused;\n\n const pause: Transports['pause'] = () => {\n internalLogger.debug('Pausing transports');\n batchExecutor?.pause();\n\n paused = true;\n };\n\n const remove: Transports['remove'] = (...transportsToRemove) => {\n internalLogger.debug('Removing transports');\n\n transportsToRemove.forEach((transportToRemove) => {\n internalLogger.debug(`Removing \"${transportToRemove.name}\" transport`);\n\n const existingTransportIndex = transports.indexOf(transportToRemove);\n\n if (existingTransportIndex === -1) {\n internalLogger.warn(`Transport \"${transportToRemove.name}\" is not added`);\n\n return;\n }\n\n transports.splice(existingTransportIndex, 1);\n });\n };\n\n const removeBeforeSendHooks: Transports['removeBeforeSendHooks'] = (...beforeSendHooksToRemove) => {\n beforeSendHooks.filter((beforeSendHook) => !beforeSendHooksToRemove.includes(beforeSendHook));\n };\n\n const unpause: Transports['unpause'] = () => {\n internalLogger.debug('Unpausing transports');\n batchExecutor?.start();\n\n paused = false;\n };\n\n return {\n add,\n addBeforeSendHooks,\n addIgnoreErrorsPatterns,\n getBeforeSendHooks,\n execute,\n isPaused,\n pause,\n remove,\n removeBeforeSendHooks,\n get transports() {\n return [...transports];\n },\n unpause,\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/transports/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { APIEvent, EventEvent, ExceptionEvent, LogEvent, MeasurementEvent, TraceEvent } from '../api';\nimport type { Patterns } from '../config';\nimport type { Extension } from '../extensions';\nimport type { Meta } from '../metas';\n\nimport type { TransportItemType } from './const';\n\nexport type TransportItemPayload<P = APIEvent> = P;\n\nexport type BeforeSendHook<P = APIEvent> = (item: TransportItem<P>) => TransportItem<P> | null;\n\nexport interface TransportItem<P = APIEvent> {\n type: TransportItemType;\n payload: TransportItemPayload<P>;\n meta: Meta;\n}\n\nexport interface Transport extends Extension {\n send(items: TransportItem | TransportItem[]): void | Promise<void>;\n\n // returns URLs to be ignored by tracing, to not cause a feedback loop\n getIgnoreUrls(): Patterns;\n}\n\nexport interface TransportBody {\n meta: Meta;\n\n exceptions?: ExceptionEvent[];\n logs?: LogEvent[];\n measurements?: MeasurementEvent[];\n traces?: TraceEvent;\n events?: EventEvent[];\n}\n\nexport interface Transports {\n add: (...transports: Transport[]) => void;\n addBeforeSendHooks: (...hooks: Array<BeforeSendHook | undefined>) => void;\n addIgnoreErrorsPatterns: (...ignoreErrorsPatterns: Array<Patterns | undefined>) => void;\n execute: (transportItem: TransportItem) => void;\n getBeforeSendHooks: () => BeforeSendHook[];\n isPaused: () => boolean;\n remove: (...transports: Transport[]) => void;\n removeBeforeSendHooks: (...hooks: Array<BeforeSendHook | undefined>) => void;\n transports: Transport[];\n pause: () => void;\n unpause: () => void;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/transports/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { APIEvent, EventEvent, ExceptionEvent, LogEvent, MeasurementEvent, TraceEvent } from '../api';\nimport type { Patterns } from '../config';\nimport type { Extension } from '../extensions';\nimport type { Meta } from '../metas';\n\nimport type { TransportItemType } from './const';\n\nexport type TransportItemPayload<P = APIEvent> = P;\n\nexport type SendFn<P = APIEvent> = (items: Array<TransportItem<P>>) => void;\nexport type BeforeSendHook<P = APIEvent> = (item: TransportItem<P>) => TransportItem<P> | null;\n\nexport interface TransportItem<P = APIEvent> {\n type: TransportItemType;\n payload: TransportItemPayload<P>;\n meta: Meta;\n}\n\nexport interface Transport extends Extension {\n send(items: TransportItem | TransportItem[]): void | Promise<void>;\n\n // returns URLs to be ignored by tracing, to not cause a feedback loop\n getIgnoreUrls(): Patterns;\n // returns wether the transport supports processing of a batches of items\n isBatched(): boolean;\n}\n\nexport type BodyKey = 'exceptions' | 'logs' | 'measurements' | 'traces' | 'events';\n\nexport interface TransportBody {\n meta: Meta;\n\n exceptions?: ExceptionEvent[];\n logs?: LogEvent[];\n measurements?: MeasurementEvent[];\n traces?: TraceEvent;\n events?: EventEvent[];\n}\n\nexport interface Transports {\n add: (...transports: Transport[]) => void;\n addBeforeSendHooks: (...hooks: Array<BeforeSendHook | undefined>) => void;\n addIgnoreErrorsPatterns: (...ignoreErrorsPatterns: Array<Patterns | undefined>) => void;\n execute: (transportItem: TransportItem) => void;\n getBeforeSendHooks: () => BeforeSendHook[];\n isPaused: () => boolean;\n remove: (...transports: Transport[]) => void;\n removeBeforeSendHooks: (...hooks: Array<BeforeSendHook | undefined>) => void;\n transports: Transport[];\n pause: () => void;\n unpause: () => void;\n}\n\nexport interface BatchExecutorOptions {\n readonly enabled?: boolean;\n // If no new signal arrives after \"batchSendTimeout\" ms, send the payload. If set to 0, timeout is disabled\n readonly sendTimeout?: number;\n // Buffer \"sendLimit\" is the number of signals before sending the payload\n readonly itemLimit?: number;\n readonly paused?: boolean;\n}\n"]}
@@ -1,13 +1,72 @@
1
1
  "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
+ if (ar || !(i in from)) {
16
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
17
+ ar[i] = from[i];
18
+ }
19
+ }
20
+ return to.concat(ar || Array.prototype.slice.call(from));
21
+ };
2
22
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getTransportBody = void 0;
23
+ exports.getTransportBody = exports.mergeResourceSpans = void 0;
4
24
  var const_1 = require("./const");
25
+ function mergeResourceSpans(traces, resourceSpans) {
26
+ var _a, _b;
27
+ if (resourceSpans === undefined) {
28
+ return traces;
29
+ }
30
+ if (traces === undefined) {
31
+ return {
32
+ resourceSpans: resourceSpans,
33
+ };
34
+ }
35
+ var currentResource = (_a = traces.resourceSpans) === null || _a === void 0 ? void 0 : _a[0];
36
+ if (currentResource === undefined) {
37
+ return traces;
38
+ }
39
+ var currentSpans = (currentResource === null || currentResource === void 0 ? void 0 : currentResource.scopeSpans) || [];
40
+ var newSpans = ((_b = resourceSpans === null || resourceSpans === void 0 ? void 0 : resourceSpans[0]) === null || _b === void 0 ? void 0 : _b.scopeSpans) || [];
41
+ return __assign(__assign({}, traces), { resourceSpans: [
42
+ __assign(__assign({}, currentResource), { scopeSpans: __spreadArray(__spreadArray([], currentSpans, true), newSpans, true) }),
43
+ ] });
44
+ }
45
+ exports.mergeResourceSpans = mergeResourceSpans;
5
46
  function getTransportBody(item) {
6
- var _a;
7
- return _a = {},
8
- _a[const_1.transportItemTypeToBodyKey[item.type]] = item.type === const_1.TransportItemType.TRACE ? item.payload : [item.payload],
9
- _a.meta = item.meta,
10
- _a;
47
+ var body = {
48
+ meta: {},
49
+ };
50
+ if (item[0] !== undefined) {
51
+ body.meta = item[0].meta;
52
+ }
53
+ item.forEach(function (currentItem) {
54
+ var _a;
55
+ switch (currentItem.type) {
56
+ case const_1.TransportItemType.LOG:
57
+ case const_1.TransportItemType.EVENT:
58
+ case const_1.TransportItemType.EXCEPTION:
59
+ case const_1.TransportItemType.MEASUREMENT:
60
+ var bk = const_1.transportItemTypeToBodyKey[currentItem.type];
61
+ var signals = body[bk];
62
+ body = __assign(__assign({}, body), (_a = {}, _a[bk] = signals === undefined ? [currentItem.payload] : __spreadArray(__spreadArray([], signals, true), [currentItem.payload], false), _a));
63
+ break;
64
+ case const_1.TransportItemType.TRACE:
65
+ body = __assign(__assign({}, body), { traces: mergeResourceSpans(body.traces, currentItem.payload.resourceSpans) });
66
+ break;
67
+ }
68
+ });
69
+ return body;
11
70
  }
12
71
  exports.getTransportBody = getTransportBody;
13
72
  //# sourceMappingURL=utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/transports/utils.ts"],"names":[],"mappings":";;;AAAA,iCAAwE;AAGxE,SAAgB,gBAAgB,CAAC,IAAmB;;IAClD;QACE,GAAC,kCAA0B,CAAC,IAAI,CAAC,IAAI,CAAC,IAAG,IAAI,CAAC,IAAI,KAAK,yBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC;QAC9G,OAAI,GAAE,IAAI,CAAC,IAAI;WACf;AACJ,CAAC;AALD,4CAKC","sourcesContent":["import { TransportItemType, transportItemTypeToBodyKey } from './const';\nimport type { TransportBody, TransportItem } from './types';\n\nexport function getTransportBody(item: TransportItem): TransportBody {\n return {\n [transportItemTypeToBodyKey[item.type]]: item.type === TransportItemType.TRACE ? item.payload : [item.payload],\n meta: item.meta,\n };\n}\n"]}
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/transports/utils.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAIA,iCAAwE;AAGxE,SAAgB,kBAAkB,CAAC,MAAmB,EAAE,aAAgC;;IACtF,IAAI,aAAa,KAAK,SAAS,EAAE;QAC/B,OAAO,MAAM,CAAC;KACf;IAED,IAAI,MAAM,KAAK,SAAS,EAAE;QACxB,OAAO;YACL,aAAa,eAAA;SACd,CAAC;KACH;IAED,IAAM,eAAe,GAAG,MAAA,MAAM,CAAC,aAAa,0CAAG,CAAC,CAAC,CAAC;IAClD,IAAI,eAAe,KAAK,SAAS,EAAE;QACjC,OAAO,MAAM,CAAC;KACf;IAED,IAAM,YAAY,GAAG,CAAA,eAAe,aAAf,eAAe,uBAAf,eAAe,CA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CAAC,CAAC,CAAC;IAEH,OAAO,IAAI,CAAC;AACd,CAAC;AAjCD,4CAiCC","sourcesContent":["import type { IResourceSpans } from '@opentelemetry/otlp-transformer';\n\nimport type { EventEvent, ExceptionEvent, LogEvent, MeasurementEvent, TraceEvent } from '..';\n\nimport { TransportItemType, transportItemTypeToBodyKey } from './const';\nimport type { TransportBody, TransportItem } from './types';\n\nexport function mergeResourceSpans(traces?: TraceEvent, resourceSpans?: IResourceSpans[]): TraceEvent | undefined {\n if (resourceSpans === undefined) {\n return traces;\n }\n\n if (traces === undefined) {\n return {\n resourceSpans,\n };\n }\n\n const currentResource = traces.resourceSpans?.[0];\n if (currentResource === undefined) {\n return traces;\n }\n\n const currentSpans = currentResource?.scopeSpans || [];\n const newSpans = resourceSpans?.[0]?.scopeSpans || [];\n\n return {\n ...traces,\n resourceSpans: [\n {\n ...currentResource,\n scopeSpans: [...currentSpans, ...newSpans],\n },\n ],\n };\n}\n\nexport function getTransportBody(item: TransportItem[]): TransportBody {\n let body: TransportBody = {\n meta: {},\n };\n\n if (item[0] !== undefined) {\n body.meta = item[0].meta;\n }\n\n item.forEach((currentItem: TransportItem) => {\n switch (currentItem.type) {\n case TransportItemType.LOG:\n case TransportItemType.EVENT:\n case TransportItemType.EXCEPTION:\n case TransportItemType.MEASUREMENT:\n const bk = transportItemTypeToBodyKey[currentItem.type];\n const signals = body[bk] as LogEvent[] | EventEvent[] | ExceptionEvent[] | MeasurementEvent[];\n\n body = {\n ...body,\n [bk]: signals === undefined ? [currentItem.payload] : [...signals, currentItem.payload],\n };\n break;\n case TransportItemType.TRACE:\n body = {\n ...body,\n traces: mergeResourceSpans(body.traces, (currentItem.payload as TraceEvent).resourceSpans),\n };\n break;\n }\n });\n\n return body;\n}\n"]}
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
4
  // auto-generated by bin/genVersion.ts
5
- exports.VERSION = '1.0.5';
5
+ exports.VERSION = '1.1.0';
6
6
  //# sourceMappingURL=version.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAA,sCAAsC;AACzB,QAAA,OAAO,GAAG,OAAO,CAAC","sourcesContent":["// auto-generated by bin/genVersion.ts\nexport const VERSION = '1.0.5';\n"]}
1
+ {"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";;;AAAA,sCAAsC;AACzB,QAAA,OAAO,GAAG,OAAO,CAAC","sourcesContent":["// auto-generated by bin/genVersion.ts\nexport const VERSION = '1.1.0';\n"]}
@@ -12,7 +12,7 @@ export function initializeExceptionsAPI(_unpatchedConsole, internalLogger, confi
12
12
  stacktraceParser = newStacktraceParser !== null && newStacktraceParser !== void 0 ? newStacktraceParser : stacktraceParser;
13
13
  };
14
14
  const getStacktraceParser = () => stacktraceParser;
15
- const pushError = (error, { skipDedupe, stackFrames, type } = {}) => {
15
+ const pushError = (error, { skipDedupe, stackFrames, type, context } = {}) => {
16
16
  type = type || error.name || defaultExceptionType;
17
17
  const item = {
18
18
  meta: metas.value,
@@ -21,6 +21,7 @@ export function initializeExceptionsAPI(_unpatchedConsole, internalLogger, confi
21
21
  value: error.message,
22
22
  timestamp: getCurrentTimestamp(),
23
23
  trace: tracesApi.getTraceContext(),
24
+ context: context !== null && context !== void 0 ? context : {},
24
25
  },
25
26
  type: TransportItemType.EXCEPTION,
26
27
  };
@@ -34,6 +35,7 @@ export function initializeExceptionsAPI(_unpatchedConsole, internalLogger, confi
34
35
  type: item.payload.type,
35
36
  value: item.payload.value,
36
37
  stackTrace: item.payload.stacktrace,
38
+ context: item.payload.context,
37
39
  };
38
40
  if (!skipDedupe && config.dedupe && !isNull(lastPayload) && deepEqual(testingPayload, lastPayload)) {
39
41
  internalLogger.debug('Skipping error push because it is the same as the last one\n', item.payload);
@@ -1 +1 @@
1
- {"version":3,"file":"initialize.js","sourceRoot":"","sources":["../../../../src/api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AAW,aAAX,WAAW,cAAX,WAAW,GAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAG,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAE1F,IAAI,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,MAAM,EAAE;YACvB,IAAI,CAAC,OAAO,CAAC,UAAU,GAAG;gBACxB,MAAM,EAAE,WAAW;aACpB,CAAC;SACH;QAED,MAAM,cAAc,GAAG;YACrB,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI;YACvB,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK;YACzB,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU;SACpC,CAAC;QAEF,IAAI,CAAC,UAAU,IAAI,MAAM,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,SAAS,CAAC,cAAc,EAAE,WAAW,CAAC,EAAE;YAClG,cAAc,CAAC,KAAK,CAAC,8DAA8D,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YAEnG,OAAO;SACR;QAED,WAAW,GAAG,cAAc,CAAC;QAE7B,cAAc,CAAC,KAAK,CAAC,qBAAqB,EAAE,IAAI,CAAC,CAAC;QAElD,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC,CAAC;IAEF,sBAAsB,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;IAE/C,OAAO;QACL,sBAAsB;QACtB,mBAAmB;QACnB,SAAS;KACV,CAAC;AACJ,CAAC","sourcesContent":["import type { Config } from '../../config';\nimport type { InternalLogger } from '../../internalLogger';\nimport type { Metas } from '../../metas';\nimport { TransportItemType } from '../../transports';\nimport type { TransportItem, Transports } from '../../transports';\nimport type { UnpatchedConsole } from '../../unpatchedConsole';\nimport { deepEqual, getCurrentTimestamp, isNull } from '../../utils';\nimport type { TracesAPI } from '../traces';\n\nimport { defaultExceptionType } from './const';\nimport type { ExceptionEvent, ExceptionsAPI, StacktraceParser } from './types';\n\nlet stacktraceParser: StacktraceParser | undefined;\n\nexport function initializeExceptionsAPI(\n _unpatchedConsole: UnpatchedConsole,\n internalLogger: InternalLogger,\n config: Config,\n metas: Metas,\n transports: Transports,\n tracesApi: TracesAPI\n): ExceptionsAPI {\n internalLogger.debug('Initializing exceptions API');\n\n let lastPayload: Pick<ExceptionEvent, 'type' | 'value' | 'stacktrace'> | null = null;\n\n stacktraceParser = config.parseStacktrace ?? stacktraceParser;\n\n const changeStacktraceParser: ExceptionsAPI['changeStacktraceParser'] = (newStacktraceParser) => {\n internalLogger.debug('Changing stacktrace parser');\n\n stacktraceParser = newStacktraceParser ?? stacktraceParser;\n };\n\n const getStacktraceParser: ExceptionsAPI['getStacktraceParser'] = () => stacktraceParser;\n\n const pushError: ExceptionsAPI['pushError'] = (error, { skipDedupe, stackFrames, type } = {}) => {\n type = type || error.name || defaultExceptionType;\n\n const item: TransportItem<ExceptionEvent> = {\n meta: metas.value,\n payload: {\n type,\n value: error.message,\n timestamp: getCurrentTimestamp(),\n trace: tracesApi.getTraceContext(),\n },\n type: TransportItemType.EXCEPTION,\n };\n\n stackFrames = stackFrames ?? (error.stack ? stacktraceParser?.(error).frames : undefined);\n\n if (stackFrames?.length) {\n item.payload.stacktrace = {\n frames: stackFrames,\n };\n }\n\n const testingPayload = {\n type: item.payload.type,\n value: item.payload.value,\n stackTrace: item.payload.stacktrace,\n };\n\n if (!skipDedupe && config.dedupe && !isNull(lastPayload) && deepEqual(testingPayload, lastPayload)) {\n internalLogger.debug('Skipping error push because it is the same as the last one\\n', item.payload);\n\n return;\n }\n\n lastPayload = testingPayload;\n\n internalLogger.debug('Pushing exception\\n', item);\n\n transports.execute(item);\n };\n\n changeStacktraceParser(config.parseStacktrace);\n\n return {\n changeStacktraceParser,\n getStacktraceParser,\n pushError,\n };\n}\n"]}
1
+ {"version":3,"file":"initialize.js","sourceR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AAO,GAAI,EAAE;aACvB;YACD,IAAI,EAAE,iBAAiB,CAAC,SAAS;SAClC,CAAC;QAEF,WAAW,GAAG,WAAW,aAAX,WAAW,cAAX,WAAW,GAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAG,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAE1F,IAAI,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,MAAM,EAAE;YACvB,IAAI,CAAC,OAAO,CAAC,UAAU,GAAG;gBACxB,MAAM,EAAE,WAAW;aACpB,CAAC;SACH;QAED,MAAM,cAAc,GAAG;YACrB,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI;YACvB,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,KAAK;YACzB,UAAU,EAAE,IAAI,CAAC,OAAO,CAAC,UAAU;YACnC,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,OAAO;SAC9B,CAAC;QAEF,IAAI,CAAC,UAAU,IAAI,MAAM,CAAC,MAAM,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,IAAI,SAAS,CAAC,cAAc,EAAE,WAAW,CAAC,EAAE;YAClG,cAAc,CAAC,KAAK,CAAC,8DAA8D,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;YAEnG,OAAO;SACR;QAED,WAAW,GAAG,cAAc,CAAC;QAE7B,cAAc,CAAC,KAAK,CAAC,qBAAqB,EAAE,IAAI,CAAC,CAAC;QAElD,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC,CAAC;IAEF,sBAAsB,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;IAE/C,OAAO;QACL,sBAAsB;QACtB,mBAAmB;QACnB,SAAS;KACV,CAAC;AACJ,CAAC","sourcesContent":["import type { Config } from '../../config';\nimport type { InternalLogger } from '../../internalLogger';\nimport type { Metas } from '../../metas';\nimport { TransportItemType } from '../../transports';\nimport type { TransportItem, Transports } from '../../transports';\nimport type { UnpatchedConsole } from '../../unpatchedConsole';\nimport { deepEqual, getCurrentTimestamp, isNull } from '../../utils';\nimport type { TracesAPI } from '../traces';\n\nimport { defaultExceptionType } from './const';\nimport type { ExceptionEvent, ExceptionsAPI, StacktraceParser } from './types';\n\nlet stacktraceParser: StacktraceParser | undefined;\n\nexport function initializeExceptionsAPI(\n _unpatchedConsole: UnpatchedConsole,\n internalLogger: InternalLogger,\n config: Config,\n metas: Metas,\n transports: Transports,\n tracesApi: TracesAPI\n): ExceptionsAPI {\n internalLogger.debug('Initializing exceptions API');\n\n let lastPayload: Pick<ExceptionEvent, 'type' | 'value' | 'stacktrace'> | null = null;\n\n stacktraceParser = config.parseStacktrace ?? stacktraceParser;\n\n const changeStacktraceParser: ExceptionsAPI['changeStacktraceParser'] = (newStacktraceParser) => {\n internalLogger.debug('Changing stacktrace parser');\n\n stacktraceParser = newStacktraceParser ?? stacktraceParser;\n };\n\n const getStacktraceParser: ExceptionsAPI['getStacktraceParser'] = () => stacktraceParser;\n\n const pushError: ExceptionsAPI['pushError'] = (error, { skipDedupe, stackFrames, type, context } = {}) => {\n type = type || error.name || defaultExceptionType;\n\n const item: TransportItem<ExceptionEvent> = {\n meta: metas.value,\n payload: {\n type,\n value: error.message,\n timestamp: getCurrentTimestamp(),\n trace: tracesApi.getTraceContext(),\n context: context ?? {},\n },\n type: TransportItemType.EXCEPTION,\n };\n\n stackFrames = stackFrames ?? (error.stack ? stacktraceParser?.(error).frames : undefined);\n\n if (stackFrames?.length) {\n item.payload.stacktrace = {\n frames: stackFrames,\n };\n }\n\n const testingPayload = {\n type: item.payload.type,\n value: item.payload.value,\n stackTrace: item.payload.stacktrace,\n context: item.payload.context,\n };\n\n if (!skipDedupe && config.dedupe && !isNull(lastPayload) && deepEqual(testingPayload, lastPayload)) {\n internalLogger.debug('Skipping error push because it is the same as the last one\\n', item.payload);\n\n return;\n }\n\n lastPayload = testingPayload;\n\n internalLogger.debug('Pushing exception\\n', item);\n\n transports.execute(item);\n };\n\n changeStacktraceParser(config.parseStacktrace);\n\n return {\n changeStacktraceParser,\n getStacktraceParser,\n pushError,\n };\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/api/exceptions/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { TraceContext } from '../traces';\n\nexport type StacktraceParser = (err: ExtendedError) => Stacktrace;\n\nexport interface ExceptionStackFrame {\n filename: string;\n function: string;\n\n colno?: number;\n lineno?: number;\n}\n\nexport interface ExtendedError extends Error {\n columnNumber?: number;\n stacktrace?: Error['stack'];\n}\n\nexport interface Stacktrace {\n frames: ExceptionStackFrame[];\n}\n\nexport interface ExceptionEvent {\n timestamp: string;\n type: string;\n value: string;\n\n stacktrace?: Stacktrace;\n trace?: TraceContext;\n}\n\nexport interface PushErrorOptions {\n skipDedupe?: boolean;\n stackFrames?: ExceptionStackFrame[];\n type?: string;\n}\n\nexport interface ExceptionsAPI {\n changeStacktraceParser: (stacktraceParser: StacktraceParser) => void;\n getStacktraceParser: () => StacktraceParser | undefined;\n pushError: (value: Error, options?: PushErrorOptions) => void;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/api/exceptions/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { TraceContext } from '../traces';\n\nexport type StacktraceParser = (err: ExtendedError) => Stacktrace;\n\nexport interface ExceptionStackFrame {\n filename: string;\n function: string;\n\n colno?: number;\n lineno?: number;\n}\n\nexport interface ExtendedError extends Error {\n columnNumber?: number;\n stacktrace?: Error['stack'];\n}\n\nexport interface Stacktrace {\n frames: ExceptionStackFrame[];\n}\n\nexport type ExceptionContext = Record<string, string>;\n\nexport interface ExceptionEvent {\n timestamp: string;\n type: string;\n value: string;\n\n stacktrace?: Stacktrace;\n trace?: TraceContext;\n context?: ExceptionContext;\n}\n\nexport interface PushErrorOptions {\n skipDedupe?: boolean;\n stackFrames?: ExceptionStackFrame[];\n type?: string;\n context?: ExceptionContext;\n}\n\nexport interface ExceptionsAPI {\n changeStacktraceParser: (stacktraceParser: StacktraceParser) => void;\n getStacktraceParser: () => StacktraceParser | undefined;\n pushError: (value: Error, options?: PushErrorOptions) => void;\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/api/logs/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { BaseObject, LogLevel } from '../../utils';\nimport type { TraceContext } from '../traces';\n\nexport type LogContext = BaseObject;\n\nexport interface LogEvent {\n context: LogContext;\n level: LogLevel;\n message: string;\n timestamp: string;\n\n trace?: TraceContext;\n}\n\nexport interface PushLogOptions {\n context?: LogContext;\n level?: LogLevel;\n skipDedupe?: boolean;\n}\n\nexport interface LogsAPI {\n pushLog: (args: unknown[], options?: PushLogOptions) => void;\n}\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/api/logs/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { LogLevel } from '../../utils';\nimport type { TraceContext } from '../traces';\n\nexport type LogContext = Record<string, string>;\n\nexport interface LogEvent {\n context: LogContext;\n level: LogLevel;\n message: string;\n timestamp: string;\n\n trace?: TraceContext;\n}\n\nexport interface PushLogOptions {\n context?: LogContext;\n level?: LogLevel;\n skipDedupe?: boolean;\n}\n\nexport interface LogsAPI {\n pushLog: (args: unknown[], options?: PushLogOptions) => void;\n}\n"]}
@@ -1,2 +1,7 @@
1
1
  export const defaultGlobalObjectKey = 'faro';
2
+ export const defaultBatchingConfig = {
3
+ enabled: true,
4
+ sendTimeout: 250,
5
+ itemLimit: 50,
6
+ };
2
7
  //# sourceMappingURL=const.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"const.js","sourceRoot":"","sources":["../../../src/config/const.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC","sourcesContent":["export const defaultGlobalObjectKey = 'faro';\n"]}
1
+ {"version":3,"file":"const.js","sourceRoot":"","sources":["../../../src/config/const.ts"],"names":[],"mappings":"AAAA,MAAM,CAAC,MAAM,sBAAsB,GAAG,MAAM,CAAC;AAE7C,MAAM,CAAC,MAAM,qBAAqB,GAAG;IACnC,OAAO,EAAE,IAAI;IACb,WAAW,EAAE,GAAG;IAChB,SAAS,EAAE,EAAE;CACd,CAAC","sourcesContent":["export const defaultGlobalObjectKey = 'faro';\n\nexport const defaultBatchingConfig = {\n enabled: true,\n sendTimeout: 250,\n itemLimit: 50,\n};\n"]}
@@ -1,2 +1,2 @@
1
- export { defaultGlobalObjectKey } from './const';
1
+ export { defaultBatchingConfig, defaultGlobalObjectKey } from './const';
2
2
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC","sourcesContent":["export { defaultGlobalObjectKey } from './const';\n\nexport type { Config, Patterns } from './types';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/config/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC","sourcesContent":["export { defaultBatchingConfig, defaultGlobalObjectKey } from './const';\n\nexport type { Config, Patterns } from './types';\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/config/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { APIEvent, StacktraceParser } from '../api';\nimport type { Instrumentation } from '../instrumentations';\nimport type { InternalLoggerLevel } from '../internalLogger';\nimport type { MetaApp, MetaItem, MetaSession, MetaUser, MetaView } from '../metas';\nimport type { BeforeSendHook, Transport } from '../transports';\nimport type { UnpatchedConsole } from '../unpatchedConsole';\n\nexport interface Config<P = APIEvent> {\n app: MetaApp;\n dedupe: boolean;\n globalObjectKey: string;\n isolate: boolean;\n instrumentations: Instrumentation[];\n internalLoggerLevel: InternalLoggerLevel;\n metas: MetaItem[];\n parseStacktrace: StacktraceParser;\n paused: boolean;\n preventGlobalExposure: boolean;\n transports: Transport[];\n unpatchedConsole: UnpatchedConsole;\n\n beforeSend?: BeforeSendHook<P>;\n ignoreErrors?: Patterns;\n session?: MetaSession;\n user?: MetaUser;\n view?: MetaView;\n eventDomain?: string;\n}\n\nexport type Patterns = Array<string | RegExp>;\n"]}
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/config/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { APIEvent, StacktraceParser } from '../api';\nimport type { Instrumentation } from '../instrumentations';\nimport type { InternalLoggerLevel } from '../internalLogger';\nimport type { MetaApp, MetaItem, MetaSession, MetaUser, MetaView } from '../metas';\nimport type { BatchExecutorOptions, BeforeSendHook, Transport } from '../transports';\nimport type { UnpatchedConsole } from '../unpatchedConsole';\n\nexport interface Config<P = APIEvent> {\n app: MetaApp;\n batching?: BatchExecutorOptions;\n dedupe: boolean;\n globalObjectKey: string;\n instrumentations: Instrumentation[];\n internalLoggerLevel: InternalLoggerLevel;\n isolate: boolean;\n metas: MetaItem[];\n parseStacktrace: StacktraceParser;\n paused: boolean;\n preventGlobalExposure: boolean;\n transports: Transport[];\n unpatchedConsole: UnpatchedConsole;\n\n beforeSend?: BeforeSendHook<P>;\n ignoreErrors?: Patterns;\n session?: MetaSession;\n user?: MetaUser;\n view?: MetaView;\n eventDomain?: string;\n}\n\nexport type Patterns = Array<string | RegExp>;\n"]}
@@ -1,3 +1,9 @@
1
1
  // This does not uses isUndefined method because it will throw an error in non-browser environments
2
- export const globalObject = (typeof window === 'undefined' ? global : window);
2
+ export const globalObject = (typeof globalThis !== 'undefined'
3
+ ? globalThis
4
+ : typeof global !== 'undefined'
5
+ ? global
6
+ : typeof self !== 'undefined'
7
+ ? self
8
+ : undefined);
3
9
  //# sourceMappingURL=globalObject.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"globalObject.js","sourceRoot":"","sources":["../../../src/globalObject/globalObject.ts"],"names":[],"mappings":"AAQA,mGAAmG;AACnG,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAiB,CAAC","sourcesContent":["import type { Faro, internalGlobalObjectKey } from '../sdk';\n\nexport type GlobalObject<T = typeof window | typeof global> = T & {\n [label: string]: Faro;\n\n [internalGlobalObjectKey]: Faro;\n};\n\n// This does not uses isUndefined method because it will throw an error in non-browser environments\nexport const globalObject = (typeof window === 'undefined' ? global : window) as GlobalObject;\n"]}
1
+ {"version":3,"file":"globalObject.js","sourceRoot":"","sources":["../../../src/globalObject/globalObject.ts"],"names":[],"mappings":"AAQA,mGAAmG;AACnG,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,OAAO,UAAU,KAAK,WAAW;IAC5D,CAAC,CAAC,UAAU;IACZ,CAAC,CAAC,OAAO,MAAM,KAAK,WAAW;QAC/B,CAAC,CAAC,MAAM;QACR,CAAC,CAAC,OAAO,IAAI,KAAK,WAAW;YAC7B,CAAC,CAAC,IAAI;YACN,CAAC,CAAC,SAAS,CAA4B,CAAC","sourcesContent":["import type { Faro, internalGlobalObjectKey } from '../sdk';\n\nexport type GlobalObject<T = typeof globalThis | typeof global | typeof self> = T & {\n [label: string]: Faro;\n\n [internalGlobalObjectKey]: Faro;\n};\n\n// This does not uses isUndefined method because it will throw an error in non-browser environments\nexport const globalObject = (typeof globalThis !== 'undefined'\n ? globalThis\n : typeof global !== 'undefined'\n ? global\n : typeof self !== 'undefined'\n ? self\n : undefined) as unknown as GlobalObject;\n"]}
package/dist/esm/index.js CHANGED
@@ -2,7 +2,7 @@ export { defaultExceptionType } from './api';
2
2
  export { BaseExtension } from './extensions';
3
3
  export { globalObject } from './globalObject';
4
4
  export { initializeFaro } from './initialize';
5
- export { defaultGlobalObjectKey } from './config';
5
+ export { defaultBatchingConfig, defaultGlobalObjectKey } from './config';
6
6
  export { BaseInstrumentation } from './instrumentations';
7
7
  export { createInternalLogger, defaultInternalLoggerLevel, InternalLoggerLevel } from './internalLogger';
8
8
  export { faro, getInternalFaroFromGlobalObject, internalGlobalObjectKey, isInternalFaroOnGlobalObject, setInternalFaroOnGlobalObject, } from './sdk';
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AA4B7C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG7C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAGlD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAGzD,OAAO,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAmBzG,OAAO,EACL,IAAI,EACJ,+BAA+B,EAC/B,uBAAuB,EACvB,4BAA4B,EAC5B,6BAA6B,GAC9B,MAAM,OAAO,CAAC;AAGf,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAU9G,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAG7D,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,SAAS,EACT,eAAe,EACf,UAAU,EACV,mBAAmB,EACnB,OAAO,EACP,SAAS,EACT,UAAU,EACV,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,OAAO,EACP,cAAc,EACd,YAAY,EACZ,OAAO,EACP,cAAc,EACd,UAAU,EACV,YAAY,EACZ,KAAK,EACL,KAAK,EACL,YAAY,EACZ,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,gBAAgB,EAChB,UAAU,EACV,UAAU,EACV,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,IAAI,GACL,MAAM,SAAS,CAAC;AAYjB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC","sourcesContent":["export { defaultExceptionType } from './api';\nexport type {\n API,\n APIEvent,\n EventAttributes,\n EventEvent,\n EventsAPI,\n ExceptionEvent,\n ExceptionStackFrame,\n ExceptionsAPI,\n ExtendedError,\n LogContext,\n LogEvent,\n LogsAPI,\n MeasurementEvent,\n MeasurementsAPI,\n MetaAPI,\n OTELApi,\n PushErrorOptions,\n PushLogOptions,\n PushMeasurementOptions,\n Stacktrace,\n StacktraceParser,\n TraceContext,\n TraceEvent,\n TracesAPI,\n} from './api';\n\nexport { BaseExtension } from './extensions';\nexport type { Extension } from './extensions';\n\nexport { globalObject } from './globalObject';\nexport type { GlobalObject } from './globalObject';\n\nexport { initializeFaro } from './initialize';\n\nexport { defaultGlobalObjectKey } from './config';\nexport type { Config, Patterns } from './config';\n\nexport { BaseInstrumentation } from './instrumentations';\nexport type { Instrumentation, Instrumentations } from './instrumentations';\n\nexport { createInternalLogger, defaultInternalLoggerLevel, InternalLoggerLevel } from './internalLogger';\nexport type { InternalLogger } from './internalLogger';\n\nexport type {\n Meta,\n MetaApp,\n MetaAttributes,\n MetaBrowser,\n MetaGetter,\n MetaItem,\n MetaPage,\n Metas,\n MetaSDK,\n MetaSDKIntegration,\n MetaSession,\n MetaUser,\n MetaView,\n} from './metas';\n\nexport {\n faro,\n getInternalFaroFromGlobalObject,\n internalGlobalObjectKey,\n isInternalFaroOnGlobalObject,\n setInternalFaroOnGlobalObject,\n} from './sdk';\nexport type { Faro } from './sdk';\n\nexport { Conventions } from './semantic';\n\nexport { BaseTransport, getTransportBody, TransportItemType, transportItemTypeToBodyKey } from './transports';\nexport type {\n BeforeSendHook,\n Transport,\n TransportBody,\n TransportItem,\n TransportItemPayload,\n Transports,\n} from './transports';\n\nexport { defaultUnpatchedConsole } from './unpatchedConsole';\nexport type { UnpatchedConsole } from './unpatchedConsole';\n\nexport {\n allLogLevels,\n createPromiseBuffer,\n deepEqual,\n defaultLogLevel,\n genShortID,\n getCurrentTimestamp,\n isArray,\n isBoolean,\n isDomError,\n isDomException,\n isElement,\n isElementDefined,\n isError,\n isErrorDefined,\n isErrorEvent,\n isEvent,\n isEventDefined,\n isFunction,\n isInstanceOf,\n isInt,\n isMap,\n isMapDefined,\n isNull,\n isNumber,\n isObject,\n isPrimitive,\n isRegExp,\n isString,\n isSymbol,\n isSyntheticEvent,\n isThenable,\n isToString,\n isTypeof,\n isUndefined,\n LogLevel,\n noop,\n} from './utils';\nexport type {\n BaseObject,\n BaseObjectKey,\n BaseObjectPrimitiveValue,\n BaseObjectValue,\n BufferItem,\n PromiseBuffer,\n PromiseBufferOptions,\n PromiseProducer,\n} from './utils';\n\nexport { VERSION } from './version';\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AA4B7C,OAAO,EAAE,aAAa,EAAE,MAAM,cAAc,CAAC;AAG7C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAG9C,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,OAAO,EAAE,qBAAqB,EAAE,sBAAsB,EAAE,MAAM,UAAU,CAAC;AAGzE,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAGzD,OAAO,EAAE,oBAAoB,EAAE,0BAA0B,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAmBzG,OAAO,EACL,IAAI,EACJ,+BAA+B,EAC/B,uBAAuB,EACvB,4BAA4B,EAC5B,6BAA6B,GAC9B,MAAM,OAAO,CAAC;AAGf,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,OAAO,EAAE,aAAa,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAC;AAW9G,OAAO,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAG7D,OAAO,EACL,YAAY,EACZ,mBAAmB,EACnB,SAAS,EACT,eAAe,EACf,UAAU,EACV,mBAAmB,EACnB,OAAO,EACP,SAAS,EACT,UAAU,EACV,cAAc,EACd,SAAS,EACT,gBAAgB,EAChB,OAAO,EACP,cAAc,EACd,YAAY,EACZ,OAAO,EACP,cAAc,EACd,UAAU,EACV,YAAY,EACZ,KAAK,EACL,KAAK,EACL,YAAY,EACZ,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,QAAQ,EACR,gBAAgB,EAChB,UAAU,EACV,UAAU,EACV,QAAQ,EACR,WAAW,EACX,QAAQ,EACR,IAAI,GACL,MAAM,SAAS,CAAC;AAYjB,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC","sourcesContent":["export { defaultExceptionType } from './api';\nexport type {\n API,\n APIEvent,\n EventAttributes,\n EventEvent,\n EventsAPI,\n ExceptionEvent,\n ExceptionStackFrame,\n ExceptionsAPI,\n ExtendedError,\n LogContext,\n LogEvent,\n LogsAPI,\n MeasurementEvent,\n MeasurementsAPI,\n MetaAPI,\n OTELApi,\n PushErrorOptions,\n PushLogOptions,\n PushMeasurementOptions,\n Stacktrace,\n StacktraceParser,\n TraceContext,\n TraceEvent,\n TracesAPI,\n} from './api';\n\nexport { BaseExtension } from './extensions';\nexport type { Extension } from './extensions';\n\nexport { globalObject } from './globalObject';\nexport type { GlobalObject } from './globalObject';\n\nexport { initializeFaro } from './initialize';\n\nexport { defaultBatchingConfig, defaultGlobalObjectKey } from './config';\nexport type { Config, Patterns } from './config';\n\nexport { BaseInstrumentation } from './instrumentations';\nexport type { Instrumentation, Instrumentations } from './instrumentations';\n\nexport { createInternalLogger, defaultInternalLoggerLevel, InternalLoggerLevel } from './internalLogger';\nexport type { InternalLogger } from './internalLogger';\n\nexport type {\n Meta,\n MetaApp,\n MetaAttributes,\n MetaBrowser,\n MetaGetter,\n MetaItem,\n MetaPage,\n Metas,\n MetaSDK,\n MetaSDKIntegration,\n MetaSession,\n MetaUser,\n MetaView,\n} from './metas';\n\nexport {\n faro,\n getInternalFaroFromGlobalObject,\n internalGlobalObjectKey,\n isInternalFaroOnGlobalObject,\n setInternalFaroOnGlobalObject,\n} from './sdk';\nexport type { Faro } from './sdk';\n\nexport { Conventions } from './semantic';\n\nexport { BaseTransport, getTransportBody, TransportItemType, transportItemTypeToBodyKey } from './transports';\nexport type {\n BeforeSendHook,\n SendFn,\n Transport,\n TransportBody,\n TransportItem,\n TransportItemPayload,\n Transports,\n} from './transports';\n\nexport { defaultUnpatchedConsole } from './unpatchedConsole';\nexport type { UnpatchedConsole } from './unpatchedConsole';\n\nexport {\n allLogLevels,\n createPromiseBuffer,\n deepEqual,\n defaultLogLevel,\n genShortID,\n getCurrentTimestamp,\n isArray,\n isBoolean,\n isDomError,\n isDomException,\n isElement,\n isElementDefined,\n isError,\n isErrorDefined,\n isErrorEvent,\n isEvent,\n isEventDefined,\n isFunction,\n isInstanceOf,\n isInt,\n isMap,\n isMapDefined,\n isNull,\n isNumber,\n isObject,\n isPrimitive,\n isRegExp,\n isString,\n isSymbol,\n isSyntheticEvent,\n isThenable,\n isToString,\n isTypeof,\n isUndefined,\n LogLevel,\n noop,\n} from './utils';\nexport type {\n BaseObject,\n BaseObjectKey,\n BaseObjectPrimitiveValue,\n BaseObjectValue,\n BufferItem,\n PromiseBuffer,\n PromiseBufferOptions,\n PromiseProducer,\n} from './utils';\n\nexport { VERSION } from './version';\n"]}
@@ -4,6 +4,8 @@ export function mockConfig(overrides = {}) {
4
4
  return Object.assign({ app: {
5
5
  name: 'test',
6
6
  version: '1.0.0',
7
+ }, batching: {
8
+ enabled: false,
7
9
  }, dedupe: true, globalObjectKey: 'faro', internalLoggerLevel: defaultInternalLoggerLevel, instrumentations: [], isolate: true, metas: [], parseStacktrace: mockStacktraceParser, paused: false, preventGlobalExposure: true, transports: [], unpatchedConsole: console }, overrides);
8
10
  }
9
11
  //# sourceMappingURL=mockConfig.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"mockConfig.js","sourceRoot":"","sources":["../../../src/testUtils/mockConfig.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAE/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,MAAM,UAAU,UAAU,CAAC,YAA6B,EAAE;IACxD,uBACE,GAAG,EAAE;YACH,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,OAAO;SACjB,EACD,MAAM,EAAE,IAAI,EACZ,eAAe,EAAE,MAAM,EACvB,mBAAmB,EAAE,0BAA0B,EAC/C,gBAAgB,EAAE,EAAE,EACpB,OAAO,EAAE,IAAI,EACb,KAAK,EAAE,EAAE,EACT,eAAe,EAAE,oBAAoB,EACrC,MAAM,EAAE,KAAK,EACb,qBAAqB,EAAE,IAAI,EAC3B,UAAU,EAAE,EAAE,EACd,gBAAgB,EAAE,OAAO,IACtB,SAAS,EACZ;AACJ,CAAC","sourcesContent":["import type { Config } from '../config';\nimport { defaultInternalLoggerLevel } from '../internalLogger';\n\nimport { mockStacktraceParser } from './mockStacktraceParser';\n\nexport function mockConfig(overrides: Partial<Config> = {}): Config {\n return {\n app: {\n name: 'test',\n version: '1.0.0',\n },\n dedupe: true,\n globalObjectKey: 'faro',\n internalLoggerLevel: defaultInternalLoggerLevel,\n instrumentations: [],\n isolate: true,\n metas: [],\n parseStacktrace: mockStacktraceParser,\n paused: false,\n preventGlobalExposure: true,\n transports: [],\n unpatchedConsole: console,\n ...overrides,\n };\n}\n"]}
1
+ {"version":3,"file":"mockConfig.js","sourceRoot":"","sources":["../../../src/testUtils/mockConfig.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,0BAA0B,EAAE,MAAM,mBAAmB,CAAC;AAE/D,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAE9D,MAAM,UAAU,UAAU,CAAC,YAA6B,EAAE;IACxD,uBACE,GAAG,EAAE;YACH,IAAI,EAAE,MAAM;YACZ,OAAO,EAAE,OAAO;SACjB,EACD,QAAQ,EAAE;YACR,OAAO,EAAE,KAAK;SACf,EACD,MAAM,EAAE,IAAI,EACZ,eAAe,EAAE,MAAM,EACvB,mBAAmB,EAAE,0BAA0B,EAC/C,gBAAgB,EAAE,EAAE,EACpB,OAAO,EAAE,IAAI,EACb,KAAK,EAAE,EAAE,EACT,eAAe,EAAE,oBAAoB,EACrC,MAAM,EAAE,KAAK,EACb,qBAAqB,EAAE,IAAI,EAC3B,UAAU,EAAE,EAAE,EACd,gBAAgB,EAAE,OAAO,IACtB,SAAS,EACZ;AACJ,CAAC","sourcesContent":["import type { Config } from '../config';\nimport { defaultInternalLoggerLevel } from '../internalLogger';\n\nimport { mockStacktraceParser } from './mockStacktraceParser';\n\nexport function mockConfig(overrides: Partial<Config> = {}): Config {\n return {\n app: {\n name: 'test',\n version: '1.0.0',\n },\n batching: {\n enabled: false,\n },\n dedupe: true,\n globalObjectKey: 'faro',\n internalLoggerLevel: defaultInternalLoggerLevel,\n instrumentations: [],\n isolate: true,\n metas: [],\n parseStacktrace: mockStacktraceParser,\n paused: false,\n preventGlobalExposure: true,\n transports: [],\n unpatchedConsole: console,\n ...overrides,\n };\n}\n"]}
@@ -1,5 +1,4 @@
1
1
  import { BaseTransport } from '../transports';
2
- import { isArray } from '../utils';
3
2
  import { VERSION } from '../version';
4
3
  export class MockTransport extends BaseTransport {
5
4
  constructor(ignoreURLs = []) {
@@ -9,10 +8,12 @@ export class MockTransport extends BaseTransport {
9
8
  this.version = VERSION;
10
9
  this.items = [];
11
10
  }
12
- send(item) {
13
- const items = isArray(item) ? item : [item];
11
+ send(items) {
14
12
  this.items.push(...items);
15
13
  }
14
+ isBatched() {
15
+ return true;
16
+ }
16
17
  getIgnoreUrls() {
17
18
  return this.ignoreURLs;
18
19
  }
@@ -1 +1 @@
1
- {"version":3,"file":"mockTransport.js","sourceRoot":"","sources":["../../../src/testUtils/mockTransport.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,MAAM,OAAO,aAAc,SAAQ,aAAa;IAM9C,YAAoB,aAAuB,EAAE;QAC3C,KAAK,EAAE,CAAC;QADU,eAAU,GAAV,UAAU,CAAe;QALpC,SAAI,GAAG,yBAAyB,CAAC;QACjC,YAAO,GAAG,OAAO,CAAC;QAE3B,UAAK,GAAoB,EAAE,CAAC;IAI5B,CAAC;IAED,IAAI,CAAC,IAAqC;QACxC,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAC5C,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC;IAC5B,CAAC;IAEQ,aAAa;QACpB,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;CACF","sourcesContent":["import type { Patterns } from '../config';\nimport { BaseTransport } from '../transports';\nimport type { Transport, TransportItem } from '../transports';\nimport { isArray } from '../utils';\nimport { VERSION } from '../version';\n\nexport class MockTransport extends BaseTransport implements Transport {\n readonly name = '@grafana/transport-mock';\n readonly version = VERSION;\n\n items: TransportItem[] = [];\n\n constructor(private ignoreURLs: Patterns = []) {\n super();\n }\n\n send(item: TransportItem | TransportItem[]): void | Promise<void> {\n const items = isArray(item) ? item : [item];\n this.items.push(...items);\n }\n\n override getIgnoreUrls(): Patterns {\n return this.ignoreURLs;\n }\n}\n"]}
1
+ {"version":3,"file":"mockTransport.js","sourceRoot":"","sources":["../../../src/testUtils/mockTransport.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,MAAM,OAAO,aAAc,SAAQ,aAAa;IAM9C,YAAoB,aAAuB,EAAE;QAC3C,KAAK,EAAE,CAAC;QADU,eAAU,GAAV,UAAU,CAAe;QALpC,SAAI,GAAG,yBAAyB,CAAC;QACjC,YAAO,GAAG,OAAO,CAAC;QAE3B,UAAK,GAAoB,EAAE,CAAC;IAI5B,CAAC;IAED,IAAI,CAAC,KAAsB;QACzB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC;IAC5B,CAAC;IAEQ,SAAS;QAChB,OAAO,IAAI,CAAC;IACd,CAAC;IAEQ,aAAa;QACpB,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;CACF","sourcesContent":["import type { Patterns } from '../config';\nimport { BaseTransport } from '../transports';\nimport type { Transport, TransportItem } from '../transports';\nimport { VERSION } from '../version';\n\nexport class MockTransport extends BaseTransport implements Transport {\n readonly name = '@grafana/transport-mock';\n readonly version = VERSION;\n\n items: TransportItem[] = [];\n\n constructor(private ignoreURLs: Patterns = []) {\n super();\n }\n\n send(items: TransportItem[]): void | Promise<void> {\n this.items.push(...items);\n }\n\n override isBatched(): boolean {\n return true;\n }\n\n override getIgnoreUrls(): Patterns {\n return this.ignoreURLs;\n }\n}\n"]}
@@ -1,5 +1,8 @@
1
1
  import { BaseExtension } from '../extensions';
2
2
  export class BaseTransport extends BaseExtension {
3
+ isBatched() {
4
+ return false;
5
+ }
3
6
  getIgnoreUrls() {
4
7
  return [];
5
8
  }
@@ -1 +1 @@
1
- {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/transports/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAI9C,MAAM,OAAgB,aAAc,SAAQ,aAAa;IAGvD,aAAa;QACX,OAAO,EAAE,CAAC;IACZ,CAAC;CACF","sourcesContent":["import { BaseExtension } from '../extensions';\n\nimport type { Transport, TransportItem } from './types';\n\nexport abstract class BaseTransport extends BaseExtension implements Transport {\n abstract send(item: TransportItem | TransportItem[]): void | Promise<void>;\n\n getIgnoreUrls(): Array<string | RegExp> {\n return [];\n }\n}\n"]}
1
+ {"version":3,"file":"base.js","sourceRoot":"","sources":["../../../src/transports/base.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAI9C,MAAM,OAAgB,aAAc,SAAQ,aAAa;IAGvD,SAAS;QACP,OAAO,KAAK,CAAC;IACf,CAAC;IAED,aAAa;QACX,OAAO,EAAE,CAAC;IACZ,CAAC;CACF","sourcesContent":["import { BaseExtension } from '../extensions';\n\nimport type { Transport, TransportItem } from './types';\n\nexport abstract class BaseTransport extends BaseExtension implements Transport {\n abstract send(items: TransportItem | TransportItem[]): void | Promise<void>;\n\n isBatched(): boolean {\n return false;\n }\n\n getIgnoreUrls(): Array<string | RegExp> {\n return [];\n }\n}\n"]}
@@ -0,0 +1,67 @@
1
+ import { murmur3 } from 'murmurhash-js';
2
+ const DEFAULT_SEND_TIMEOUT_MS = 250;
3
+ const DEFAULT_BATCH_ITEM_LIMIT = 50;
4
+ export class BatchExecutor {
5
+ constructor(sendFn, options) {
6
+ var _a, _b;
7
+ this.signalBuffer = [];
8
+ this.itemLimit = (_a = options === null || options === void 0 ? void 0 : options.itemLimit) !== null && _a !== void 0 ? _a : DEFAULT_BATCH_ITEM_LIMIT;
9
+ this.sendTimeout = (_b = options === null || options === void 0 ? void 0 : options.sendTimeout) !== null && _b !== void 0 ? _b : DEFAULT_SEND_TIMEOUT_MS;
10
+ this.paused = (options === null || options === void 0 ? void 0 : options.paused) || false;
11
+ this.sendFn = sendFn;
12
+ this.flushInterval = -1;
13
+ if (!this.paused) {
14
+ this.start();
15
+ }
16
+ // Send batched/buffered data when user navigates to new page, switches or closes the tab, minimizes or closes the browser.
17
+ // If on mobile, it also sends data if user switches from the browser to a different app.
18
+ document.addEventListener('visibilitychange', () => {
19
+ if (document.visibilityState === 'hidden') {
20
+ this.flush();
21
+ }
22
+ });
23
+ }
24
+ addItem(item) {
25
+ if (this.paused) {
26
+ return;
27
+ }
28
+ this.signalBuffer.push(item);
29
+ if (this.signalBuffer.length >= this.itemLimit) {
30
+ this.flush();
31
+ }
32
+ }
33
+ start() {
34
+ this.paused = false;
35
+ if (this.sendTimeout > 0) {
36
+ this.flushInterval = window.setInterval(() => this.flush(), this.sendTimeout);
37
+ }
38
+ }
39
+ pause() {
40
+ this.paused = true;
41
+ clearInterval(this.flushInterval);
42
+ }
43
+ groupItems(items) {
44
+ const itemMap = new Map();
45
+ items.forEach((item) => {
46
+ const metaKey = murmur3(JSON.stringify(item.meta));
47
+ let currentItems = itemMap.get(metaKey);
48
+ if (currentItems === undefined) {
49
+ currentItems = [item];
50
+ }
51
+ else {
52
+ currentItems = [...currentItems, item];
53
+ }
54
+ itemMap.set(metaKey, currentItems);
55
+ });
56
+ return Array.from(itemMap.values());
57
+ }
58
+ flush() {
59
+ if (this.paused || this.signalBuffer.length === 0) {
60
+ return;
61
+ }
62
+ const itemGroups = this.groupItems(this.signalBuffer);
63
+ itemGroups.forEach(this.sendFn);
64
+ this.signalBuffer = [];
65
+ }
66
+ }
67
+ //# sourceMappingURL=batchExecutor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"batchExecutor.js","sourceRoot":"","sources":["../../../src/transports/batchExecutor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AAMxC,MAAM,uBAAuB,GAAG,GAAG,CAAC;AACpC,MAAM,wBAAwB,GAAG,EAAE,CAAC;AAEpC,MAAM,OAAO,aAAa;IASxB,YAAY,MAAc,EAAE,OAA8B;;QALlD,iB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AK;QACH,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;QACnB,aAAa,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IACpC,CAAC;IAED,UAAU,CAAC,KAAsB;QAC/B,MAAM,OAAO,GAAG,IAAI,GAAG,EAA2B,CAAC;QACnD,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACrB,MAAM,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;YAEnD,IAAI,YAAY,GAAG,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACxC,IAAI,YAAY,KAAK,SAAS,EAAE;gBAC9B,YAAY,GAAG,CAAC,IAAI,CAAC,CAAC;aACvB;iBAAM;gBACL,YAAY,GAAG,CAAC,GAAG,YAAY,EAAE,IAAI,CAAC,CAAC;aACxC;YAED,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;QACrC,CAAC,CAAC,CAAC;QACH,OAAO,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IACtC,CAAC;IAEO,KAAK;QACX,IAAI,IAAI,CAAC,MAAM,IAAI,IAAI,CAAC,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE;YACjD,OAAO;SACR;QAED,MAAM,UAAU,GAAG,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;QACtD,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;QAChC,IAAI,CAAC,YAAY,GAAG,EAAE,CAAC;IACzB,CAAC;CACF","sourcesContent":["import { murmur3 } from 'murmurhash-js';\n\nimport type { TransportItem } from '../';\n\nimport type { BatchExecutorOptions, SendFn } from './types';\n\nconst DEFAULT_SEND_TIMEOUT_MS = 250;\nconst DEFAULT_BATCH_ITEM_LIMIT = 50;\n\nexport class BatchExecutor {\n private readonly itemLimit: number;\n private readonly sendTimeout: number;\n\n private signalBuffer: TransportItem[] = [];\n private sendFn: SendFn;\n private paused: boolean;\n private flushInterval: number;\n\n constructor(sendFn: SendFn, options?: BatchExecutorOptions) {\n this.itemLimit = options?.itemLimit ?? DEFAULT_BATCH_ITEM_LIMIT;\n this.sendTimeout = options?.sendTimeout ?? DEFAULT_SEND_TIMEOUT_MS;\n this.paused = options?.paused || false;\n this.sendFn = sendFn;\n this.flushInterval = -1;\n\n if (!this.paused) {\n this.start();\n }\n\n // Send batched/buffered data when user navigates to new page, switches or closes the tab, minimizes or closes the browser.\n // If on mobile, it also sends data if user switches from the browser to a different app.\n document.addEventListener('visibilitychange', () => {\n if (document.visibilityState === 'hidden') {\n this.flush();\n }\n });\n }\n\n addItem(item: TransportItem): void {\n if (this.paused) {\n return;\n }\n\n this.signalBuffer.push(item);\n\n if (this.signalBuffer.length >= this.itemLimit) {\n this.flush();\n }\n }\n\n start(): void {\n this.paused = false;\n if (this.sendTimeout > 0) {\n this.flushInterval = window.setInterval(() => this.flush(), this.sendTimeout);\n }\n }\n\n pause(): void {\n this.paused = true;\n clearInterval(this.flushInterval);\n }\n\n groupItems(items: TransportItem[]): TransportItem[][] {\n const itemMap = new Map<number, TransportItem[]>();\n items.forEach((item) => {\n const metaKey = murmur3(JSON.stringify(item.meta));\n\n let currentItems = itemMap.get(metaKey);\n if (currentItems === undefined) {\n currentItems = [item];\n } else {\n currentItems = [...currentItems, item];\n }\n\n itemMap.set(metaKey, currentItems);\n });\n return Array.from(itemMap.values());\n }\n\n private flush() {\n if (this.paused || this.signalBuffer.length === 0) {\n return;\n }\n\n const itemGroups = this.groupItems(this.signalBuffer);\n itemGroups.forEach(this.sendFn);\n this.signalBuffer = [];\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"const.js","sourceRoot":"","sources":["../../../src/transports/const.ts"],"names":[],"mappings":"AAAA,MAAM,CAAN,IAAY,iBAMX;AAND,WAAY,iBAAiB;IAC3B,4CAAuB,CAAA;IACvB,gCAAW,CAAA;IACX,gDAA2B,CAAA;IAC3B,oCAAe,CAAA;IACf,oCAAe,CAAA;AACjB,CAAC,EANW,iBAAiB,KAAjB,iBAAiB,QAM5B;AAED,MAAM,CAAC,MAAM,0BAA0B,GAAsC;IAC3E,CAAC,iBAAiB,CAAC,SAAS,CAAC,EAAE,YAAY;IAC3C,CAAC,iBAAiB,CAAC,GAAG,CAAC,EAAE,MAAM;IAC/B,CAAC,iBAAiB,CAAC,WAAW,CAAC,EAAE,cAAc;IAC/C,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE,QAAQ;IACnC,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE,QAAQ;CAC3B,CAAC","sourcesContent":["export enum TransportItemType {\n EXCEPTION = 'exception',\n LOG = 'log',\n MEASUREMENT = 'measurement',\n TRACE = 'trace',\n EVENT = 'event',\n}\n\nexport const transportItemTypeToBodyKey: Record<TransportItemType, string> = {\n [TransportItemType.EXCEPTION]: 'exceptions',\n [TransportItemType.LOG]: 'logs',\n [TransportItemType.MEASUREMENT]: 'measurements',\n [TransportItemType.TRACE]: 'traces',\n [TransportItemType.EVENT]: 'events',\n} as const;\n"]}
1
+ {"version":3,"file":"const.js","sourceRoot":"","sources":["../../../src/transports/const.ts"],"names":[],"mappings":"AAEA,MAAM,CAAN,IAAY,iBAMX;AAND,WAAY,iBAAiB;IAC3B,4CAAuB,CAAA;IACvB,gCAAW,CAAA;IACX,gDAA2B,CAAA;IAC3B,oCAAe,CAAA;IACf,oCAAe,CAAA;AACjB,CAAC,EANW,iBAAiB,KAAjB,iBAAiB,QAM5B;AAED,MAAM,CAAC,MAAM,0BAA0B,GAAuC;IAC5E,CAAC,iBAAiB,CAAC,SAAS,CAAC,EAAE,YAAY;IAC3C,CAAC,iBAAiB,CAAC,GAAG,CAAC,EAAE,MAAM;IAC/B,CAAC,iBAAiB,CAAC,WAAW,CAAC,EAAE,cAAc;IAC/C,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE,QAAQ;IACnC,CAAC,iBAAiB,CAAC,KAAK,CAAC,EAAE,QAAQ;CAC3B,CAAC","sourcesContent":["import type { BodyKey } from './types';\n\nexport enum TransportItemType {\n EXCEPTION = 'exception',\n LOG = 'log',\n MEASUREMENT = 'measurement',\n TRACE = 'trace',\n EVENT = 'event',\n}\n\nexport const transportItemTypeToBodyKey: Record<TransportItemType, BodyKey> = {\n [TransportItemType.EXCEPTION]: 'exceptions',\n [TransportItemType.LOG]: 'logs',\n [TransportItemType.MEASUREMENT]: 'measurements',\n [TransportItemType.TRACE]: 'traces',\n [TransportItemType.EVENT]: 'events',\n} as const;\n"]}