@coralogix/browser 2.6.0 → 2.7.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,8 @@
1
+ ## 2.7.0 (2025-05-05)
2
+
3
+ 🚀 Features
4
+ Add Web Worker error handling.
5
+
1
6
  ## 2.6.0 (2025-05-04)
2
7
 
3
8
  ### 🚀 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>
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';
@@ -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',
@@ -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.7.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.7.0",
4
4
  "description": "Official Coralogix SDK for browsers",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Coralogix",
@@ -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.7.0";