@echoteam/signoz-react 1.2.2 → 1.2.3
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 +75 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.esm.js +198 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +198 -2
- package/dist/index.js.map +1 -1
- package/dist/types/tracing.d.ts +2 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -15370,6 +15370,16 @@ function addFetchLogging(config) {
|
|
|
15370
15370
|
const responseData = await clonedResponse.text();
|
|
15371
15371
|
const truncatedData = truncateBody(responseData, config.maxBodyLogSize);
|
|
15372
15372
|
span.setAttribute('response.data', truncatedData);
|
|
15373
|
+
// Try to parse JSON and extract message if exists
|
|
15374
|
+
try {
|
|
15375
|
+
const jsonData = JSON.parse(responseData);
|
|
15376
|
+
if (jsonData.message) {
|
|
15377
|
+
span.setAttribute('response.message', jsonData.message);
|
|
15378
|
+
}
|
|
15379
|
+
}
|
|
15380
|
+
catch (e) {
|
|
15381
|
+
// Not JSON or no message field, ignore
|
|
15382
|
+
}
|
|
15373
15383
|
if (config.enableConsoleLog) {
|
|
15374
15384
|
console.log(`[SignOz] ${method} Response from ${url} (${response.status}) on page ${pagePath} [${Math.round(duration)}ms]:`, truncatedData);
|
|
15375
15385
|
}
|
|
@@ -15452,6 +15462,16 @@ function addXHRLogging(config) {
|
|
|
15452
15462
|
const responseData = xhr.responseText;
|
|
15453
15463
|
const truncatedData = truncateBody(responseData, config.maxBodyLogSize);
|
|
15454
15464
|
span.setAttribute('response.data', truncatedData);
|
|
15465
|
+
// Try to parse JSON and extract message if exists
|
|
15466
|
+
try {
|
|
15467
|
+
const jsonData = JSON.parse(responseData);
|
|
15468
|
+
if (jsonData.message) {
|
|
15469
|
+
span.setAttribute('response.message', jsonData.message);
|
|
15470
|
+
}
|
|
15471
|
+
}
|
|
15472
|
+
catch (e) {
|
|
15473
|
+
// Not JSON or no message field, ignore
|
|
15474
|
+
}
|
|
15455
15475
|
if (config.enableConsoleLog) {
|
|
15456
15476
|
console.log(`[SignOz] ${method} Response from ${url} (${xhr.status}) on page ${pagePath} [${Math.round(duration)}ms]:`, truncatedData);
|
|
15457
15477
|
}
|
|
@@ -15605,6 +15625,169 @@ function addNavigationTracking(enableConsoleLog = false) {
|
|
|
15605
15625
|
return result;
|
|
15606
15626
|
};
|
|
15607
15627
|
}
|
|
15628
|
+
// Fungsi untuk menambahkan WebSocket logging
|
|
15629
|
+
function addWebSocketLogging(config) {
|
|
15630
|
+
if (!config.enableWebSocketLogging)
|
|
15631
|
+
return;
|
|
15632
|
+
const OriginalWebSocket = window.WebSocket;
|
|
15633
|
+
window.WebSocket = function (url, protocols) {
|
|
15634
|
+
const ws = new OriginalWebSocket(url, protocols);
|
|
15635
|
+
const wsUrl = typeof url === 'string' ? url : url.toString();
|
|
15636
|
+
// Capture current page info
|
|
15637
|
+
const pageUrl = window.location.href;
|
|
15638
|
+
const pagePath = window.location.pathname;
|
|
15639
|
+
const tracer = trace.getTracer('websocket-logger');
|
|
15640
|
+
let connectionSpan = tracer.startSpan('WebSocket Connection');
|
|
15641
|
+
const connectionStartTime = performance.now();
|
|
15642
|
+
connectionSpan.setAttribute('websocket.url', wsUrl);
|
|
15643
|
+
connectionSpan.setAttribute('websocket.protocols', Array.isArray(protocols) ? protocols.join(',') : (protocols || 'none'));
|
|
15644
|
+
connectionSpan.setAttribute('page.url', pageUrl);
|
|
15645
|
+
connectionSpan.setAttribute('page.pathname', pagePath);
|
|
15646
|
+
// Track connection open
|
|
15647
|
+
const originalOnOpen = ws.onopen;
|
|
15648
|
+
ws.addEventListener('open', function (event) {
|
|
15649
|
+
const duration = performance.now() - connectionStartTime;
|
|
15650
|
+
connectionSpan.setAttribute('websocket.state', 'open');
|
|
15651
|
+
connectionSpan.setAttribute('duration_ms', Math.round(duration));
|
|
15652
|
+
connectionSpan.setStatus({ code: SpanStatusCode.OK });
|
|
15653
|
+
if (config.enableConsoleLog) {
|
|
15654
|
+
console.log(`[SignOz] WebSocket Connected to ${wsUrl} from page ${pagePath} [${Math.round(duration)}ms]`);
|
|
15655
|
+
}
|
|
15656
|
+
connectionSpan.end();
|
|
15657
|
+
if (originalOnOpen) {
|
|
15658
|
+
originalOnOpen.call(ws, event);
|
|
15659
|
+
}
|
|
15660
|
+
});
|
|
15661
|
+
// Track messages sent
|
|
15662
|
+
const originalSend = ws.send;
|
|
15663
|
+
ws.send = function (data) {
|
|
15664
|
+
if (config.logWebSocketMessages) {
|
|
15665
|
+
const messageSpan = tracer.startSpan('WebSocket Send');
|
|
15666
|
+
const sendStartTime = performance.now();
|
|
15667
|
+
messageSpan.setAttribute('websocket.url', wsUrl);
|
|
15668
|
+
messageSpan.setAttribute('websocket.direction', 'send');
|
|
15669
|
+
messageSpan.setAttribute('page.url', pageUrl);
|
|
15670
|
+
messageSpan.setAttribute('page.pathname', pagePath);
|
|
15671
|
+
// Log message data
|
|
15672
|
+
if (typeof data === 'string') {
|
|
15673
|
+
const truncatedData = truncateBody(data, config.maxBodyLogSize);
|
|
15674
|
+
messageSpan.setAttribute('websocket.message', truncatedData);
|
|
15675
|
+
// Try to parse JSON and extract message if exists
|
|
15676
|
+
try {
|
|
15677
|
+
const jsonData = JSON.parse(data);
|
|
15678
|
+
if (jsonData.message) {
|
|
15679
|
+
messageSpan.setAttribute('websocket.message.text', jsonData.message);
|
|
15680
|
+
}
|
|
15681
|
+
if (jsonData.type || jsonData.event) {
|
|
15682
|
+
messageSpan.setAttribute('websocket.message.type', jsonData.type || jsonData.event);
|
|
15683
|
+
}
|
|
15684
|
+
}
|
|
15685
|
+
catch (e) {
|
|
15686
|
+
// Not JSON, ignore
|
|
15687
|
+
}
|
|
15688
|
+
if (config.enableConsoleLog) {
|
|
15689
|
+
console.log(`[SignOz] WebSocket Send to ${wsUrl} from page ${pagePath}:`, truncatedData);
|
|
15690
|
+
}
|
|
15691
|
+
}
|
|
15692
|
+
else {
|
|
15693
|
+
messageSpan.setAttribute('websocket.message', '[Binary Data]');
|
|
15694
|
+
messageSpan.setAttribute('websocket.message.type', 'binary');
|
|
15695
|
+
if (config.enableConsoleLog) {
|
|
15696
|
+
console.log(`[SignOz] WebSocket Send to ${wsUrl} from page ${pagePath}: [Binary Data]`);
|
|
15697
|
+
}
|
|
15698
|
+
}
|
|
15699
|
+
const duration = performance.now() - sendStartTime;
|
|
15700
|
+
messageSpan.setAttribute('duration_ms', Math.round(duration));
|
|
15701
|
+
messageSpan.setStatus({ code: SpanStatusCode.OK });
|
|
15702
|
+
messageSpan.end();
|
|
15703
|
+
}
|
|
15704
|
+
return originalSend.call(ws, data);
|
|
15705
|
+
};
|
|
15706
|
+
// Track messages received
|
|
15707
|
+
const originalOnMessage = ws.onmessage;
|
|
15708
|
+
ws.addEventListener('message', function (event) {
|
|
15709
|
+
if (config.logWebSocketMessages) {
|
|
15710
|
+
const messageSpan = tracer.startSpan('WebSocket Receive');
|
|
15711
|
+
messageSpan.setAttribute('websocket.url', wsUrl);
|
|
15712
|
+
messageSpan.setAttribute('websocket.direction', 'receive');
|
|
15713
|
+
messageSpan.setAttribute('page.url', pageUrl);
|
|
15714
|
+
messageSpan.setAttribute('page.pathname', pagePath);
|
|
15715
|
+
// Log message data
|
|
15716
|
+
if (typeof event.data === 'string') {
|
|
15717
|
+
const truncatedData = truncateBody(event.data, config.maxBodyLogSize);
|
|
15718
|
+
messageSpan.setAttribute('websocket.message', truncatedData);
|
|
15719
|
+
// Try to parse JSON and extract message if exists
|
|
15720
|
+
try {
|
|
15721
|
+
const jsonData = JSON.parse(event.data);
|
|
15722
|
+
if (jsonData.message) {
|
|
15723
|
+
messageSpan.setAttribute('websocket.message.text', jsonData.message);
|
|
15724
|
+
}
|
|
15725
|
+
if (jsonData.type || jsonData.event) {
|
|
15726
|
+
messageSpan.setAttribute('websocket.message.type', jsonData.type || jsonData.event);
|
|
15727
|
+
}
|
|
15728
|
+
}
|
|
15729
|
+
catch (e) {
|
|
15730
|
+
// Not JSON, ignore
|
|
15731
|
+
}
|
|
15732
|
+
if (config.enableConsoleLog) {
|
|
15733
|
+
console.log(`[SignOz] WebSocket Receive from ${wsUrl} on page ${pagePath}:`, truncatedData);
|
|
15734
|
+
}
|
|
15735
|
+
}
|
|
15736
|
+
else {
|
|
15737
|
+
messageSpan.setAttribute('websocket.message', '[Binary Data]');
|
|
15738
|
+
messageSpan.setAttribute('websocket.message.type', 'binary');
|
|
15739
|
+
if (config.enableConsoleLog) {
|
|
15740
|
+
console.log(`[SignOz] WebSocket Receive from ${wsUrl} on page ${pagePath}: [Binary Data]`);
|
|
15741
|
+
}
|
|
15742
|
+
}
|
|
15743
|
+
messageSpan.setStatus({ code: SpanStatusCode.OK });
|
|
15744
|
+
messageSpan.end();
|
|
15745
|
+
}
|
|
15746
|
+
if (originalOnMessage) {
|
|
15747
|
+
originalOnMessage.call(ws, event);
|
|
15748
|
+
}
|
|
15749
|
+
});
|
|
15750
|
+
// Track connection errors
|
|
15751
|
+
const originalOnError = ws.onerror;
|
|
15752
|
+
ws.addEventListener('error', function (event) {
|
|
15753
|
+
const errorSpan = tracer.startSpan('WebSocket Error');
|
|
15754
|
+
errorSpan.setAttribute('websocket.url', wsUrl);
|
|
15755
|
+
errorSpan.setAttribute('websocket.state', 'error');
|
|
15756
|
+
errorSpan.setAttribute('page.url', pageUrl);
|
|
15757
|
+
errorSpan.setAttribute('page.pathname', pagePath);
|
|
15758
|
+
errorSpan.recordException(new Error('WebSocket connection error'));
|
|
15759
|
+
errorSpan.setStatus({ code: SpanStatusCode.ERROR, message: 'WebSocket connection error' });
|
|
15760
|
+
if (config.enableConsoleLog) {
|
|
15761
|
+
console.error(`[SignOz] WebSocket Error for ${wsUrl} on page ${pagePath}`);
|
|
15762
|
+
}
|
|
15763
|
+
errorSpan.end();
|
|
15764
|
+
if (originalOnError) {
|
|
15765
|
+
originalOnError.call(ws, event);
|
|
15766
|
+
}
|
|
15767
|
+
});
|
|
15768
|
+
// Track connection close
|
|
15769
|
+
const originalOnClose = ws.onclose;
|
|
15770
|
+
ws.addEventListener('close', function (event) {
|
|
15771
|
+
const closeSpan = tracer.startSpan('WebSocket Close');
|
|
15772
|
+
closeSpan.setAttribute('websocket.url', wsUrl);
|
|
15773
|
+
closeSpan.setAttribute('websocket.state', 'closed');
|
|
15774
|
+
closeSpan.setAttribute('websocket.close.code', event.code);
|
|
15775
|
+
closeSpan.setAttribute('websocket.close.reason', event.reason || 'No reason provided');
|
|
15776
|
+
closeSpan.setAttribute('websocket.close.wasClean', event.wasClean);
|
|
15777
|
+
closeSpan.setAttribute('page.url', pageUrl);
|
|
15778
|
+
closeSpan.setAttribute('page.pathname', pagePath);
|
|
15779
|
+
if (config.enableConsoleLog) {
|
|
15780
|
+
console.log(`[SignOz] WebSocket Closed ${wsUrl} on page ${pagePath} - Code: ${event.code}, Reason: ${event.reason || 'No reason'}, Clean: ${event.wasClean}`);
|
|
15781
|
+
}
|
|
15782
|
+
closeSpan.setStatus({ code: SpanStatusCode.OK });
|
|
15783
|
+
closeSpan.end();
|
|
15784
|
+
if (originalOnClose) {
|
|
15785
|
+
originalOnClose.call(ws, event);
|
|
15786
|
+
}
|
|
15787
|
+
});
|
|
15788
|
+
return ws;
|
|
15789
|
+
};
|
|
15790
|
+
}
|
|
15608
15791
|
/**
|
|
15609
15792
|
* Inisialisasi SignOz tracing untuk aplikasi React
|
|
15610
15793
|
* @param config - Konfigurasi SignOz (opsional, akan menggunakan environment variables jika tidak disediakan)
|
|
@@ -15636,7 +15819,9 @@ function initializeSignOzTracing(config) {
|
|
|
15636
15819
|
enableDocumentLoad: (config === null || config === void 0 ? void 0 : config.enableDocumentLoad) !== undefined ? config.enableDocumentLoad : (getConfigValue('REACT_APP_SIGNOZ_ENABLE_DOCUMENT_LOAD') === 'true'),
|
|
15637
15820
|
enableErrorTracking: (config === null || config === void 0 ? void 0 : config.enableErrorTracking) !== undefined ? config.enableErrorTracking : (getConfigValue('REACT_APP_SIGNOZ_ENABLE_ERROR_TRACKING') !== 'false'),
|
|
15638
15821
|
enableNavigationTracking: (config === null || config === void 0 ? void 0 : config.enableNavigationTracking) !== undefined ? config.enableNavigationTracking : (getConfigValue('REACT_APP_SIGNOZ_ENABLE_NAVIGATION_TRACKING') === 'true'),
|
|
15639
|
-
enableConsoleLog: (config === null || config === void 0 ? void 0 : config.enableConsoleLog) !== undefined ? config.enableConsoleLog : (getConfigValue('REACT_APP_SIGNOZ_ENABLE_CONSOLE_LOG') === 'true')
|
|
15822
|
+
enableConsoleLog: (config === null || config === void 0 ? void 0 : config.enableConsoleLog) !== undefined ? config.enableConsoleLog : (getConfigValue('REACT_APP_SIGNOZ_ENABLE_CONSOLE_LOG') === 'true'),
|
|
15823
|
+
enableWebSocketLogging: (config === null || config === void 0 ? void 0 : config.enableWebSocketLogging) !== undefined ? config.enableWebSocketLogging : (getConfigValue('REACT_APP_SIGNOZ_ENABLE_WEBSOCKET_LOGGING') === 'true'),
|
|
15824
|
+
logWebSocketMessages: (config === null || config === void 0 ? void 0 : config.logWebSocketMessages) !== undefined ? config.logWebSocketMessages : (getConfigValue('REACT_APP_SIGNOZ_LOG_WEBSOCKET_MESSAGES') === 'true')
|
|
15640
15825
|
};
|
|
15641
15826
|
// Validasi konfigurasi
|
|
15642
15827
|
const { isValid, missingFields } = validateConfig(effectiveConfig);
|
|
@@ -15724,6 +15909,15 @@ function initializeSignOzTracing(config) {
|
|
|
15724
15909
|
if (effectiveConfig.enableNavigationTracking) {
|
|
15725
15910
|
addNavigationTracking(effectiveConfig.enableConsoleLog);
|
|
15726
15911
|
}
|
|
15912
|
+
// Tambahkan WebSocket logging
|
|
15913
|
+
if (effectiveConfig.enableWebSocketLogging) {
|
|
15914
|
+
addWebSocketLogging({
|
|
15915
|
+
enableWebSocketLogging: effectiveConfig.enableWebSocketLogging,
|
|
15916
|
+
logWebSocketMessages: effectiveConfig.logWebSocketMessages,
|
|
15917
|
+
maxBodyLogSize: effectiveConfig.maxBodyLogSize,
|
|
15918
|
+
enableConsoleLog: effectiveConfig.enableConsoleLog
|
|
15919
|
+
});
|
|
15920
|
+
}
|
|
15727
15921
|
console.log('SignOz: Konfigurasi tracing:', {
|
|
15728
15922
|
serviceName: effectiveConfig.serviceName,
|
|
15729
15923
|
environment: effectiveConfig.environment,
|
|
@@ -15735,7 +15929,9 @@ function initializeSignOzTracing(config) {
|
|
|
15735
15929
|
maxBodyLogSize: effectiveConfig.maxBodyLogSize,
|
|
15736
15930
|
enableDocumentLoad: effectiveConfig.enableDocumentLoad,
|
|
15737
15931
|
enableErrorTracking: effectiveConfig.enableErrorTracking,
|
|
15738
|
-
enableNavigationTracking: effectiveConfig.enableNavigationTracking
|
|
15932
|
+
enableNavigationTracking: effectiveConfig.enableNavigationTracking,
|
|
15933
|
+
enableWebSocketLogging: effectiveConfig.enableWebSocketLogging,
|
|
15934
|
+
logWebSocketMessages: effectiveConfig.logWebSocketMessages
|
|
15739
15935
|
});
|
|
15740
15936
|
console.log('SignOz: Tracing berhasil diinisialisasi');
|
|
15741
15937
|
}
|