@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.d.ts CHANGED
@@ -24,6 +24,8 @@ interface SignOzConfig {
24
24
  enableConsoleLog?: boolean;
25
25
  enableWebSocketLogging?: boolean;
26
26
  logWebSocketMessages?: boolean;
27
+ trackNetworkErrors?: boolean;
28
+ ignoreNetworkErrorUrls?: (string | RegExp)[];
27
29
  }
28
30
  declare global {
29
31
  interface Window {
package/dist/index.esm.js CHANGED
@@ -15548,23 +15548,75 @@ function addXHRLogging(config) {
15548
15548
  };
15549
15549
  }
15550
15550
  // Fungsi untuk menambahkan error tracking
15551
- function addErrorTracking(enableConsoleLog = false) {
15551
+ function addErrorTracking(config) {
15552
+ // Helper function to check if URL should be ignored
15553
+ const shouldIgnoreUrl = (url) => {
15554
+ if (!url)
15555
+ return false;
15556
+ return config.ignoreNetworkErrorUrls.some(pattern => {
15557
+ if (pattern instanceof RegExp) {
15558
+ return pattern.test(url);
15559
+ }
15560
+ return url.includes(pattern);
15561
+ });
15562
+ };
15552
15563
  // Track unhandled errors
15553
15564
  window.addEventListener('error', (event) => {
15554
15565
  var _a, _b;
15555
- // Skip SignOz internal timeout errors
15566
+ // Skip SignOz internal timeout errors and network errors
15556
15567
  const errorMessage = event.message || '';
15557
15568
  const errorStack = ((_a = event.error) === null || _a === void 0 ? void 0 : _a.stack) || '';
15558
- const isSignOzTimeout = (errorMessage.includes('Timeout') &&
15569
+ const errorFilename = event.filename || '';
15570
+ const isSignOzTimeout = ((errorMessage.includes('Timeout') || errorMessage.includes('timeout') || errorMessage.includes('ETIMEDOUT')) &&
15559
15571
  (errorMessage.includes('BatchSpanProcessor') ||
15572
+ errorMessage.includes('OTLP') ||
15573
+ errorMessage.includes('exporter') ||
15560
15574
  errorStack.includes('BatchSpanProcessor') ||
15575
+ errorStack.includes('OTLPTraceExporter') ||
15561
15576
  errorStack.includes('zone.js') ||
15562
- errorStack.includes('SignOz')));
15563
- if (isSignOzTimeout) {
15564
- if (enableConsoleLog) {
15577
+ errorStack.includes('SignOz') ||
15578
+ errorFilename.includes('zone.js')));
15579
+ // Also skip generic timeout errors that might be from SignOz
15580
+ const isGenericTimeout = (errorMessage === 'Timeout' ||
15581
+ errorMessage === 'timeout' ||
15582
+ (errorMessage.includes('Timeout') && errorStack.includes('zone.js')));
15583
+ if (isSignOzTimeout || isGenericTimeout) {
15584
+ if (config.enableConsoleLog) {
15565
15585
  console.warn('[SignOz] Span export timeout detected (safe to ignore - not tracking this error)');
15566
15586
  }
15567
15587
  event.preventDefault(); // Prevent the error from propagating
15588
+ event.stopPropagation(); // Stop event bubbling
15589
+ event.stopImmediatePropagation(); // Stop other listeners
15590
+ return;
15591
+ }
15592
+ // Skip network errors if trackNetworkErrors is disabled
15593
+ if (!config.trackNetworkErrors) {
15594
+ const isNetworkError = (errorMessage.includes('XHR request failed') ||
15595
+ errorMessage.includes('Failed to fetch') ||
15596
+ errorMessage.includes('Network request failed') ||
15597
+ errorMessage.includes('NetworkError') ||
15598
+ errorMessage.includes('net::ERR_') ||
15599
+ errorStack.includes('XMLHttpRequest') ||
15600
+ errorStack.includes('fetch'));
15601
+ if (isNetworkError) {
15602
+ if (config.enableConsoleLog) {
15603
+ console.warn('[SignOz] Network error detected (not tracking - trackNetworkErrors is disabled)');
15604
+ }
15605
+ event.preventDefault();
15606
+ event.stopPropagation();
15607
+ event.stopImmediatePropagation();
15608
+ return;
15609
+ }
15610
+ }
15611
+ // Check if URL should be ignored
15612
+ const errorUrl = event.filename || '';
15613
+ if (shouldIgnoreUrl(errorUrl)) {
15614
+ if (config.enableConsoleLog) {
15615
+ console.warn('[SignOz] Error from ignored URL (not tracking):', errorUrl);
15616
+ }
15617
+ event.preventDefault();
15618
+ event.stopPropagation();
15619
+ event.stopImmediatePropagation();
15568
15620
  return;
15569
15621
  }
15570
15622
  const tracer = trace.getTracer('error-tracker');
@@ -15585,7 +15637,7 @@ function addErrorTracking(enableConsoleLog = false) {
15585
15637
  span.setAttribute('error.name', event.error.name || 'Error');
15586
15638
  }
15587
15639
  span.setStatus({ code: SpanStatusCode.ERROR, message: event.message });
15588
- if (enableConsoleLog) {
15640
+ if (config.enableConsoleLog) {
15589
15641
  console.error('[SignOz] Unhandled Error:', {
15590
15642
  message: event.message,
15591
15643
  filename: event.filename,
@@ -15603,17 +15655,45 @@ function addErrorTracking(enableConsoleLog = false) {
15603
15655
  const reason = String(event.reason);
15604
15656
  const stack = event.reason instanceof Error ? (event.reason.stack || '') : '';
15605
15657
  // Check if this is a SignOz internal timeout error
15606
- const isSignOzTimeout = (reason.includes('Timeout') &&
15658
+ const isSignOzTimeout = ((reason.includes('Timeout') || reason.includes('timeout') || reason.includes('ETIMEDOUT')) &&
15607
15659
  (reason.includes('BatchSpanProcessor') ||
15660
+ reason.includes('OTLP') ||
15661
+ reason.includes('exporter') ||
15608
15662
  stack.includes('BatchSpanProcessor') ||
15663
+ stack.includes('OTLPTraceExporter') ||
15609
15664
  stack.includes('zone.js')));
15610
- if (isSignOzTimeout) {
15611
- if (enableConsoleLog) {
15665
+ // Also skip generic timeout errors that might be from SignOz
15666
+ const isGenericTimeout = (reason === 'Timeout' ||
15667
+ reason === 'timeout' ||
15668
+ (reason.includes('Timeout') && stack.includes('zone.js')));
15669
+ if (isSignOzTimeout || isGenericTimeout) {
15670
+ if (config.enableConsoleLog) {
15612
15671
  console.warn('[SignOz] Span export timeout (this is usually safe to ignore - check if SignOz endpoint is reachable)');
15613
15672
  }
15614
15673
  event.preventDefault(); // Prevent the error from being logged
15674
+ event.stopPropagation(); // Stop event bubbling
15675
+ event.stopImmediatePropagation(); // Stop other listeners
15615
15676
  return;
15616
15677
  }
15678
+ // Skip network errors if trackNetworkErrors is disabled
15679
+ if (!config.trackNetworkErrors) {
15680
+ const isNetworkError = (reason.includes('XHR request failed') ||
15681
+ reason.includes('Failed to fetch') ||
15682
+ reason.includes('Network request failed') ||
15683
+ reason.includes('NetworkError') ||
15684
+ reason.includes('net::ERR_') ||
15685
+ stack.includes('XMLHttpRequest') ||
15686
+ stack.includes('fetch'));
15687
+ if (isNetworkError) {
15688
+ if (config.enableConsoleLog) {
15689
+ console.warn('[SignOz] Network error in promise (not tracking - trackNetworkErrors is disabled)');
15690
+ }
15691
+ event.preventDefault();
15692
+ event.stopPropagation();
15693
+ event.stopImmediatePropagation();
15694
+ return;
15695
+ }
15696
+ }
15617
15697
  const tracer = trace.getTracer('error-tracker');
15618
15698
  const span = tracer.startSpan('Unhandled Promise Rejection');
15619
15699
  span.setAttribute('error.type', 'unhandled_rejection');
@@ -15630,7 +15710,7 @@ function addErrorTracking(enableConsoleLog = false) {
15630
15710
  span.setAttribute('error.name', event.reason.name || 'Error');
15631
15711
  }
15632
15712
  span.setStatus({ code: SpanStatusCode.ERROR, message: String(event.reason) });
15633
- if (enableConsoleLog) {
15713
+ if (config.enableConsoleLog) {
15634
15714
  console.error('[SignOz] Unhandled Promise Rejection:', event.reason, 'on page', window.location.pathname);
15635
15715
  }
15636
15716
  span.end();
@@ -15644,14 +15724,39 @@ function addErrorTracking(enableConsoleLog = false) {
15644
15724
  // Skip SignOz internal timeout errors
15645
15725
  const errorMessage = error.message || String(error);
15646
15726
  const errorStack = error.stack || '';
15647
- const isSignOzTimeout = (errorMessage.includes('Timeout') &&
15648
- (errorStack.includes('BatchSpanProcessor') || errorStack.includes('zone.js')));
15649
- if (isSignOzTimeout) {
15650
- if (enableConsoleLog) {
15727
+ const isSignOzTimeout = ((errorMessage.includes('Timeout') || errorMessage.includes('timeout') || errorMessage.includes('ETIMEDOUT')) &&
15728
+ (errorMessage.includes('BatchSpanProcessor') ||
15729
+ errorMessage.includes('OTLP') ||
15730
+ errorMessage.includes('exporter') ||
15731
+ errorStack.includes('BatchSpanProcessor') ||
15732
+ errorStack.includes('OTLPTraceExporter') ||
15733
+ errorStack.includes('zone.js')));
15734
+ // Also skip generic timeout errors
15735
+ const isGenericTimeout = (errorMessage === 'Timeout' ||
15736
+ errorMessage === 'timeout' ||
15737
+ (errorMessage.includes('Timeout') && errorStack.includes('zone.js')));
15738
+ if (isSignOzTimeout || isGenericTimeout) {
15739
+ if (config.enableConsoleLog) {
15651
15740
  console.warn('[SignOz] Zone.js caught span export timeout (safe to ignore)');
15652
15741
  }
15653
15742
  return; // Don't track this error
15654
15743
  }
15744
+ // Skip network errors if trackNetworkErrors is disabled
15745
+ if (!config.trackNetworkErrors) {
15746
+ const isNetworkError = (errorMessage.includes('XHR request failed') ||
15747
+ errorMessage.includes('Failed to fetch') ||
15748
+ errorMessage.includes('Network request failed') ||
15749
+ errorMessage.includes('NetworkError') ||
15750
+ errorMessage.includes('net::ERR_') ||
15751
+ errorStack.includes('XMLHttpRequest') ||
15752
+ errorStack.includes('fetch'));
15753
+ if (isNetworkError) {
15754
+ if (config.enableConsoleLog) {
15755
+ console.warn('[SignOz] Zone.js caught network error (not tracking - trackNetworkErrors is disabled)');
15756
+ }
15757
+ return;
15758
+ }
15759
+ }
15655
15760
  const tracer = trace.getTracer('error-tracker');
15656
15761
  const span = tracer.startSpan('Zone.js Error');
15657
15762
  span.setAttribute('error.type', 'zone_error');
@@ -15667,7 +15772,7 @@ function addErrorTracking(enableConsoleLog = false) {
15667
15772
  }
15668
15773
  span.recordException(error);
15669
15774
  span.setStatus({ code: SpanStatusCode.ERROR, message: error.message || String(error) });
15670
- if (enableConsoleLog) {
15775
+ if (config.enableConsoleLog) {
15671
15776
  console.error('[SignOz] Zone.js Error:', error, 'on page', window.location.pathname);
15672
15777
  }
15673
15778
  span.end();
@@ -15690,6 +15795,16 @@ function addErrorTracking(enableConsoleLog = false) {
15690
15795
  // Just call original console.error without tracking
15691
15796
  return originalConsoleError.apply(console, args);
15692
15797
  }
15798
+ // Skip network errors if trackNetworkErrors is disabled
15799
+ const isNetworkError = (errorMessage.includes('XHR request failed') ||
15800
+ errorMessage.includes('Failed to fetch') ||
15801
+ errorMessage.includes('Network request failed') ||
15802
+ errorMessage.includes('NetworkError') ||
15803
+ errorMessage.includes('net::ERR_'));
15804
+ if (isNetworkError && !config.trackNetworkErrors) {
15805
+ // Just call original console.error without tracking
15806
+ return originalConsoleError.apply(console, args);
15807
+ }
15693
15808
  if (errorMessage.includes('React') || errorMessage.includes('TypeError') || errorMessage.includes('Uncaught')) {
15694
15809
  const tracer = trace.getTracer('error-tracker');
15695
15810
  const span = tracer.startSpan('Console Error');
@@ -16019,6 +16134,34 @@ function addWebSocketLogging(config) {
16019
16134
  */
16020
16135
  function initializeSignOzTracing(config) {
16021
16136
  try {
16137
+ // Install global error suppression for SignOz timeout errors FIRST
16138
+ // This must be done before any other initialization
16139
+ const originalWindowError = window.onerror;
16140
+ window.onerror = function (message, source, lineno, colno, error) {
16141
+ const errorMessage = String(message);
16142
+ const errorStack = (error === null || error === void 0 ? void 0 : error.stack) || '';
16143
+ // Suppress SignOz timeout errors globally
16144
+ const isSignOzTimeout = ((errorMessage.includes('Timeout') || errorMessage.includes('timeout') || errorMessage.includes('ETIMEDOUT')) &&
16145
+ (errorMessage.includes('BatchSpanProcessor') ||
16146
+ errorMessage.includes('OTLP') ||
16147
+ errorMessage.includes('exporter') ||
16148
+ errorStack.includes('BatchSpanProcessor') ||
16149
+ errorStack.includes('OTLPTraceExporter') ||
16150
+ errorStack.includes('zone.js') ||
16151
+ (source === null || source === void 0 ? void 0 : source.includes('zone.js'))));
16152
+ const isGenericTimeout = (errorMessage === 'Timeout' ||
16153
+ errorMessage === 'timeout' ||
16154
+ (errorMessage.includes('Timeout') && errorStack.includes('zone.js')));
16155
+ if (isSignOzTimeout || isGenericTimeout) {
16156
+ // Suppress completely - don't log, don't propagate
16157
+ return true; // Returning true prevents default error handling
16158
+ }
16159
+ // Call original handler for other errors
16160
+ if (originalWindowError) {
16161
+ return originalWindowError.call(window, message, source, lineno, colno, error);
16162
+ }
16163
+ return false;
16164
+ };
16022
16165
  // Gabungkan konfigurasi dari parameter, process.env, dan window
16023
16166
  const effectiveConfig = {
16024
16167
  serviceName: (config === null || config === void 0 ? void 0 : config.serviceName) || getConfigValue('REACT_APP_SIGNOZ_SERVICE_NAME'),
@@ -16033,9 +16176,9 @@ function initializeSignOzTracing(config) {
16033
16176
  })(),
16034
16177
  batchSpanProcessorConfig: (config === null || config === void 0 ? void 0 : config.batchSpanProcessorConfig) || {
16035
16178
  maxQueueSize: 100,
16036
- scheduledDelayMillis: 5000,
16037
- exportTimeoutMillis: 30000, // Reduced to 30 seconds to fail faster
16038
- maxExportBatchSize: 50 // Smaller batches to avoid timeouts
16179
+ scheduledDelayMillis: 3000, // Kirim lebih cepat (3 detik)
16180
+ exportTimeoutMillis: 10000, // Timeout lebih pendek (10 detik)
16181
+ maxExportBatchSize: 30 // Batch lebih kecil untuk menghindari timeout
16039
16182
  },
16040
16183
  allowedOrigins: (config === null || config === void 0 ? void 0 : config.allowedOrigins) || parseAllowedOrigins(getConfigValue('REACT_APP_SIGNOZ_ALLOWED_ORIGINS')),
16041
16184
  enableRequestLogging: (config === null || config === void 0 ? void 0 : config.enableRequestLogging) !== undefined ? config.enableRequestLogging : (getConfigValue('REACT_APP_SIGNOZ_ENABLE_REQUEST_LOGGING') === 'true' || true),
@@ -16047,7 +16190,9 @@ function initializeSignOzTracing(config) {
16047
16190
  enableNavigationTracking: (config === null || config === void 0 ? void 0 : config.enableNavigationTracking) !== undefined ? config.enableNavigationTracking : (getConfigValue('REACT_APP_SIGNOZ_ENABLE_NAVIGATION_TRACKING') === 'true'),
16048
16191
  enableConsoleLog: (config === null || config === void 0 ? void 0 : config.enableConsoleLog) !== undefined ? config.enableConsoleLog : (getConfigValue('REACT_APP_SIGNOZ_ENABLE_CONSOLE_LOG') === 'true'),
16049
16192
  enableWebSocketLogging: (config === null || config === void 0 ? void 0 : config.enableWebSocketLogging) !== undefined ? config.enableWebSocketLogging : (getConfigValue('REACT_APP_SIGNOZ_ENABLE_WEBSOCKET_LOGGING') === 'true'),
16050
- logWebSocketMessages: (config === null || config === void 0 ? void 0 : config.logWebSocketMessages) !== undefined ? config.logWebSocketMessages : (getConfigValue('REACT_APP_SIGNOZ_LOG_WEBSOCKET_MESSAGES') === 'true')
16193
+ logWebSocketMessages: (config === null || config === void 0 ? void 0 : config.logWebSocketMessages) !== undefined ? config.logWebSocketMessages : (getConfigValue('REACT_APP_SIGNOZ_LOG_WEBSOCKET_MESSAGES') === 'true'),
16194
+ trackNetworkErrors: (config === null || config === void 0 ? void 0 : config.trackNetworkErrors) !== undefined ? config.trackNetworkErrors : (getConfigValue('REACT_APP_SIGNOZ_TRACK_NETWORK_ERRORS') === 'true'),
16195
+ ignoreNetworkErrorUrls: (config === null || config === void 0 ? void 0 : config.ignoreNetworkErrorUrls) || []
16051
16196
  };
16052
16197
  // Validasi konfigurasi
16053
16198
  const { isValid, missingFields } = validateConfig(effectiveConfig);
@@ -16067,32 +16212,49 @@ function initializeSignOzTracing(config) {
16067
16212
  const exporter = new OTLPTraceExporter({
16068
16213
  url: effectiveConfig.url,
16069
16214
  headers: effectiveConfig.headers,
16070
- timeoutMillis: 30000 // Reduced to 30 seconds to fail faster
16215
+ timeoutMillis: 10000 // Timeout lebih pendek (10 detik)
16071
16216
  });
16072
- // Wrap exporter to suppress timeout errors
16217
+ // Wrap exporter to suppress timeout errors completely
16073
16218
  const originalExport = exporter.export.bind(exporter);
16074
16219
  exporter.export = function (spans, resultCallback) {
16075
- originalExport(spans, (result) => {
16076
- // Suppress timeout errors to prevent console noise
16077
- if (result.error) {
16078
- const errorMessage = String(result.error);
16079
- if (errorMessage.includes('Timeout') || errorMessage.includes('timeout')) {
16220
+ // Wrap in try-catch to prevent any errors from propagating
16221
+ try {
16222
+ originalExport(spans, (result) => {
16223
+ // Suppress ALL errors to prevent console noise and Zone.js catching them
16224
+ if (result.error) {
16225
+ const errorMessage = String(result.error);
16226
+ if (errorMessage.includes('Timeout') || errorMessage.includes('timeout') || errorMessage.includes('ETIMEDOUT')) {
16227
+ if (effectiveConfig.enableConsoleLog) {
16228
+ console.warn('[SignOz] Span export timeout - check if SignOz endpoint is reachable:', effectiveConfig.url);
16229
+ }
16230
+ // Call callback with success to prevent error propagation
16231
+ resultCallback({ code: 0 });
16232
+ return;
16233
+ }
16234
+ // For other errors, also suppress but log if console logging is enabled
16080
16235
  if (effectiveConfig.enableConsoleLog) {
16081
- console.warn('[SignOz] Span export timeout - check if SignOz endpoint is reachable:', effectiveConfig.url);
16236
+ console.warn('[SignOz] Span export error (suppressed):', errorMessage);
16082
16237
  }
16083
- // Call callback with success to prevent error propagation
16084
16238
  resultCallback({ code: 0 });
16085
16239
  return;
16086
16240
  }
16241
+ resultCallback(result);
16242
+ });
16243
+ }
16244
+ catch (error) {
16245
+ // Catch any synchronous errors and suppress them
16246
+ if (effectiveConfig.enableConsoleLog) {
16247
+ console.warn('[SignOz] Span export exception (suppressed):', error);
16087
16248
  }
16088
- resultCallback(result);
16089
- });
16249
+ resultCallback({ code: 0 });
16250
+ }
16090
16251
  };
16091
16252
  // Set up the span processor with configuration
16092
16253
  const processor = new BatchSpanProcessor(exporter, {
16093
16254
  maxQueueSize: effectiveConfig.batchSpanProcessorConfig.maxQueueSize,
16094
16255
  scheduledDelayMillis: effectiveConfig.batchSpanProcessorConfig.scheduledDelayMillis,
16095
- exportTimeoutMillis: effectiveConfig.batchSpanProcessorConfig.exportTimeoutMillis
16256
+ exportTimeoutMillis: effectiveConfig.batchSpanProcessorConfig.exportTimeoutMillis,
16257
+ maxExportBatchSize: effectiveConfig.batchSpanProcessorConfig.maxExportBatchSize
16096
16258
  });
16097
16259
  // Create and configure the WebTracerProvider
16098
16260
  const provider = new WebTracerProvider({
@@ -16149,7 +16311,11 @@ function initializeSignOzTracing(config) {
16149
16311
  }
16150
16312
  // Tambahkan error tracking
16151
16313
  if (effectiveConfig.enableErrorTracking) {
16152
- addErrorTracking(effectiveConfig.enableConsoleLog);
16314
+ addErrorTracking({
16315
+ enableConsoleLog: effectiveConfig.enableConsoleLog,
16316
+ trackNetworkErrors: effectiveConfig.trackNetworkErrors,
16317
+ ignoreNetworkErrorUrls: effectiveConfig.ignoreNetworkErrorUrls
16318
+ });
16153
16319
  }
16154
16320
  // Tambahkan navigation tracking
16155
16321
  if (effectiveConfig.enableNavigationTracking) {
@@ -16177,7 +16343,8 @@ function initializeSignOzTracing(config) {
16177
16343
  enableErrorTracking: effectiveConfig.enableErrorTracking,
16178
16344
  enableNavigationTracking: effectiveConfig.enableNavigationTracking,
16179
16345
  enableWebSocketLogging: effectiveConfig.enableWebSocketLogging,
16180
- logWebSocketMessages: effectiveConfig.logWebSocketMessages
16346
+ logWebSocketMessages: effectiveConfig.logWebSocketMessages,
16347
+ trackNetworkErrors: effectiveConfig.trackNetworkErrors
16181
16348
  });
16182
16349
  console.log('SignOz: Tracing berhasil diinisialisasi');
16183
16350
  }