log primary and secondary responses
This commit is contained in:
@@ -18,6 +18,7 @@ const config = {
|
|||||||
|
|
||||||
// Logging
|
// Logging
|
||||||
logMismatches: process.env.LOG_MISMATCHES !== 'false', // default true
|
logMismatches: process.env.LOG_MISMATCHES !== 'false', // default true
|
||||||
|
logAllMismatchedResponses: process.env.LOG_ALL_MISMATCHED_RESPONSES === 'true', // default false
|
||||||
|
|
||||||
// Server
|
// Server
|
||||||
port: parseInt(process.env.PORT || '8545', 10),
|
port: parseInt(process.env.PORT || '8545', 10),
|
||||||
|
|||||||
@@ -17,6 +17,9 @@ SIZE_DIFF_THRESHOLD=100
|
|||||||
# Whether to log mismatches
|
# Whether to log mismatches
|
||||||
LOG_MISMATCHES=true
|
LOG_MISMATCHES=true
|
||||||
|
|
||||||
|
# Whether to log full responses for ALL mismatches (not just size differences)
|
||||||
|
LOG_ALL_MISMATCHED_RESPONSES=false
|
||||||
|
|
||||||
# Server port
|
# Server port
|
||||||
PORT=8545
|
PORT=8545
|
||||||
|
|
||||||
|
|||||||
@@ -423,30 +423,65 @@ class RPCProxy {
|
|||||||
const logEntry = {
|
const logEntry = {
|
||||||
requestId,
|
requestId,
|
||||||
method: requestBody.method,
|
method: requestBody.method,
|
||||||
|
request: requestBody, // Include the original request for context
|
||||||
mismatches,
|
mismatches,
|
||||||
streamEndpoint: this.streamEndpoint,
|
streamEndpoint: this.streamEndpoint,
|
||||||
compareEndpoint: this.compareEndpoint,
|
compareEndpoint: this.compareEndpoint,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Include full compare response if size differs significantly
|
// Include full responses if there's any mismatch (not just size)
|
||||||
if (sizeDiff > config.sizeDiffThreshold) {
|
// This helps debug status code mismatches, timeouts, etc.
|
||||||
|
const shouldLogResponses = sizeDiff > config.sizeDiffThreshold ||
|
||||||
|
streamResponse.statusCode !== compareResponse.statusCode ||
|
||||||
|
(config.logAllMismatchedResponses === true);
|
||||||
|
|
||||||
|
if (shouldLogResponses) {
|
||||||
try {
|
try {
|
||||||
logEntry.compareResponseData = JSON.parse(compareResponse.data);
|
// Try to parse as JSON for better readability
|
||||||
logEntry.streamResponseData = JSON.parse(streamResponse.data);
|
logEntry.streamResponse = {
|
||||||
|
statusCode: streamResponse.statusCode,
|
||||||
|
size: streamResponse.size,
|
||||||
|
data: streamResponse.data ? JSON.parse(streamResponse.data) : null
|
||||||
|
};
|
||||||
|
logEntry.compareResponse = {
|
||||||
|
statusCode: compareResponse.statusCode,
|
||||||
|
size: compareResponse.size,
|
||||||
|
data: compareResponse.data ? JSON.parse(compareResponse.data) : null
|
||||||
|
};
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
// If not valid JSON, include raw data
|
// If not valid JSON, include raw data
|
||||||
logEntry.compareResponseData = compareResponse.data;
|
logEntry.streamResponse = {
|
||||||
logEntry.streamResponseData = streamResponse.data;
|
statusCode: streamResponse.statusCode,
|
||||||
}
|
size: streamResponse.size,
|
||||||
|
data: streamResponse.data
|
||||||
|
};
|
||||||
|
logEntry.compareResponse = {
|
||||||
|
statusCode: compareResponse.statusCode,
|
||||||
|
size: compareResponse.size,
|
||||||
|
data: compareResponse.data
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.warn(logEntry, 'Response mismatch detected');
|
// Log a summary for easier reading
|
||||||
|
logger.warn({
|
||||||
|
requestId,
|
||||||
|
method: requestBody.method,
|
||||||
|
mismatchTypes: mismatches.map(m => m.type),
|
||||||
|
streamEndpoint: this.streamEndpoint,
|
||||||
|
compareEndpoint: this.compareEndpoint,
|
||||||
|
}, 'Response mismatch detected - full details below');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Log the full entry with all details
|
||||||
|
logger.warn(logEntry, 'Response mismatch details');
|
||||||
} else {
|
} else {
|
||||||
logger.debug({
|
logger.debug({
|
||||||
requestId,
|
requestId,
|
||||||
method: requestBody.method,
|
method: requestBody.method,
|
||||||
streamLatency: streamResponse.latency,
|
streamLatency: streamResponse.latency,
|
||||||
compareLatency: compareResponse.latency,
|
compareLatency: compareResponse.latency,
|
||||||
|
streamSize: streamResponse.size,
|
||||||
|
compareSize: compareResponse.size,
|
||||||
}, 'Responses match');
|
}, 'Responses match');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user