@echoteam/signoz-react 1.2.11 → 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,10 +15568,77 @@ 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
- var _a;
15585
+ var _a, _b;
15586
+ // Skip SignOz internal timeout errors and network errors
15587
+ const errorMessage = event.message || '';
15588
+ const errorStack = ((_a = event.error) === null || _a === void 0 ? void 0 : _a.stack) || '';
15589
+ const errorFilename = event.filename || '';
15590
+ const isSignOzTimeout = ((errorMessage.includes('Timeout') || errorMessage.includes('timeout') || errorMessage.includes('ETIMEDOUT')) &&
15591
+ (errorMessage.includes('BatchSpanProcessor') ||
15592
+ errorMessage.includes('OTLP') ||
15593
+ errorMessage.includes('exporter') ||
15594
+ errorStack.includes('BatchSpanProcessor') ||
15595
+ errorStack.includes('OTLPTraceExporter') ||
15596
+ errorStack.includes('zone.js') ||
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) {
15605
+ console.warn('[SignOz] Span export timeout detected (safe to ignore - not tracking this error)');
15606
+ }
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();
15640
+ return;
15641
+ }
15575
15642
  const tracer = trace.getTracer('error-tracker');
15576
15643
  const span = tracer.startSpan('Unhandled Error');
15577
15644
  span.setAttribute('error.type', 'unhandled');
@@ -15590,13 +15657,13 @@ function addErrorTracking(enableConsoleLog = false) {
15590
15657
  span.setAttribute('error.name', event.error.name || 'Error');
15591
15658
  }
15592
15659
  span.setStatus({ code: SpanStatusCode.ERROR, message: event.message });
15593
- if (enableConsoleLog) {
15660
+ if (config.enableConsoleLog) {
15594
15661
  console.error('[SignOz] Unhandled Error:', {
15595
15662
  message: event.message,
15596
15663
  filename: event.filename,
15597
15664
  lineno: event.lineno,
15598
15665
  colno: event.colno,
15599
- stack: (_a = event.error) === null || _a === void 0 ? void 0 : _a.stack,
15666
+ stack: (_b = event.error) === null || _b === void 0 ? void 0 : _b.stack,
15600
15667
  page: window.location.pathname
15601
15668
  });
15602
15669
  }
@@ -15608,17 +15675,45 @@ function addErrorTracking(enableConsoleLog = false) {
15608
15675
  const reason = String(event.reason);
15609
15676
  const stack = event.reason instanceof Error ? (event.reason.stack || '') : '';
15610
15677
  // Check if this is a SignOz internal timeout error
15611
- const isSignOzTimeout = (reason.includes('Timeout') &&
15678
+ const isSignOzTimeout = ((reason.includes('Timeout') || reason.includes('timeout') || reason.includes('ETIMEDOUT')) &&
15612
15679
  (reason.includes('BatchSpanProcessor') ||
15680
+ reason.includes('OTLP') ||
15681
+ reason.includes('exporter') ||
15613
15682
  stack.includes('BatchSpanProcessor') ||
15683
+ stack.includes('OTLPTraceExporter') ||
15614
15684
  stack.includes('zone.js')));
15615
- if (isSignOzTimeout) {
15616
- 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) {
15617
15691
  console.warn('[SignOz] Span export timeout (this is usually safe to ignore - check if SignOz endpoint is reachable)');
15618
15692
  }
15619
15693
  event.preventDefault(); // Prevent the error from being logged
15694
+ event.stopPropagation(); // Stop event bubbling
15695
+ event.stopImmediatePropagation(); // Stop other listeners
15620
15696
  return;
15621
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
+ }
15622
15717
  const tracer = trace.getTracer('error-tracker');
15623
15718
  const span = tracer.startSpan('Unhandled Promise Rejection');
15624
15719
  span.setAttribute('error.type', 'unhandled_rejection');
@@ -15635,7 +15730,7 @@ function addErrorTracking(enableConsoleLog = false) {
15635
15730
  span.setAttribute('error.name', event.reason.name || 'Error');
15636
15731
  }
15637
15732
  span.setStatus({ code: SpanStatusCode.ERROR, message: String(event.reason) });
15638
- if (enableConsoleLog) {
15733
+ if (config.enableConsoleLog) {
15639
15734
  console.error('[SignOz] Unhandled Promise Rejection:', event.reason, 'on page', window.location.pathname);
15640
15735
  }
15641
15736
  span.end();
@@ -15649,14 +15744,39 @@ function addErrorTracking(enableConsoleLog = false) {
15649
15744
  // Skip SignOz internal timeout errors
15650
15745
  const errorMessage = error.message || String(error);
15651
15746
  const errorStack = error.stack || '';
15652
- const isSignOzTimeout = (errorMessage.includes('Timeout') &&
15653
- (errorStack.includes('BatchSpanProcessor') || errorStack.includes('zone.js')));
15654
- if (isSignOzTimeout) {
15655
- 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) {
15656
15760
  console.warn('[SignOz] Zone.js caught span export timeout (safe to ignore)');
15657
15761
  }
15658
15762
  return; // Don't track this error
15659
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
+ }
15660
15780
  const tracer = trace.getTracer('error-tracker');
15661
15781
  const span = tracer.startSpan('Zone.js Error');
15662
15782
  span.setAttribute('error.type', 'zone_error');
@@ -15672,7 +15792,7 @@ function addErrorTracking(enableConsoleLog = false) {
15672
15792
  }
15673
15793
  span.recordException(error);
15674
15794
  span.setStatus({ code: SpanStatusCode.ERROR, message: error.message || String(error) });
15675
- if (enableConsoleLog) {
15795
+ if (config.enableConsoleLog) {
15676
15796
  console.error('[SignOz] Zone.js Error:', error, 'on page', window.location.pathname);
15677
15797
  }
15678
15798
  span.end();
@@ -15686,6 +15806,25 @@ function addErrorTracking(enableConsoleLog = false) {
15686
15806
  console.error = function (...args) {
15687
15807
  // Check if this is a React error
15688
15808
  const errorMessage = args.map(arg => String(arg)).join(' ');
15809
+ // Skip SignOz internal errors
15810
+ const isSignOzError = (errorMessage.includes('Timeout') &&
15811
+ (errorMessage.includes('BatchSpanProcessor') ||
15812
+ errorMessage.includes('zone.js') ||
15813
+ errorMessage.includes('SignOz')));
15814
+ if (isSignOzError) {
15815
+ // Just call original console.error without tracking
15816
+ return originalConsoleError.apply(console, args);
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
+ }
15689
15828
  if (errorMessage.includes('React') || errorMessage.includes('TypeError') || errorMessage.includes('Uncaught')) {
15690
15829
  const tracer = trace.getTracer('error-tracker');
15691
15830
  const span = tracer.startSpan('Console Error');
@@ -16015,6 +16154,34 @@ function addWebSocketLogging(config) {
16015
16154
  */
16016
16155
  function initializeSignOzTracing(config) {
16017
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
+ };
16018
16185
  // Gabungkan konfigurasi dari parameter, process.env, dan window
16019
16186
  const effectiveConfig = {
16020
16187
  serviceName: (config === null || config === void 0 ? void 0 : config.serviceName) || getConfigValue('REACT_APP_SIGNOZ_SERVICE_NAME'),
@@ -16029,9 +16196,9 @@ function initializeSignOzTracing(config) {
16029
16196
  })(),
16030
16197
  batchSpanProcessorConfig: (config === null || config === void 0 ? void 0 : config.batchSpanProcessorConfig) || {
16031
16198
  maxQueueSize: 100,
16032
- scheduledDelayMillis: 5000,
16033
- exportTimeoutMillis: 60000, // Increased to 60 seconds
16034
- 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
16035
16202
  },
16036
16203
  allowedOrigins: (config === null || config === void 0 ? void 0 : config.allowedOrigins) || parseAllowedOrigins(getConfigValue('REACT_APP_SIGNOZ_ALLOWED_ORIGINS')),
16037
16204
  enableRequestLogging: (config === null || config === void 0 ? void 0 : config.enableRequestLogging) !== undefined ? config.enableRequestLogging : (getConfigValue('REACT_APP_SIGNOZ_ENABLE_REQUEST_LOGGING') === 'true' || true),
@@ -16043,7 +16210,9 @@ function initializeSignOzTracing(config) {
16043
16210
  enableNavigationTracking: (config === null || config === void 0 ? void 0 : config.enableNavigationTracking) !== undefined ? config.enableNavigationTracking : (getConfigValue('REACT_APP_SIGNOZ_ENABLE_NAVIGATION_TRACKING') === 'true'),
16044
16211
  enableConsoleLog: (config === null || config === void 0 ? void 0 : config.enableConsoleLog) !== undefined ? config.enableConsoleLog : (getConfigValue('REACT_APP_SIGNOZ_ENABLE_CONSOLE_LOG') === 'true'),
16045
16212
  enableWebSocketLogging: (config === null || config === void 0 ? void 0 : config.enableWebSocketLogging) !== undefined ? config.enableWebSocketLogging : (getConfigValue('REACT_APP_SIGNOZ_ENABLE_WEBSOCKET_LOGGING') === 'true'),
16046
- 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) || []
16047
16216
  };
16048
16217
  // Validasi konfigurasi
16049
16218
  const { isValid, missingFields } = validateConfig(effectiveConfig);
@@ -16059,17 +16228,53 @@ function initializeSignOzTracing(config) {
16059
16228
  'deployment.environment': effectiveConfig.environment,
16060
16229
  'service.namespace': effectiveConfig.serviceNamespace,
16061
16230
  });
16062
- // Set up the OTLP trace exporter
16231
+ // Set up the OTLP trace exporter with error handling
16063
16232
  const exporter = new OTLPTraceExporter({
16064
16233
  url: effectiveConfig.url,
16065
16234
  headers: effectiveConfig.headers,
16066
- timeoutMillis: 60000 // Set exporter timeout to 60 seconds
16235
+ timeoutMillis: 10000 // Timeout lebih pendek (10 detik)
16067
16236
  });
16237
+ // Wrap exporter to suppress timeout errors completely
16238
+ const originalExport = exporter.export.bind(exporter);
16239
+ exporter.export = function (spans, resultCallback) {
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
16255
+ if (effectiveConfig.enableConsoleLog) {
16256
+ console.warn('[SignOz] Span export error (suppressed):', errorMessage);
16257
+ }
16258
+ resultCallback({ code: 0 });
16259
+ return;
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);
16268
+ }
16269
+ resultCallback({ code: 0 });
16270
+ }
16271
+ };
16068
16272
  // Set up the span processor with configuration
16069
16273
  const processor = new BatchSpanProcessor(exporter, {
16070
16274
  maxQueueSize: effectiveConfig.batchSpanProcessorConfig.maxQueueSize,
16071
16275
  scheduledDelayMillis: effectiveConfig.batchSpanProcessorConfig.scheduledDelayMillis,
16072
- exportTimeoutMillis: effectiveConfig.batchSpanProcessorConfig.exportTimeoutMillis
16276
+ exportTimeoutMillis: effectiveConfig.batchSpanProcessorConfig.exportTimeoutMillis,
16277
+ maxExportBatchSize: effectiveConfig.batchSpanProcessorConfig.maxExportBatchSize
16073
16278
  });
16074
16279
  // Create and configure the WebTracerProvider
16075
16280
  const provider = new WebTracerProvider({
@@ -16126,7 +16331,11 @@ function initializeSignOzTracing(config) {
16126
16331
  }
16127
16332
  // Tambahkan error tracking
16128
16333
  if (effectiveConfig.enableErrorTracking) {
16129
- addErrorTracking(effectiveConfig.enableConsoleLog);
16334
+ addErrorTracking({
16335
+ enableConsoleLog: effectiveConfig.enableConsoleLog,
16336
+ trackNetworkErrors: effectiveConfig.trackNetworkErrors,
16337
+ ignoreNetworkErrorUrls: effectiveConfig.ignoreNetworkErrorUrls
16338
+ });
16130
16339
  }
16131
16340
  // Tambahkan navigation tracking
16132
16341
  if (effectiveConfig.enableNavigationTracking) {
@@ -16154,7 +16363,8 @@ function initializeSignOzTracing(config) {
16154
16363
  enableErrorTracking: effectiveConfig.enableErrorTracking,
16155
16364
  enableNavigationTracking: effectiveConfig.enableNavigationTracking,
16156
16365
  enableWebSocketLogging: effectiveConfig.enableWebSocketLogging,
16157
- logWebSocketMessages: effectiveConfig.logWebSocketMessages
16366
+ logWebSocketMessages: effectiveConfig.logWebSocketMessages,
16367
+ trackNetworkErrors: effectiveConfig.trackNetworkErrors
16158
16368
  });
16159
16369
  console.log('SignOz: Tracing berhasil diinisialisasi');
16160
16370
  }