@coralogix/browser 2.6.0 → 2.8.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,14 @@
1
+ ## 2.8.0 (2025-05-11)
2
+
3
+ ### 🚀 Features
4
+
5
+ Build CDN versions (ES5/ES2015)
6
+
7
+ ## 2.7.0 (2025-05-05)
8
+
9
+ 🚀 Features
10
+ Add Web Worker error handling.
11
+
1
12
  ## 2.6.0 (2025-05-04)
2
13
 
3
14
  ### 🚀 Features
package/README.md CHANGED
@@ -839,6 +839,53 @@ You can also manually trigger memory usage data collection.
839
839
  CoralogixRum.measureUserAgentSpecificMemory();
840
840
  ```
841
841
 
842
+ ## Web Worker Support
843
+
844
+ Web Worker support enables the capture of events originating from Web Workers, including unhandled errors, custom logs, and other functionalities provided by the SDK.
845
+
846
+ > By default, Web Worker support is **disabled**.
847
+
848
+ ---
849
+
850
+ ### Enabling Web Worker Support
851
+
852
+ ```javascript
853
+ CoralogixRum.init({
854
+ workerSupport: true,
855
+ });
856
+ ```
857
+
858
+ ---
859
+
860
+ #### Examples
861
+
862
+ ```javascript
863
+ // App code – creating a worker. The SDK will automatically capture errors from it.
864
+
865
+ const worker = new Worker('my-worker.js');
866
+ ```
867
+
868
+ ```javascript
869
+ // Worker code
870
+
871
+ // Log a basic info log
872
+ worker.CoralogixRum.log(CoralogixLogSeverity.Info, 'Test log from worker');
873
+
874
+ // Manually capture errors
875
+ try {
876
+ // Some code that might throw an error
877
+ } catch (error) {
878
+ worker.CoralogixRum.captureError(error, { worker: 'analytics-worker' }, { label1: 'value1' });
879
+ }
880
+
881
+ // Log messages received in the worker
882
+ self.onmessage = (message) => {
883
+ worker.CoralogixRum.log(CoralogixLogSeverity.Info, message);
884
+ };
885
+ ```
886
+
887
+ ---
888
+
842
889
  ## CDN
843
890
 
844
891
  Coralogix Browser SDK is also provided via CDN.<br>
@@ -846,9 +893,17 @@ You can choose your desired version.
846
893
 
847
894
  #### Specific Version (recommended)
848
895
 
896
+ By default, the CDN is built using the <b>ES2015 (ES6)</b> standard.<br>
897
+
849
898
  https://cdn.rum-ingress-coralogix.com/coralogix/browser/[version]/coralogix-browser-sdk.js \
850
899
  Replace [version] with a version from [Releases page](https://www.npmjs.com/package/@coralogix/browser?activeTab=versions).
851
900
 
901
+ #### ES5
902
+
903
+ If you are targeting legacy environments, make sure to use the ES5-compatible version.
904
+
905
+ https://cdn.rum-ingress-coralogix.com/coralogix/browser/[version]/coralogix-browser-sdk.es5.js
906
+
852
907
  > _**Note: CDN latest has no longer maintained, please use an explicit version instead.**_
853
908
 
854
909
  ### Add the CDN script to your application
package/index.esm2.js CHANGED
@@ -381,6 +381,7 @@ var ErrorSource;
381
381
  ErrorSource["UNHANDLED_REJECTION"] = "unhandledrejection";
382
382
  ErrorSource["DOCUMENT"] = "document";
383
383
  ErrorSource["CAPTURED"] = "captured";
384
+ ErrorSource["WEB_WORKER"] = "web_worker";
384
385
  })(ErrorSource || (ErrorSource = {}));
385
386
  function buildStacktrace(span, err) {
386
387
  return __awaiter(this, void 0, void 0, function () {
@@ -1251,6 +1252,8 @@ var DOM_INSTRUMENTATION_NAME = 'dom';
1251
1252
  var DOM_INSTRUMENTATION_VERSION = '1.0.0';
1252
1253
  var CUSTOM_MEASUREMENT_INSTRUMENTATION_NAME = 'custom_measurement';
1253
1254
  var CUSTOM_MEASUREMENT_INSTRUMENTATION_VERSION = '1.0.0';
1255
+ var WORKER_INSTRUMENTATION = 'web_worker';
1256
+ var WORKER_INSTRUMENTATION_VERSION = '1.0.0';
1254
1257
  var XHR_INSTRUMENTATION_NAME = 'xhr';
1255
1258
  var FETCH_INSTRUMENTATION_NAME = 'fetch';
1256
1259
  var CUSTOM_INSTRUMENTATION_NAME = 'custom';
@@ -1533,7 +1536,7 @@ C.prototype.m = function (a) {
1533
1536
  this.f.set(a, performance.now());
1534
1537
  };
1535
1538
  C.prototype.l = function (a) {
1536
- this.f.delete(a);
1539
+ this.f["delete"](a);
1537
1540
  };
1538
1541
  C.prototype.B = function () {
1539
1542
  G(this, performance.now() + 5e3);
@@ -2429,6 +2432,76 @@ var CoralogixDOMInstrumentation = /** @class */ (function (_super) {
2429
2432
  return CoralogixDOMInstrumentation;
2430
2433
  }(InstrumentationBase));
2431
2434
 
2435
+ var ERROR_TYPES = {
2436
+ RUNTIME: 'web-worker-runtime-error',
2437
+ MESSAGE_ERROR: 'web-worker-messageerror',
2438
+ };
2439
+ var ERROR_MESSAGES = {
2440
+ UNKNOWN_RUNTIME: 'Unknown worker runtime error',
2441
+ DESERIALIZATION_FAILED: 'Failed to deserialize message from worker',
2442
+ };
2443
+ var WORKER_EVENTS = {
2444
+ ERROR: 'error',
2445
+ MESSAGE_ERROR: 'messageerror',
2446
+ };
2447
+
2448
+ var CoralogixWorkerInstrumentation = /** @class */ (function (_super) {
2449
+ __extends(CoralogixWorkerInstrumentation, _super);
2450
+ function CoralogixWorkerInstrumentation(config, errorInstrumentation, coralogixRum) {
2451
+ var _this = _super.call(this, WORKER_INSTRUMENTATION, WORKER_INSTRUMENTATION_VERSION, config) || this;
2452
+ _this.errorInstrumentation = errorInstrumentation;
2453
+ _this.coralogixRum = coralogixRum;
2454
+ _this.init();
2455
+ return _this;
2456
+ }
2457
+ CoralogixWorkerInstrumentation.prototype.disable = function () { };
2458
+ CoralogixWorkerInstrumentation.prototype.enable = function () { };
2459
+ CoralogixWorkerInstrumentation.prototype.init = function () {
2460
+ var globalObj = CxGlobal;
2461
+ var OriginalWorker = globalObj.Worker;
2462
+ globalObj.Worker = this.createCxWorker(OriginalWorker);
2463
+ };
2464
+ CoralogixWorkerInstrumentation.prototype.createCxWorker = function (OriginalWorker) {
2465
+ var self = this;
2466
+ var CxWorker = /** @class */ (function (_super) {
2467
+ __extends(CxWorker, _super);
2468
+ function CxWorker(scriptURL, options) {
2469
+ var _this = _super.call(this, scriptURL, options) || this;
2470
+ _this.CoralogixRum = self.coralogixRum;
2471
+ self.attachWorkerErrorHandlers(_this, scriptURL);
2472
+ return _this;
2473
+ }
2474
+ return CxWorker;
2475
+ }(OriginalWorker));
2476
+ return CxWorker;
2477
+ };
2478
+ CoralogixWorkerInstrumentation.prototype.attachWorkerErrorHandlers = function (worker, scriptURL) {
2479
+ var _this = this;
2480
+ var source = scriptURL.toString();
2481
+ worker.addEventListener(WORKER_EVENTS.ERROR, function (event) {
2482
+ var message = event.message || ERROR_MESSAGES.UNKNOWN_RUNTIME;
2483
+ _this.reportWorkerError(message, {
2484
+ scriptURL: source,
2485
+ filename: event.filename,
2486
+ lineno: event.lineno,
2487
+ colno: event.colno,
2488
+ originalError: event.error || null,
2489
+ }, { type: ERROR_TYPES.RUNTIME });
2490
+ });
2491
+ worker.addEventListener(WORKER_EVENTS.MESSAGE_ERROR, function (event) {
2492
+ _this.reportWorkerError(ERROR_MESSAGES.DESERIALIZATION_FAILED, {
2493
+ scriptURL: source,
2494
+ event: event,
2495
+ }, { type: ERROR_TYPES.MESSAGE_ERROR });
2496
+ });
2497
+ };
2498
+ CoralogixWorkerInstrumentation.prototype.reportWorkerError = function (message, customData, labels) {
2499
+ var _a;
2500
+ (_a = this.errorInstrumentation) === null || _a === void 0 ? void 0 : _a.reportError(ErrorSource.WEB_WORKER, new Error(message), customData, labels);
2501
+ };
2502
+ return CoralogixWorkerInstrumentation;
2503
+ }(InstrumentationBase));
2504
+
2432
2505
  var CORALOGIX_LOGS_URL_SUFFIX = '/browser/v1beta/logs';
2433
2506
  var CORALOGIX_RECORDING_URL_SUFFIX = '/sessionrecording';
2434
2507
  var MAX_EXPORT_BATCH_SIZE = 50;
@@ -2548,6 +2621,11 @@ var INSTRUMENTATIONS = [
2548
2621
  confKey: SCREENSHOT_INSTRUMENTATION_NAME,
2549
2622
  disable: false,
2550
2623
  },
2624
+ {
2625
+ Instrument: CoralogixWorkerInstrumentation,
2626
+ confKey: WORKER_INSTRUMENTATION,
2627
+ disable: false,
2628
+ },
2551
2629
  ];
2552
2630
  var CoralogixAttributes = {
2553
2631
  USER_AGENT: 'user_agent',
@@ -3199,7 +3277,7 @@ var CompositePropagator = /** @class */function () {
3199
3277
  };
3200
3278
  } finally {
3201
3279
  try {
3202
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
3280
+ if (_c && !_c.done && (_a = _b["return"])) _a.call(_b);
3203
3281
  } finally {
3204
3282
  if (e_1) throw e_1.error;
3205
3283
  }
@@ -3309,14 +3387,14 @@ var TraceState = /** @class */function () {
3309
3387
  // use the faster one.
3310
3388
  var traceState = this._clone();
3311
3389
  if (traceState._internalState.has(key)) {
3312
- traceState._internalState.delete(key);
3390
+ traceState._internalState["delete"](key);
3313
3391
  }
3314
3392
  traceState._internalState.set(key, value);
3315
3393
  return traceState;
3316
3394
  };
3317
3395
  TraceState.prototype.unset = function (key) {
3318
3396
  var traceState = this._clone();
3319
- traceState._internalState.delete(key);
3397
+ traceState._internalState["delete"](key);
3320
3398
  return traceState;
3321
3399
  };
3322
3400
  TraceState.prototype.get = function (key) {
@@ -4134,7 +4212,7 @@ function resolveUrlBlueprinters(urlBlueprinters) {
4134
4212
  return resolvedUrlBlueprinters;
4135
4213
  }
4136
4214
 
4137
- var SDK_VERSION = '2.6.0';
4215
+ var SDK_VERSION = '2.8.0';
4138
4216
 
4139
4217
  function shouldDropEvent(cxRumEvent, options) {
4140
4218
  if (isDocumentErrorWithoutMessage(cxRumEvent)) {
@@ -4621,7 +4699,7 @@ function getTiming(duration) {
4621
4699
  return getNowTime() - getSessionManager().currentPageTimestamp;
4622
4700
  }
4623
4701
 
4624
- if (supportedPerformanceTypes.has(PerformanceTypes.LongTask)) {
4702
+ if (supportedPerformanceTypes === null || supportedPerformanceTypes === void 0 ? void 0 : supportedPerformanceTypes.has(PerformanceTypes.LongTask)) {
4625
4703
  var ttiHandler_1 = (CxGlobal.__tti = {
4626
4704
  e: [],
4627
4705
  });
@@ -4650,6 +4728,7 @@ var CoralogixRum = {
4650
4728
  },
4651
4729
  init: function (options) {
4652
4730
  var _a, _b;
4731
+ var _this = this;
4653
4732
  try {
4654
4733
  // Check if CoralogixRum already inited.
4655
4734
  if (isInited) {
@@ -4691,6 +4770,12 @@ var CoralogixRum = {
4691
4770
  if (pluginConf) {
4692
4771
  var instrumentation = void 0;
4693
4772
  switch (confKey) {
4773
+ case WORKER_INSTRUMENTATION: {
4774
+ if (resolvedOptions_1.workerSupport) {
4775
+ instrumentation = new Instrument(pluginConf, errorsInstrumentation, _this);
4776
+ }
4777
+ break;
4778
+ }
4694
4779
  case ERROR_INSTRUMENTATION_NAME: {
4695
4780
  instrumentation = new Instrument(pluginConf);
4696
4781
  errorsInstrumentation =
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coralogix/browser",
3
- "version": "2.6.0",
3
+ "version": "2.8.0",
4
4
  "description": "Official Coralogix SDK for browsers",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Coralogix",
@@ -80,6 +80,15 @@ function _createForOfIteratorHelper(r, e) {
80
80
  }
81
81
  };
82
82
  }
83
+ function _extends() {
84
+ return _extends = Object.assign ? Object.assign.bind() : function (n) {
85
+ for (var e = 1; e < arguments.length; e++) {
86
+ var t = arguments[e];
87
+ for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
88
+ }
89
+ return n;
90
+ }, _extends.apply(null, arguments);
91
+ }
83
92
  function _toPrimitive(t, r) {
84
93
  if ("object" != typeof t || !t) return t;
85
94
  var e = t[Symbol.toPrimitive];
@@ -247,7 +256,7 @@ var Mirror = /*#__PURE__*/function () {
247
256
  value: function removeNodeFromMap(n) {
248
257
  var _this = this;
249
258
  var id = this.getId(n);
250
- this.idNodeMap.delete(id);
259
+ this.idNodeMap["delete"](id);
251
260
  if (n.childNodes) {
252
261
  n.childNodes.forEach(function (childNode) {
253
262
  return _this.removeNodeFromMap(childNode);
@@ -889,7 +898,7 @@ function serializeElementNode(n, options) {
889
898
  width = _n$getBoundingClientR.width,
890
899
  height = _n$getBoundingClientR.height;
891
900
  attributes2 = {
892
- class: attributes2.class,
901
+ "class": attributes2["class"],
893
902
  rr_width: "".concat(width, "px"),
894
903
  rr_height: "".concat(height, "px")
895
904
  };
@@ -1026,7 +1035,7 @@ function serializeNodeWithId(n, options) {
1026
1035
  } else {
1027
1036
  id = genId();
1028
1037
  }
1029
- var serializedNode2 = Object.assign(_serializedNode, {
1038
+ var serializedNode2 = _extends(_serializedNode, {
1030
1039
  id: id
1031
1040
  });
1032
1041
  mirror.add(n, serializedNode2);
@@ -12,6 +12,7 @@ import { CoralogixScreenshotInstrumentation } from './instrumentations/screensho
12
12
  import { CoralogixCustomMeasurementInstrumentation } from './instrumentations/custom-measurements';
13
13
  import { CoralogixInternalInstrumentation } from './instrumentations/CoralogixInternalInstrumentation';
14
14
  import { CoralogixDOMInstrumentation } from './instrumentations/CoralogixDOMInstrumentation';
15
+ import { CoralogixWorkerInstrumentation } from './instrumentations/web-worker/CoralogixWorkerInstrumentation';
15
16
  export declare const CORALOGIX_LOGS_URL_SUFFIX = "/browser/v1beta/logs";
16
17
  export declare const CORALOGIX_RECORDING_URL_SUFFIX = "/sessionrecording";
17
18
  export declare const MAX_EXPORT_BATCH_SIZE = 50;
@@ -82,6 +83,10 @@ export declare const INSTRUMENTATIONS: readonly [{
82
83
  readonly Instrument: typeof CoralogixScreenshotInstrumentation;
83
84
  readonly confKey: "screenshot";
84
85
  readonly disable: false;
86
+ }, {
87
+ readonly Instrument: typeof CoralogixWorkerInstrumentation;
88
+ readonly confKey: "web_worker";
89
+ readonly disable: false;
85
90
  }];
86
91
  export declare const CoralogixAttributes: {
87
92
  USER_AGENT: string;
@@ -1,11 +1,15 @@
1
1
  import { CoralogixOtelWebType, CoralogixWindow, CxSpan } from './types';
2
2
  import { MemoryUsageContext } from './instrumentations/memory-usage';
3
3
  declare global {
4
+ interface Worker {
5
+ CoralogixRum: CoralogixOtelWebType;
6
+ }
4
7
  interface Object {
5
8
  __cx_global__: unknown;
6
9
  }
7
10
  interface Window extends CoralogixWindow {
8
11
  cachedLogs: CxSpan[];
12
+ Worker: typeof Worker;
9
13
  }
10
14
  interface Performance {
11
15
  measureUserAgentSpecificMemory(): Promise<MemoryUsageContext>;
@@ -12,7 +12,8 @@ export declare enum ErrorSource {
12
12
  WINDOW = "window",
13
13
  UNHANDLED_REJECTION = "unhandledrejection",
14
14
  DOCUMENT = "document",
15
- CAPTURED = "captured"
15
+ CAPTURED = "captured",
16
+ WEB_WORKER = "web_worker"
16
17
  }
17
18
  interface CoralogixErrorInstrumentationConfig extends InstrumentationConfig {
18
19
  ignoreErrors?: Array<string | RegExp>;
@@ -9,6 +9,8 @@ export declare const DOM_INSTRUMENTATION_NAME = "dom";
9
9
  export declare const DOM_INSTRUMENTATION_VERSION = "1.0.0";
10
10
  export declare const CUSTOM_MEASUREMENT_INSTRUMENTATION_NAME = "custom_measurement";
11
11
  export declare const CUSTOM_MEASUREMENT_INSTRUMENTATION_VERSION = "1.0.0";
12
+ export declare const WORKER_INSTRUMENTATION = "web_worker";
13
+ export declare const WORKER_INSTRUMENTATION_VERSION = "1.0.0";
12
14
  export declare const XHR_INSTRUMENTATION_NAME = "xhr";
13
15
  export declare const FETCH_INSTRUMENTATION_NAME = "fetch";
14
16
  export declare const CUSTOM_INSTRUMENTATION_NAME = "custom";
@@ -0,0 +1,14 @@
1
+ import { CoralogixOtelWebType } from '../../types';
2
+ import { InstrumentationBase, InstrumentationConfig } from '@opentelemetry/instrumentation';
3
+ import { CoralogixErrorInstrumentation } from '../CoralogixErrorInstrumentation';
4
+ export declare class CoralogixWorkerInstrumentation extends InstrumentationBase {
5
+ private errorInstrumentation;
6
+ coralogixRum: CoralogixOtelWebType;
7
+ constructor(config: InstrumentationConfig, errorInstrumentation: CoralogixErrorInstrumentation | undefined, coralogixRum: CoralogixOtelWebType);
8
+ disable(): void;
9
+ enable(): void;
10
+ init(): void;
11
+ private createCxWorker;
12
+ private attachWorkerErrorHandlers;
13
+ private reportWorkerError;
14
+ }
@@ -0,0 +1,12 @@
1
+ export declare const ERROR_TYPES: {
2
+ RUNTIME: string;
3
+ MESSAGE_ERROR: string;
4
+ };
5
+ export declare const ERROR_MESSAGES: {
6
+ readonly UNKNOWN_RUNTIME: "Unknown worker runtime error";
7
+ readonly DESERIALIZATION_FAILED: "Failed to deserialize message from worker";
8
+ };
9
+ export declare const WORKER_EVENTS: {
10
+ readonly ERROR: "error";
11
+ readonly MESSAGE_ERROR: "messageerror";
12
+ };
package/src/types.d.ts CHANGED
@@ -198,6 +198,8 @@ export interface CoralogixBrowserSdkConfig {
198
198
  networkExtraConfig?: NetworkExtraConfig[];
199
199
  /** Enable MFE support. Defaults to false */
200
200
  supportMfe?: boolean;
201
+ /** Enable Web Worker support. Defaults to false */
202
+ workerSupport?: boolean;
201
203
  }
202
204
  export interface CoralogixOtelWebType extends SendLog {
203
205
  /**
package/src/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "2.6.0";
1
+ export declare const SDK_VERSION = "2.8.0";