@echoteam/signoz-react 1.2.1 → 1.2.2

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/README.md CHANGED
@@ -66,10 +66,13 @@ REACT_APP_SIGNOZ_LOG_REQUEST_BODY=true
66
66
  REACT_APP_SIGNOZ_LOG_RESPONSE_BODY=true
67
67
  REACT_APP_SIGNOZ_MAX_BODY_LOG_SIZE=10000
68
68
 
69
- # Konfigurasi Tracking (opsional, default: true)
70
- REACT_APP_SIGNOZ_ENABLE_DOCUMENT_LOAD=true
71
- REACT_APP_SIGNOZ_ENABLE_ERROR_TRACKING=true
72
- REACT_APP_SIGNOZ_ENABLE_NAVIGATION_TRACKING=true
69
+ # Konfigurasi Tracking (opsional)
70
+ REACT_APP_SIGNOZ_ENABLE_DOCUMENT_LOAD=false # default: false
71
+ REACT_APP_SIGNOZ_ENABLE_ERROR_TRACKING=true # default: true
72
+ REACT_APP_SIGNOZ_ENABLE_NAVIGATION_TRACKING=false # default: false
73
+
74
+ # Console Logging (opsional, default: false)
75
+ REACT_APP_SIGNOZ_ENABLE_CONSOLE_LOG=false
73
76
  ```
74
77
 
75
78
  > **Catatan untuk REACT_APP_SIGNOZ_ALLOWED_ORIGINS:**
@@ -131,9 +134,11 @@ initializeSignOzTracing({
131
134
  logResponseBody: true, // Log response body (default: true)
132
135
  maxBodyLogSize: 10000, // Maksimal 10KB per log (default: 10000)
133
136
  // Konfigurasi tracking
134
- enableDocumentLoad: true, // Track page load performance (default: true)
137
+ enableDocumentLoad: false, // Track page load performance (default: false)
135
138
  enableErrorTracking: true, // Track unhandled errors (default: true)
136
- enableNavigationTracking: true // Track route changes (default: true)
139
+ enableNavigationTracking: false, // Track route changes (default: false)
140
+ // Console logging (default: false, hanya kirim ke SignOz tanpa console.log)
141
+ enableConsoleLog: false // Set true untuk enable console.log di browser
137
142
  });
138
143
  ```
139
144
 
@@ -171,7 +176,7 @@ Library ini secara otomatis melog semua HTTP request dan response yang dilakukan
171
176
  3. Pilih trace yang ingin dilihat
172
177
  4. Lihat span attributes:
173
178
  - `http.request.body`: Body dari request (untuk POST/PUT/PATCH)
174
- - `http.response.body`: Body dari response
179
+ - `response.data`: Body dari response
175
180
  - `http.url`: URL endpoint
176
181
  - `http.method`: HTTP method
177
182
  - `http.status_code`: Status code response
@@ -452,9 +457,10 @@ Inisialisasi SignOz tracing untuk aplikasi React.
452
457
  - `logRequestBody` (opsional): Log request body untuk POST/PUT/PATCH (default: true)
453
458
  - `logResponseBody` (opsional): Log response body untuk semua request (default: true)
454
459
  - `maxBodyLogSize` (opsional): Maksimal ukuran body yang di-log dalam bytes (default: 10000)
455
- - `enableDocumentLoad` (opsional): Aktifkan document load instrumentation (default: true)
460
+ - `enableDocumentLoad` (opsional): Aktifkan document load instrumentation (default: false)
456
461
  - `enableErrorTracking` (opsional): Aktifkan automatic error tracking (default: true)
457
- - `enableNavigationTracking` (opsional): Aktifkan navigation/route tracking (default: true)
462
+ - `enableNavigationTracking` (opsional): Aktifkan navigation/route tracking (default: false)
463
+ - `enableConsoleLog` (opsional): Aktifkan console.log output di browser (default: false)
458
464
 
459
465
  ### `ErrorBoundary`
460
466
 
package/dist/index.d.ts CHANGED
@@ -20,6 +20,7 @@ interface SignOzConfig {
20
20
  enableDocumentLoad?: boolean;
21
21
  enableErrorTracking?: boolean;
22
22
  enableNavigationTracking?: boolean;
23
+ enableConsoleLog?: boolean;
23
24
  }
24
25
  declare global {
25
26
  interface Window {
package/dist/index.esm.js CHANGED
@@ -15318,6 +15318,8 @@ function addFetchLogging(config) {
15318
15318
  // Capture current page info
15319
15319
  const pageUrl = window.location.href;
15320
15320
  const pagePath = window.location.pathname;
15321
+ // Track start time
15322
+ const startTime = performance.now();
15321
15323
  const tracer = trace.getTracer('fetch-logger');
15322
15324
  const span = tracer.startSpan(`HTTP ${method} ${url}`);
15323
15325
  try {
@@ -15332,9 +15334,14 @@ function addFetchLogging(config) {
15332
15334
  if (config.logRequestBody && (init === null || init === void 0 ? void 0 : init.body) && ['POST', 'PUT', 'PATCH'].includes(method.toUpperCase())) {
15333
15335
  const bodyStr = truncateBody(init.body, config.maxBodyLogSize);
15334
15336
  span.setAttribute('http.request.body', bodyStr);
15335
- console.log(`[SignOz] ${method} Request to ${url} from page ${pagePath}:`, bodyStr);
15337
+ if (config.enableConsoleLog) {
15338
+ console.log(`[SignOz] ${method} Request to ${url} from page ${pagePath}:`, bodyStr);
15339
+ }
15336
15340
  }
15337
15341
  const response = await originalFetch.apply(this, args);
15342
+ // Calculate duration
15343
+ const duration = performance.now() - startTime;
15344
+ span.setAttribute('duration_ms', Math.round(duration));
15338
15345
  // Log response data
15339
15346
  span.setAttribute('http.status_code', response.status);
15340
15347
  if (config.logResponseBody && response.ok) {
@@ -15342,23 +15349,32 @@ function addFetchLogging(config) {
15342
15349
  try {
15343
15350
  const responseData = await clonedResponse.text();
15344
15351
  const truncatedData = truncateBody(responseData, config.maxBodyLogSize);
15345
- span.setAttribute('http.response.body', truncatedData);
15346
- console.log(`[SignOz] ${method} Response from ${url} (${response.status}) on page ${pagePath}:`, truncatedData);
15352
+ span.setAttribute('response.data', truncatedData);
15353
+ if (config.enableConsoleLog) {
15354
+ console.log(`[SignOz] ${method} Response from ${url} (${response.status}) on page ${pagePath} [${Math.round(duration)}ms]:`, truncatedData);
15355
+ }
15347
15356
  }
15348
15357
  catch (e) {
15349
- console.warn('[SignOz] Failed to read response body:', e);
15358
+ if (config.enableConsoleLog) {
15359
+ console.warn('[SignOz] Failed to read response body:', e);
15360
+ }
15350
15361
  }
15351
15362
  }
15352
- else if (!response.ok) {
15353
- console.log(`[SignOz] ${method} Request to ${url} from page ${pagePath} - Status: ${response.status}`);
15363
+ else if (!response.ok && config.enableConsoleLog) {
15364
+ console.log(`[SignOz] ${method} Request to ${url} from page ${pagePath} - Status: ${response.status} [${Math.round(duration)}ms]`);
15354
15365
  }
15355
15366
  span.setStatus({ code: SpanStatusCode.OK });
15356
15367
  return response;
15357
15368
  }
15358
15369
  catch (error) {
15370
+ // Calculate duration even on error
15371
+ const duration = performance.now() - startTime;
15372
+ span.setAttribute('duration_ms', Math.round(duration));
15359
15373
  span.recordException(error);
15360
15374
  span.setStatus({ code: SpanStatusCode.ERROR, message: error.message });
15361
- console.error(`[SignOz] ${method} Error for ${url} on page ${pagePath}:`, error);
15375
+ if (config.enableConsoleLog) {
15376
+ console.error(`[SignOz] ${method} Error for ${url} on page ${pagePath} [${Math.round(duration)}ms]:`, error);
15377
+ }
15362
15378
  throw error;
15363
15379
  }
15364
15380
  finally {
@@ -15375,6 +15391,7 @@ function addXHRLogging(config) {
15375
15391
  const xhr = new OriginalXHR();
15376
15392
  let method = '';
15377
15393
  let url = '';
15394
+ let startTime = 0;
15378
15395
  // Capture current page info when XHR is created
15379
15396
  const pageUrl = window.location.href;
15380
15397
  const pagePath = window.location.pathname;
@@ -15386,6 +15403,8 @@ function addXHRLogging(config) {
15386
15403
  };
15387
15404
  const originalSend = xhr.send;
15388
15405
  xhr.send = function (body) {
15406
+ // Track start time
15407
+ startTime = performance.now();
15389
15408
  const tracer = trace.getTracer('xhr-logger');
15390
15409
  const span = tracer.startSpan(`HTTP ${method} ${url}`);
15391
15410
  span.setAttribute('http.url', url);
@@ -15399,27 +15418,39 @@ function addXHRLogging(config) {
15399
15418
  if (config.logRequestBody && body && ['POST', 'PUT', 'PATCH'].includes(method.toUpperCase())) {
15400
15419
  const bodyStr = truncateBody(body, config.maxBodyLogSize);
15401
15420
  span.setAttribute('http.request.body', bodyStr);
15402
- console.log(`[SignOz] ${method} Request to ${url} from page ${pagePath}:`, bodyStr);
15421
+ if (config.enableConsoleLog) {
15422
+ console.log(`[SignOz] ${method} Request to ${url} from page ${pagePath}:`, bodyStr);
15423
+ }
15403
15424
  }
15404
15425
  this.addEventListener('load', function () {
15426
+ // Calculate duration
15427
+ const duration = performance.now() - startTime;
15428
+ span.setAttribute('duration_ms', Math.round(duration));
15405
15429
  span.setAttribute('http.status_code', xhr.status);
15406
15430
  // Log response body
15407
15431
  if (config.logResponseBody && xhr.status >= 200 && xhr.status < 300) {
15408
15432
  const responseData = xhr.responseText;
15409
15433
  const truncatedData = truncateBody(responseData, config.maxBodyLogSize);
15410
- span.setAttribute('http.response.body', truncatedData);
15411
- console.log(`[SignOz] ${method} Response from ${url} (${xhr.status}) on page ${pagePath}:`, truncatedData);
15434
+ span.setAttribute('response.data', truncatedData);
15435
+ if (config.enableConsoleLog) {
15436
+ console.log(`[SignOz] ${method} Response from ${url} (${xhr.status}) on page ${pagePath} [${Math.round(duration)}ms]:`, truncatedData);
15437
+ }
15412
15438
  }
15413
- else if (xhr.status >= 300) {
15414
- console.log(`[SignOz] ${method} Request to ${url} from page ${pagePath} - Status: ${xhr.status}`);
15439
+ else if (xhr.status >= 300 && config.enableConsoleLog) {
15440
+ console.log(`[SignOz] ${method} Request to ${url} from page ${pagePath} - Status: ${xhr.status} [${Math.round(duration)}ms]`);
15415
15441
  }
15416
15442
  span.setStatus({ code: SpanStatusCode.OK });
15417
15443
  span.end();
15418
15444
  });
15419
15445
  this.addEventListener('error', function () {
15446
+ // Calculate duration even on error
15447
+ const duration = performance.now() - startTime;
15448
+ span.setAttribute('duration_ms', Math.round(duration));
15420
15449
  span.recordException(new Error('XHR request failed'));
15421
15450
  span.setStatus({ code: SpanStatusCode.ERROR, message: 'XHR request failed' });
15422
- console.error(`[SignOz] ${method} Error for ${url} on page ${pagePath}`);
15451
+ if (config.enableConsoleLog) {
15452
+ console.error(`[SignOz] ${method} Error for ${url} on page ${pagePath} [${Math.round(duration)}ms]`);
15453
+ }
15423
15454
  span.end();
15424
15455
  });
15425
15456
  return originalSend.call(this, body);
@@ -15428,7 +15459,7 @@ function addXHRLogging(config) {
15428
15459
  };
15429
15460
  }
15430
15461
  // Fungsi untuk menambahkan error tracking
15431
- function addErrorTracking() {
15462
+ function addErrorTracking(enableConsoleLog = false) {
15432
15463
  // Track unhandled errors
15433
15464
  window.addEventListener('error', (event) => {
15434
15465
  var _a;
@@ -15444,13 +15475,15 @@ function addErrorTracking() {
15444
15475
  span.setAttribute('error.stack', event.error.stack || '');
15445
15476
  }
15446
15477
  span.setStatus({ code: SpanStatusCode.ERROR, message: event.message });
15447
- console.error('[SignOz] Unhandled Error:', {
15448
- message: event.message,
15449
- filename: event.filename,
15450
- lineno: event.lineno,
15451
- colno: event.colno,
15452
- stack: (_a = event.error) === null || _a === void 0 ? void 0 : _a.stack
15453
- });
15478
+ if (enableConsoleLog) {
15479
+ console.error('[SignOz] Unhandled Error:', {
15480
+ message: event.message,
15481
+ filename: event.filename,
15482
+ lineno: event.lineno,
15483
+ colno: event.colno,
15484
+ stack: (_a = event.error) === null || _a === void 0 ? void 0 : _a.stack
15485
+ });
15486
+ }
15454
15487
  span.end();
15455
15488
  });
15456
15489
  // Track unhandled promise rejections
@@ -15465,12 +15498,14 @@ function addErrorTracking() {
15465
15498
  span.setAttribute('error.stack', event.reason.stack || '');
15466
15499
  }
15467
15500
  span.setStatus({ code: SpanStatusCode.ERROR, message: String(event.reason) });
15468
- console.error('[SignOz] Unhandled Promise Rejection:', event.reason);
15501
+ if (enableConsoleLog) {
15502
+ console.error('[SignOz] Unhandled Promise Rejection:', event.reason);
15503
+ }
15469
15504
  span.end();
15470
15505
  });
15471
15506
  }
15472
15507
  // Fungsi untuk menambahkan navigation tracking
15473
- function addNavigationTracking() {
15508
+ function addNavigationTracking(enableConsoleLog = false) {
15474
15509
  let previousUrl = window.location.href;
15475
15510
  // Track initial page load
15476
15511
  const tracer = trace.getTracer('navigation-tracker');
@@ -15480,10 +15515,12 @@ function addNavigationTracking() {
15480
15515
  initialSpan.setAttribute('navigation.pathname', window.location.pathname);
15481
15516
  initialSpan.setAttribute('navigation.search', window.location.search);
15482
15517
  initialSpan.setAttribute('navigation.hash', window.location.hash);
15483
- console.log('[SignOz] Page Load:', {
15484
- url: window.location.href,
15485
- pathname: window.location.pathname
15486
- });
15518
+ if (enableConsoleLog) {
15519
+ console.log('[SignOz] Page Load:', {
15520
+ url: window.location.href,
15521
+ pathname: window.location.pathname
15522
+ });
15523
+ }
15487
15524
  initialSpan.end();
15488
15525
  // Track popstate (browser back/forward)
15489
15526
  window.addEventListener('popstate', () => {
@@ -15494,11 +15531,13 @@ function addNavigationTracking() {
15494
15531
  span.setAttribute('navigation.pathname', window.location.pathname);
15495
15532
  span.setAttribute('navigation.search', window.location.search);
15496
15533
  span.setAttribute('navigation.hash', window.location.hash);
15497
- console.log('[SignOz] Navigation (popstate):', {
15498
- from: previousUrl,
15499
- to: window.location.href,
15500
- pathname: window.location.pathname
15501
- });
15534
+ if (enableConsoleLog) {
15535
+ console.log('[SignOz] Navigation (popstate):', {
15536
+ from: previousUrl,
15537
+ to: window.location.href,
15538
+ pathname: window.location.pathname
15539
+ });
15540
+ }
15502
15541
  previousUrl = window.location.href;
15503
15542
  span.end();
15504
15543
  });
@@ -15513,11 +15552,13 @@ function addNavigationTracking() {
15513
15552
  span.setAttribute('navigation.pathname', window.location.pathname);
15514
15553
  span.setAttribute('navigation.search', window.location.search);
15515
15554
  span.setAttribute('navigation.hash', window.location.hash);
15516
- console.log('[SignOz] Navigation (pushState):', {
15517
- from: previousUrl,
15518
- to: window.location.href,
15519
- pathname: window.location.pathname
15520
- });
15555
+ if (enableConsoleLog) {
15556
+ console.log('[SignOz] Navigation (pushState):', {
15557
+ from: previousUrl,
15558
+ to: window.location.href,
15559
+ pathname: window.location.pathname
15560
+ });
15561
+ }
15521
15562
  previousUrl = window.location.href;
15522
15563
  span.end();
15523
15564
  return result;
@@ -15532,11 +15573,13 @@ function addNavigationTracking() {
15532
15573
  span.setAttribute('navigation.pathname', window.location.pathname);
15533
15574
  span.setAttribute('navigation.search', window.location.search);
15534
15575
  span.setAttribute('navigation.hash', window.location.hash);
15535
- console.log('[SignOz] Navigation (replaceState):', {
15536
- from: previousUrl,
15537
- to: window.location.href,
15538
- pathname: window.location.pathname
15539
- });
15576
+ if (enableConsoleLog) {
15577
+ console.log('[SignOz] Navigation (replaceState):', {
15578
+ from: previousUrl,
15579
+ to: window.location.href,
15580
+ pathname: window.location.pathname
15581
+ });
15582
+ }
15540
15583
  previousUrl = window.location.href;
15541
15584
  span.end();
15542
15585
  return result;
@@ -15570,9 +15613,10 @@ function initializeSignOzTracing(config) {
15570
15613
  logRequestBody: (config === null || config === void 0 ? void 0 : config.logRequestBody) !== undefined ? config.logRequestBody : (getConfigValue('REACT_APP_SIGNOZ_LOG_REQUEST_BODY') === 'true' || true),
15571
15614
  logResponseBody: (config === null || config === void 0 ? void 0 : config.logResponseBody) !== undefined ? config.logResponseBody : (getConfigValue('REACT_APP_SIGNOZ_LOG_RESPONSE_BODY') === 'true' || true),
15572
15615
  maxBodyLogSize: (config === null || config === void 0 ? void 0 : config.maxBodyLogSize) || parseInt(getConfigValue('REACT_APP_SIGNOZ_MAX_BODY_LOG_SIZE') || '10000') || 10000,
15573
- enableDocumentLoad: (config === null || config === void 0 ? void 0 : config.enableDocumentLoad) !== undefined ? config.enableDocumentLoad : (getConfigValue('REACT_APP_SIGNOZ_ENABLE_DOCUMENT_LOAD') !== 'false'),
15616
+ enableDocumentLoad: (config === null || config === void 0 ? void 0 : config.enableDocumentLoad) !== undefined ? config.enableDocumentLoad : (getConfigValue('REACT_APP_SIGNOZ_ENABLE_DOCUMENT_LOAD') === 'true'),
15574
15617
  enableErrorTracking: (config === null || config === void 0 ? void 0 : config.enableErrorTracking) !== undefined ? config.enableErrorTracking : (getConfigValue('REACT_APP_SIGNOZ_ENABLE_ERROR_TRACKING') !== 'false'),
15575
- enableNavigationTracking: (config === null || config === void 0 ? void 0 : config.enableNavigationTracking) !== undefined ? config.enableNavigationTracking : (getConfigValue('REACT_APP_SIGNOZ_ENABLE_NAVIGATION_TRACKING') !== 'false')
15618
+ enableNavigationTracking: (config === null || config === void 0 ? void 0 : config.enableNavigationTracking) !== undefined ? config.enableNavigationTracking : (getConfigValue('REACT_APP_SIGNOZ_ENABLE_NAVIGATION_TRACKING') === 'true'),
15619
+ enableConsoleLog: (config === null || config === void 0 ? void 0 : config.enableConsoleLog) !== undefined ? config.enableConsoleLog : (getConfigValue('REACT_APP_SIGNOZ_ENABLE_CONSOLE_LOG') === 'true')
15576
15620
  };
15577
15621
  // Validasi konfigurasi
15578
15622
  const { isValid, missingFields } = validateConfig(effectiveConfig);
@@ -15641,22 +15685,24 @@ function initializeSignOzTracing(config) {
15641
15685
  enableRequestLogging: effectiveConfig.enableRequestLogging,
15642
15686
  logRequestBody: effectiveConfig.logRequestBody,
15643
15687
  logResponseBody: effectiveConfig.logResponseBody,
15644
- maxBodyLogSize: effectiveConfig.maxBodyLogSize
15688
+ maxBodyLogSize: effectiveConfig.maxBodyLogSize,
15689
+ enableConsoleLog: effectiveConfig.enableConsoleLog
15645
15690
  });
15646
15691
  addXHRLogging({
15647
15692
  enableRequestLogging: effectiveConfig.enableRequestLogging,
15648
15693
  logRequestBody: effectiveConfig.logRequestBody,
15649
15694
  logResponseBody: effectiveConfig.logResponseBody,
15650
- maxBodyLogSize: effectiveConfig.maxBodyLogSize
15695
+ maxBodyLogSize: effectiveConfig.maxBodyLogSize,
15696
+ enableConsoleLog: effectiveConfig.enableConsoleLog
15651
15697
  });
15652
15698
  }
15653
15699
  // Tambahkan error tracking
15654
15700
  if (effectiveConfig.enableErrorTracking) {
15655
- addErrorTracking();
15701
+ addErrorTracking(effectiveConfig.enableConsoleLog);
15656
15702
  }
15657
15703
  // Tambahkan navigation tracking
15658
15704
  if (effectiveConfig.enableNavigationTracking) {
15659
- addNavigationTracking();
15705
+ addNavigationTracking(effectiveConfig.enableConsoleLog);
15660
15706
  }
15661
15707
  console.log('SignOz: Konfigurasi tracing:', {
15662
15708
  serviceName: effectiveConfig.serviceName,