@echoteam/signoz-react 1.2.13 → 1.2.14

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,34 @@ 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
+ // Suppress SignOz timeout errors globally
16164
+ const isSignOzTimeout = ((errorMessage.includes('Timeout') || errorMessage.includes('timeout') || errorMessage.includes('ETIMEDOUT')) &&
16165
+ (errorMessage.includes('BatchSpanProcessor') ||
16166
+ errorMessage.includes('OTLP') ||
16167
+ errorMessage.includes('exporter') ||
16168
+ errorStack.includes('BatchSpanProcessor') ||
16169
+ errorStack.includes('OTLPTraceExporter') ||
16170
+ errorStack.includes('zone.js') ||
16171
+ (source === null || source === void 0 ? void 0 : source.includes('zone.js'))));
16172
+ const isGenericTimeout = (errorMessage === 'Timeout' ||
16173
+ errorMessage === 'timeout' ||
16174
+ (errorMessage.includes('Timeout') && errorStack.includes('zone.js')));
16175
+ if (isSignOzTimeout || isGenericTimeout) {
16176
+ // Suppress completely - don't log, don't propagate
16177
+ return true; // Returning true prevents default error handling
16178
+ }
16179
+ // Call original handler for other errors
16180
+ if (originalWindowError) {
16181
+ return originalWindowError.call(window, message, source, lineno, colno, error);
16182
+ }
16183
+ return false;
16184
+ };
16042
16185
  // Gabungkan konfigurasi dari parameter, process.env, dan window
16043
16186
  const effectiveConfig = {
16044
16187
  serviceName: (config === null || config === void 0 ? void 0 : config.serviceName) || getConfigValue('REACT_APP_SIGNOZ_SERVICE_NAME'),
@@ -16053,9 +16196,9 @@ function initializeSignOzTracing(config) {
16053
16196
  })(),
16054
16197
  batchSpanProcessorConfig: (config === null || config === void 0 ? void 0 : config.batchSpanProcessorConfig) || {
16055
16198
  maxQueueSize: 100,
16056
- scheduledDelayMillis: 5000,
16057
- exportTimeoutMillis: 30000, // Reduced to 30 seconds to fail faster
16058
- maxExportBatchSize: 50 // Smaller batches to avoid timeouts
16199
+ scheduledDelayMillis: 3000, // Kirim lebih cepat (3 detik)
16200
+ exportTimeoutMillis: 10000, // Timeout lebih pendek (10 detik)
16201
+ maxExportBatchSize: 30 // Batch lebih kecil untuk menghindari timeout
16059
16202
  },
16060
16203
  allowedOrigins: (config === null || config === void 0 ? void 0 : config.allowedOrigins) || parseAllowedOrigins(getConfigValue('REACT_APP_SIGNOZ_ALLOWED_ORIGINS')),
16061
16204
  enableRequestLogging: (config === null || config === void 0 ? void 0 : config.enableRequestLogging) !== undefined ? config.enableRequestLogging : (getConfigValue('REACT_APP_SIGNOZ_ENABLE_REQUEST_LOGGING') === 'true' || true),
@@ -16067,7 +16210,9 @@ function initializeSignOzTracing(config) {
16067
16210
  enableNavigationTracking: (config === null || config === void 0 ? void 0 : config.enableNavigationTracking) !== undefined ? config.enableNavigationTracking : (getConfigValue('REACT_APP_SIGNOZ_ENABLE_NAVIGATION_TRACKING') === 'true'),
16068
16211
  enableConsoleLog: (config === null || config === void 0 ? void 0 : config.enableConsoleLog) !== undefined ? config.enableConsoleLog : (getConfigValue('REACT_APP_SIGNOZ_ENABLE_CONSOLE_LOG') === 'true'),
16069
16212
  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')
16213
+ logWebSocketMessages: (config === null || config === void 0 ? void 0 : config.logWebSocketMessages) !== undefined ? config.logWebSocketMessages : (getConfigValue('REACT_APP_SIGNOZ_LOG_WEBSOCKET_MESSAGES') === 'true'),
16214
+ trackNetworkErrors: (config === null || config === void 0 ? void 0 : config.trackNetworkErrors) !== undefined ? config.trackNetworkErrors : (getConfigValue('REACT_APP_SIGNOZ_TRACK_NETWORK_ERRORS') === 'true'),
16215
+ ignoreNetworkErrorUrls: (config === null || config === void 0 ? void 0 : config.ignoreNetworkErrorUrls) || []
16071
16216
  };
16072
16217
  // Validasi konfigurasi
16073
16218
  const { isValid, missingFields } = validateConfig(effectiveConfig);
@@ -16087,32 +16232,49 @@ function initializeSignOzTracing(config) {
16087
16232
  const exporter = new OTLPTraceExporter({
16088
16233
  url: effectiveConfig.url,
16089
16234
  headers: effectiveConfig.headers,
16090
- timeoutMillis: 30000 // Reduced to 30 seconds to fail faster
16235
+ timeoutMillis: 10000 // Timeout lebih pendek (10 detik)
16091
16236
  });
16092
- // Wrap exporter to suppress timeout errors
16237
+ // Wrap exporter to suppress timeout errors completely
16093
16238
  const originalExport = exporter.export.bind(exporter);
16094
16239
  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')) {
16240
+ // Wrap in try-catch to prevent any errors from propagating
16241
+ try {
16242
+ originalExport(spans, (result) => {
16243
+ // Suppress ALL errors to prevent console noise and Zone.js catching them
16244
+ if (result.error) {
16245
+ const errorMessage = String(result.error);
16246
+ if (errorMessage.includes('Timeout') || errorMessage.includes('timeout') || errorMessage.includes('ETIMEDOUT')) {
16247
+ if (effectiveConfig.enableConsoleLog) {
16248
+ console.warn('[SignOz] Span export timeout - check if SignOz endpoint is reachable:', effectiveConfig.url);
16249
+ }
16250
+ // Call callback with success to prevent error propagation
16251
+ resultCallback({ code: 0 });
16252
+ return;
16253
+ }
16254
+ // For other errors, also suppress but log if console logging is enabled
16100
16255
  if (effectiveConfig.enableConsoleLog) {
16101
- console.warn('[SignOz] Span export timeout - check if SignOz endpoint is reachable:', effectiveConfig.url);
16256
+ console.warn('[SignOz] Span export error (suppressed):', errorMessage);
16102
16257
  }
16103
- // Call callback with success to prevent error propagation
16104
16258
  resultCallback({ code: 0 });
16105
16259
  return;
16106
16260
  }
16261
+ resultCallback(result);
16262
+ });
16263
+ }
16264
+ catch (error) {
16265
+ // Catch any synchronous errors and suppress them
16266
+ if (effectiveConfig.enableConsoleLog) {
16267
+ console.warn('[SignOz] Span export exception (suppressed):', error);
16107
16268
  }
16108
- resultCallback(result);
16109
- });
16269
+ resultCallback({ code: 0 });
16270
+ }
16110
16271
  };
16111
16272
  // Set up the span processor with configuration
16112
16273
  const processor = new BatchSpanProcessor(exporter, {
16113
16274
  maxQueueSize: effectiveConfig.batchSpanProcessorConfig.maxQueueSize,
16114
16275
  scheduledDelayMillis: effectiveConfig.batchSpanProcessorConfig.scheduledDelayMillis,
16115
- exportTimeoutMillis: effectiveConfig.batchSpanProcessorConfig.exportTimeoutMillis
16276
+ exportTimeoutMillis: effectiveConfig.batchSpanProcessorConfig.exportTimeoutMillis,
16277
+ maxExportBatchSize: effectiveConfig.batchSpanProcessorConfig.maxExportBatchSize
16116
16278
  });
16117
16279
  // Create and configure the WebTracerProvider
16118
16280
  const provider = new WebTracerProvider({
@@ -16169,7 +16331,11 @@ function initializeSignOzTracing(config) {
16169
16331
  }
16170
16332
  // Tambahkan error tracking
16171
16333
  if (effectiveConfig.enableErrorTracking) {
16172
- addErrorTracking(effectiveConfig.enableConsoleLog);
16334
+ addErrorTracking({
16335
+ enableConsoleLog: effectiveConfig.enableConsoleLog,
16336
+ trackNetworkErrors: effectiveConfig.trackNetworkErrors,
16337
+ ignoreNetworkErrorUrls: effectiveConfig.ignoreNetworkErrorUrls
16338
+ });
16173
16339
  }
16174
16340
  // Tambahkan navigation tracking
16175
16341
  if (effectiveConfig.enableNavigationTracking) {
@@ -16197,7 +16363,8 @@ function initializeSignOzTracing(config) {
16197
16363
  enableErrorTracking: effectiveConfig.enableErrorTracking,
16198
16364
  enableNavigationTracking: effectiveConfig.enableNavigationTracking,
16199
16365
  enableWebSocketLogging: effectiveConfig.enableWebSocketLogging,
16200
- logWebSocketMessages: effectiveConfig.logWebSocketMessages
16366
+ logWebSocketMessages: effectiveConfig.logWebSocketMessages,
16367
+ trackNetworkErrors: effectiveConfig.trackNetworkErrors
16201
16368
  });
16202
16369
  console.log('SignOz: Tracing berhasil diinisialisasi');
16203
16370
  }