@echoteam/signoz-react 1.2.13 → 1.2.15

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/dist/index.js CHANGED
@@ -15568,23 +15568,75 @@ function addXHRLogging(config) {
15568
15568
  };
15569
15569
  }
15570
15570
  // Fungsi untuk menambahkan error tracking
15571
- function addErrorTracking(enableConsoleLog = false) {
15571
+ function addErrorTracking(config) {
15572
+ // Helper function to check if URL should be ignored
15573
+ const shouldIgnoreUrl = (url) => {
15574
+ if (!url)
15575
+ return false;
15576
+ return config.ignoreNetworkErrorUrls.some(pattern => {
15577
+ if (pattern instanceof RegExp) {
15578
+ return pattern.test(url);
15579
+ }
15580
+ return url.includes(pattern);
15581
+ });
15582
+ };
15572
15583
  // Track unhandled errors
15573
15584
  window.addEventListener('error', (event) => {
15574
15585
  var _a, _b;
15575
- // Skip SignOz internal timeout errors
15586
+ // Skip SignOz internal timeout errors and network errors
15576
15587
  const errorMessage = event.message || '';
15577
15588
  const errorStack = ((_a = event.error) === null || _a === void 0 ? void 0 : _a.stack) || '';
15578
- const isSignOzTimeout = (errorMessage.includes('Timeout') &&
15589
+ const errorFilename = event.filename || '';
15590
+ const isSignOzTimeout = ((errorMessage.includes('Timeout') || errorMessage.includes('timeout') || errorMessage.includes('ETIMEDOUT')) &&
15579
15591
  (errorMessage.includes('BatchSpanProcessor') ||
15592
+ errorMessage.includes('OTLP') ||
15593
+ errorMessage.includes('exporter') ||
15580
15594
  errorStack.includes('BatchSpanProcessor') ||
15595
+ errorStack.includes('OTLPTraceExporter') ||
15581
15596
  errorStack.includes('zone.js') ||
15582
- errorStack.includes('SignOz')));
15583
- if (isSignOzTimeout) {
15584
- if (enableConsoleLog) {
15597
+ errorStack.includes('SignOz') ||
15598
+ errorFilename.includes('zone.js')));
15599
+ // Also skip generic timeout errors that might be from SignOz
15600
+ const isGenericTimeout = (errorMessage === 'Timeout' ||
15601
+ errorMessage === 'timeout' ||
15602
+ (errorMessage.includes('Timeout') && errorStack.includes('zone.js')));
15603
+ if (isSignOzTimeout || isGenericTimeout) {
15604
+ if (config.enableConsoleLog) {
15585
15605
  console.warn('[SignOz] Span export timeout detected (safe to ignore - not tracking this error)');
15586
15606
  }
15587
15607
  event.preventDefault(); // Prevent the error from propagating
15608
+ event.stopPropagation(); // Stop event bubbling
15609
+ event.stopImmediatePropagation(); // Stop other listeners
15610
+ return;
15611
+ }
15612
+ // Skip network errors if trackNetworkErrors is disabled
15613
+ if (!config.trackNetworkErrors) {
15614
+ const isNetworkError = (errorMessage.includes('XHR request failed') ||
15615
+ errorMessage.includes('Failed to fetch') ||
15616
+ errorMessage.includes('Network request failed') ||
15617
+ errorMessage.includes('NetworkError') ||
15618
+ errorMessage.includes('net::ERR_') ||
15619
+ errorStack.includes('XMLHttpRequest') ||
15620
+ errorStack.includes('fetch'));
15621
+ if (isNetworkError) {
15622
+ if (config.enableConsoleLog) {
15623
+ console.warn('[SignOz] Network error detected (not tracking - trackNetworkErrors is disabled)');
15624
+ }
15625
+ event.preventDefault();
15626
+ event.stopPropagation();
15627
+ event.stopImmediatePropagation();
15628
+ return;
15629
+ }
15630
+ }
15631
+ // Check if URL should be ignored
15632
+ const errorUrl = event.filename || '';
15633
+ if (shouldIgnoreUrl(errorUrl)) {
15634
+ if (config.enableConsoleLog) {
15635
+ console.warn('[SignOz] Error from ignored URL (not tracking):', errorUrl);
15636
+ }
15637
+ event.preventDefault();
15638
+ event.stopPropagation();
15639
+ event.stopImmediatePropagation();
15588
15640
  return;
15589
15641
  }
15590
15642
  const tracer = trace.getTracer('error-tracker');
@@ -15605,7 +15657,7 @@ function addErrorTracking(enableConsoleLog = false) {
15605
15657
  span.setAttribute('error.name', event.error.name || 'Error');
15606
15658
  }
15607
15659
  span.setStatus({ code: SpanStatusCode.ERROR, message: event.message });
15608
- if (enableConsoleLog) {
15660
+ if (config.enableConsoleLog) {
15609
15661
  console.error('[SignOz] Unhandled Error:', {
15610
15662
  message: event.message,
15611
15663
  filename: event.filename,
@@ -15623,17 +15675,45 @@ function addErrorTracking(enableConsoleLog = false) {
15623
15675
  const reason = String(event.reason);
15624
15676
  const stack = event.reason instanceof Error ? (event.reason.stack || '') : '';
15625
15677
  // Check if this is a SignOz internal timeout error
15626
- const isSignOzTimeout = (reason.includes('Timeout') &&
15678
+ const isSignOzTimeout = ((reason.includes('Timeout') || reason.includes('timeout') || reason.includes('ETIMEDOUT')) &&
15627
15679
  (reason.includes('BatchSpanProcessor') ||
15680
+ reason.includes('OTLP') ||
15681
+ reason.includes('exporter') ||
15628
15682
  stack.includes('BatchSpanProcessor') ||
15683
+ stack.includes('OTLPTraceExporter') ||
15629
15684
  stack.includes('zone.js')));
15630
- if (isSignOzTimeout) {
15631
- if (enableConsoleLog) {
15685
+ // Also skip generic timeout errors that might be from SignOz
15686
+ const isGenericTimeout = (reason === 'Timeout' ||
15687
+ reason === 'timeout' ||
15688
+ (reason.includes('Timeout') && stack.includes('zone.js')));
15689
+ if (isSignOzTimeout || isGenericTimeout) {
15690
+ if (config.enableConsoleLog) {
15632
15691
  console.warn('[SignOz] Span export timeout (this is usually safe to ignore - check if SignOz endpoint is reachable)');
15633
15692
  }
15634
15693
  event.preventDefault(); // Prevent the error from being logged
15694
+ event.stopPropagation(); // Stop event bubbling
15695
+ event.stopImmediatePropagation(); // Stop other listeners
15635
15696
  return;
15636
15697
  }
15698
+ // Skip network errors if trackNetworkErrors is disabled
15699
+ if (!config.trackNetworkErrors) {
15700
+ const isNetworkError = (reason.includes('XHR request failed') ||
15701
+ reason.includes('Failed to fetch') ||
15702
+ reason.includes('Network request failed') ||
15703
+ reason.includes('NetworkError') ||
15704
+ reason.includes('net::ERR_') ||
15705
+ stack.includes('XMLHttpRequest') ||
15706
+ stack.includes('fetch'));
15707
+ if (isNetworkError) {
15708
+ if (config.enableConsoleLog) {
15709
+ console.warn('[SignOz] Network error in promise (not tracking - trackNetworkErrors is disabled)');
15710
+ }
15711
+ event.preventDefault();
15712
+ event.stopPropagation();
15713
+ event.stopImmediatePropagation();
15714
+ return;
15715
+ }
15716
+ }
15637
15717
  const tracer = trace.getTracer('error-tracker');
15638
15718
  const span = tracer.startSpan('Unhandled Promise Rejection');
15639
15719
  span.setAttribute('error.type', 'unhandled_rejection');
@@ -15650,7 +15730,7 @@ function addErrorTracking(enableConsoleLog = false) {
15650
15730
  span.setAttribute('error.name', event.reason.name || 'Error');
15651
15731
  }
15652
15732
  span.setStatus({ code: SpanStatusCode.ERROR, message: String(event.reason) });
15653
- if (enableConsoleLog) {
15733
+ if (config.enableConsoleLog) {
15654
15734
  console.error('[SignOz] Unhandled Promise Rejection:', event.reason, 'on page', window.location.pathname);
15655
15735
  }
15656
15736
  span.end();
@@ -15664,14 +15744,39 @@ function addErrorTracking(enableConsoleLog = false) {
15664
15744
  // Skip SignOz internal timeout errors
15665
15745
  const errorMessage = error.message || String(error);
15666
15746
  const errorStack = error.stack || '';
15667
- const isSignOzTimeout = (errorMessage.includes('Timeout') &&
15668
- (errorStack.includes('BatchSpanProcessor') || errorStack.includes('zone.js')));
15669
- if (isSignOzTimeout) {
15670
- if (enableConsoleLog) {
15747
+ const isSignOzTimeout = ((errorMessage.includes('Timeout') || errorMessage.includes('timeout') || errorMessage.includes('ETIMEDOUT')) &&
15748
+ (errorMessage.includes('BatchSpanProcessor') ||
15749
+ errorMessage.includes('OTLP') ||
15750
+ errorMessage.includes('exporter') ||
15751
+ errorStack.includes('BatchSpanProcessor') ||
15752
+ errorStack.includes('OTLPTraceExporter') ||
15753
+ errorStack.includes('zone.js')));
15754
+ // Also skip generic timeout errors
15755
+ const isGenericTimeout = (errorMessage === 'Timeout' ||
15756
+ errorMessage === 'timeout' ||
15757
+ (errorMessage.includes('Timeout') && errorStack.includes('zone.js')));
15758
+ if (isSignOzTimeout || isGenericTimeout) {
15759
+ if (config.enableConsoleLog) {
15671
15760
  console.warn('[SignOz] Zone.js caught span export timeout (safe to ignore)');
15672
15761
  }
15673
15762
  return; // Don't track this error
15674
15763
  }
15764
+ // Skip network errors if trackNetworkErrors is disabled
15765
+ if (!config.trackNetworkErrors) {
15766
+ const isNetworkError = (errorMessage.includes('XHR request failed') ||
15767
+ errorMessage.includes('Failed to fetch') ||
15768
+ errorMessage.includes('Network request failed') ||
15769
+ errorMessage.includes('NetworkError') ||
15770
+ errorMessage.includes('net::ERR_') ||
15771
+ errorStack.includes('XMLHttpRequest') ||
15772
+ errorStack.includes('fetch'));
15773
+ if (isNetworkError) {
15774
+ if (config.enableConsoleLog) {
15775
+ console.warn('[SignOz] Zone.js caught network error (not tracking - trackNetworkErrors is disabled)');
15776
+ }
15777
+ return;
15778
+ }
15779
+ }
15675
15780
  const tracer = trace.getTracer('error-tracker');
15676
15781
  const span = tracer.startSpan('Zone.js Error');
15677
15782
  span.setAttribute('error.type', 'zone_error');
@@ -15687,7 +15792,7 @@ function addErrorTracking(enableConsoleLog = false) {
15687
15792
  }
15688
15793
  span.recordException(error);
15689
15794
  span.setStatus({ code: SpanStatusCode.ERROR, message: error.message || String(error) });
15690
- if (enableConsoleLog) {
15795
+ if (config.enableConsoleLog) {
15691
15796
  console.error('[SignOz] Zone.js Error:', error, 'on page', window.location.pathname);
15692
15797
  }
15693
15798
  span.end();
@@ -15710,6 +15815,16 @@ function addErrorTracking(enableConsoleLog = false) {
15710
15815
  // Just call original console.error without tracking
15711
15816
  return originalConsoleError.apply(console, args);
15712
15817
  }
15818
+ // Skip network errors if trackNetworkErrors is disabled
15819
+ const isNetworkError = (errorMessage.includes('XHR request failed') ||
15820
+ errorMessage.includes('Failed to fetch') ||
15821
+ errorMessage.includes('Network request failed') ||
15822
+ errorMessage.includes('NetworkError') ||
15823
+ errorMessage.includes('net::ERR_'));
15824
+ if (isNetworkError && !config.trackNetworkErrors) {
15825
+ // Just call original console.error without tracking
15826
+ return originalConsoleError.apply(console, args);
15827
+ }
15713
15828
  if (errorMessage.includes('React') || errorMessage.includes('TypeError') || errorMessage.includes('Uncaught')) {
15714
15829
  const tracer = trace.getTracer('error-tracker');
15715
15830
  const span = tracer.startSpan('Console Error');
@@ -16039,6 +16154,63 @@ function addWebSocketLogging(config) {
16039
16154
  */
16040
16155
  function initializeSignOzTracing(config) {
16041
16156
  try {
16157
+ // Install global error suppression for SignOz timeout errors FIRST
16158
+ // This must be done before any other initialization
16159
+ const originalWindowError = window.onerror;
16160
+ window.onerror = function (message, source, lineno, colno, error) {
16161
+ const errorMessage = String(message);
16162
+ const errorStack = (error === null || error === void 0 ? void 0 : error.stack) || '';
16163
+ const errorSource = source || '';
16164
+ // Suppress SignOz timeout errors globally - be very aggressive
16165
+ const isSignOzTimeout = ((errorMessage.includes('Timeout') || errorMessage.includes('timeout') || errorMessage.includes('ETIMEDOUT')) &&
16166
+ (errorMessage.includes('BatchSpanProcessor') ||
16167
+ errorMessage.includes('OTLP') ||
16168
+ errorMessage.includes('exporter') ||
16169
+ errorStack.includes('BatchSpanProcessor') ||
16170
+ errorStack.includes('OTLPTraceExporter') ||
16171
+ errorStack.includes('zone.js') ||
16172
+ errorSource.includes('zone.js') ||
16173
+ errorStack.includes('signoz') ||
16174
+ errorSource.includes('signoz')));
16175
+ // Also suppress generic timeout errors from zone.js or bundle.js
16176
+ const isGenericTimeout = ((errorMessage === 'Timeout' || errorMessage === 'timeout') ||
16177
+ (errorMessage.includes('Timeout') && (errorStack.includes('zone.js') || errorSource.includes('bundle.js'))));
16178
+ if (isSignOzTimeout || isGenericTimeout) {
16179
+ // Suppress completely - don't log, don't propagate
16180
+ return true; // Returning true prevents default error handling
16181
+ }
16182
+ // Call original handler for other errors
16183
+ if (originalWindowError) {
16184
+ return originalWindowError.call(window, message, source, lineno, colno, error);
16185
+ }
16186
+ return false;
16187
+ };
16188
+ // Also suppress unhandledrejection for timeout errors
16189
+ const originalUnhandledRejection = window.onunhandledrejection;
16190
+ window.addEventListener('unhandledrejection', function (event) {
16191
+ const reason = String(event.reason);
16192
+ const stack = event.reason instanceof Error ? (event.reason.stack || '') : '';
16193
+ const isSignOzTimeout = ((reason.includes('Timeout') || reason.includes('timeout') || reason.includes('ETIMEDOUT')) &&
16194
+ (reason.includes('BatchSpanProcessor') ||
16195
+ reason.includes('OTLP') ||
16196
+ reason.includes('exporter') ||
16197
+ stack.includes('BatchSpanProcessor') ||
16198
+ stack.includes('OTLPTraceExporter') ||
16199
+ stack.includes('zone.js') ||
16200
+ stack.includes('signoz')));
16201
+ const isGenericTimeout = (reason === 'Timeout' ||
16202
+ reason === 'timeout' ||
16203
+ (reason.includes('Timeout') && stack.includes('zone.js')));
16204
+ if (isSignOzTimeout || isGenericTimeout) {
16205
+ event.preventDefault();
16206
+ event.stopPropagation();
16207
+ event.stopImmediatePropagation();
16208
+ return;
16209
+ }
16210
+ if (originalUnhandledRejection) {
16211
+ originalUnhandledRejection.call(window, event);
16212
+ }
16213
+ }, true);
16042
16214
  // Gabungkan konfigurasi dari parameter, process.env, dan window
16043
16215
  const effectiveConfig = {
16044
16216
  serviceName: (config === null || config === void 0 ? void 0 : config.serviceName) || getConfigValue('REACT_APP_SIGNOZ_SERVICE_NAME'),
@@ -16053,9 +16225,9 @@ function initializeSignOzTracing(config) {
16053
16225
  })(),
16054
16226
  batchSpanProcessorConfig: (config === null || config === void 0 ? void 0 : config.batchSpanProcessorConfig) || {
16055
16227
  maxQueueSize: 100,
16056
- scheduledDelayMillis: 5000,
16057
- exportTimeoutMillis: 30000, // Reduced to 30 seconds to fail faster
16058
- maxExportBatchSize: 50 // Smaller batches to avoid timeouts
16228
+ scheduledDelayMillis: 2000, // Kirim lebih cepat (2 detik)
16229
+ exportTimeoutMillis: 5000, // Timeout lebih pendek (5 detik)
16230
+ maxExportBatchSize: 20 // Batch lebih kecil untuk menghindari timeout
16059
16231
  },
16060
16232
  allowedOrigins: (config === null || config === void 0 ? void 0 : config.allowedOrigins) || parseAllowedOrigins(getConfigValue('REACT_APP_SIGNOZ_ALLOWED_ORIGINS')),
16061
16233
  enableRequestLogging: (config === null || config === void 0 ? void 0 : config.enableRequestLogging) !== undefined ? config.enableRequestLogging : (getConfigValue('REACT_APP_SIGNOZ_ENABLE_REQUEST_LOGGING') === 'true' || true),
@@ -16067,7 +16239,9 @@ function initializeSignOzTracing(config) {
16067
16239
  enableNavigationTracking: (config === null || config === void 0 ? void 0 : config.enableNavigationTracking) !== undefined ? config.enableNavigationTracking : (getConfigValue('REACT_APP_SIGNOZ_ENABLE_NAVIGATION_TRACKING') === 'true'),
16068
16240
  enableConsoleLog: (config === null || config === void 0 ? void 0 : config.enableConsoleLog) !== undefined ? config.enableConsoleLog : (getConfigValue('REACT_APP_SIGNOZ_ENABLE_CONSOLE_LOG') === 'true'),
16069
16241
  enableWebSocketLogging: (config === null || config === void 0 ? void 0 : config.enableWebSocketLogging) !== undefined ? config.enableWebSocketLogging : (getConfigValue('REACT_APP_SIGNOZ_ENABLE_WEBSOCKET_LOGGING') === 'true'),
16070
- logWebSocketMessages: (config === null || config === void 0 ? void 0 : config.logWebSocketMessages) !== undefined ? config.logWebSocketMessages : (getConfigValue('REACT_APP_SIGNOZ_LOG_WEBSOCKET_MESSAGES') === 'true')
16242
+ logWebSocketMessages: (config === null || config === void 0 ? void 0 : config.logWebSocketMessages) !== undefined ? config.logWebSocketMessages : (getConfigValue('REACT_APP_SIGNOZ_LOG_WEBSOCKET_MESSAGES') === 'true'),
16243
+ trackNetworkErrors: (config === null || config === void 0 ? void 0 : config.trackNetworkErrors) !== undefined ? config.trackNetworkErrors : (getConfigValue('REACT_APP_SIGNOZ_TRACK_NETWORK_ERRORS') === 'true'),
16244
+ ignoreNetworkErrorUrls: (config === null || config === void 0 ? void 0 : config.ignoreNetworkErrorUrls) || []
16071
16245
  };
16072
16246
  // Validasi konfigurasi
16073
16247
  const { isValid, missingFields } = validateConfig(effectiveConfig);
@@ -16087,32 +16261,55 @@ function initializeSignOzTracing(config) {
16087
16261
  const exporter = new OTLPTraceExporter({
16088
16262
  url: effectiveConfig.url,
16089
16263
  headers: effectiveConfig.headers,
16090
- timeoutMillis: 30000 // Reduced to 30 seconds to fail faster
16264
+ timeoutMillis: 5000 // Timeout lebih pendek (5 detik) untuk fail fast
16091
16265
  });
16092
- // Wrap exporter to suppress timeout errors
16266
+ // Wrap exporter to suppress timeout errors completely
16093
16267
  const originalExport = exporter.export.bind(exporter);
16094
16268
  exporter.export = function (spans, resultCallback) {
16095
- originalExport(spans, (result) => {
16096
- // Suppress timeout errors to prevent console noise
16097
- if (result.error) {
16098
- const errorMessage = String(result.error);
16099
- if (errorMessage.includes('Timeout') || errorMessage.includes('timeout')) {
16269
+ // Wrap in try-catch to prevent any errors from propagating
16270
+ try {
16271
+ // Set a timeout to force success callback if export takes too long
16272
+ const timeoutId = setTimeout(() => {
16273
+ // Force success callback to prevent error propagation
16274
+ resultCallback({ code: 0 });
16275
+ }, 6000); // Slightly longer than exporter timeout
16276
+ originalExport(spans, (result) => {
16277
+ clearTimeout(timeoutId);
16278
+ // Suppress ALL errors to prevent console noise and Zone.js catching them
16279
+ if (result.error) {
16280
+ const errorMessage = String(result.error);
16281
+ if (errorMessage.includes('Timeout') || errorMessage.includes('timeout') || errorMessage.includes('ETIMEDOUT')) {
16282
+ if (effectiveConfig.enableConsoleLog) {
16283
+ console.warn('[SignOz] Span export timeout - check if SignOz endpoint is reachable:', effectiveConfig.url);
16284
+ }
16285
+ // Call callback with success to prevent error propagation
16286
+ resultCallback({ code: 0 });
16287
+ return;
16288
+ }
16289
+ // For other errors, also suppress but log if console logging is enabled
16100
16290
  if (effectiveConfig.enableConsoleLog) {
16101
- console.warn('[SignOz] Span export timeout - check if SignOz endpoint is reachable:', effectiveConfig.url);
16291
+ console.warn('[SignOz] Span export error (suppressed):', errorMessage);
16102
16292
  }
16103
- // Call callback with success to prevent error propagation
16104
16293
  resultCallback({ code: 0 });
16105
16294
  return;
16106
16295
  }
16296
+ resultCallback(result);
16297
+ });
16298
+ }
16299
+ catch (error) {
16300
+ // Catch any synchronous errors and suppress them
16301
+ if (effectiveConfig.enableConsoleLog) {
16302
+ console.warn('[SignOz] Span export exception (suppressed):', error);
16107
16303
  }
16108
- resultCallback(result);
16109
- });
16304
+ resultCallback({ code: 0 });
16305
+ }
16110
16306
  };
16111
16307
  // Set up the span processor with configuration
16112
16308
  const processor = new BatchSpanProcessor(exporter, {
16113
16309
  maxQueueSize: effectiveConfig.batchSpanProcessorConfig.maxQueueSize,
16114
16310
  scheduledDelayMillis: effectiveConfig.batchSpanProcessorConfig.scheduledDelayMillis,
16115
- exportTimeoutMillis: effectiveConfig.batchSpanProcessorConfig.exportTimeoutMillis
16311
+ exportTimeoutMillis: effectiveConfig.batchSpanProcessorConfig.exportTimeoutMillis,
16312
+ maxExportBatchSize: effectiveConfig.batchSpanProcessorConfig.maxExportBatchSize
16116
16313
  });
16117
16314
  // Create and configure the WebTracerProvider
16118
16315
  const provider = new WebTracerProvider({
@@ -16169,7 +16366,11 @@ function initializeSignOzTracing(config) {
16169
16366
  }
16170
16367
  // Tambahkan error tracking
16171
16368
  if (effectiveConfig.enableErrorTracking) {
16172
- addErrorTracking(effectiveConfig.enableConsoleLog);
16369
+ addErrorTracking({
16370
+ enableConsoleLog: effectiveConfig.enableConsoleLog,
16371
+ trackNetworkErrors: effectiveConfig.trackNetworkErrors,
16372
+ ignoreNetworkErrorUrls: effectiveConfig.ignoreNetworkErrorUrls
16373
+ });
16173
16374
  }
16174
16375
  // Tambahkan navigation tracking
16175
16376
  if (effectiveConfig.enableNavigationTracking) {
@@ -16197,7 +16398,8 @@ function initializeSignOzTracing(config) {
16197
16398
  enableErrorTracking: effectiveConfig.enableErrorTracking,
16198
16399
  enableNavigationTracking: effectiveConfig.enableNavigationTracking,
16199
16400
  enableWebSocketLogging: effectiveConfig.enableWebSocketLogging,
16200
- logWebSocketMessages: effectiveConfig.logWebSocketMessages
16401
+ logWebSocketMessages: effectiveConfig.logWebSocketMessages,
16402
+ trackNetworkErrors: effectiveConfig.trackNetworkErrors
16201
16403
  });
16202
16404
  console.log('SignOz: Tracing berhasil diinisialisasi');
16203
16405
  }