feat: add extraction monitoring and metrics logging
This commit is contained in:
@@ -554,6 +554,41 @@ function extractFacebookMarketplaceData(
|
||||
return marketplaceData.feed_units.edges.map((edge) => ({ node: edge.node }));
|
||||
}
|
||||
|
||||
/**
|
||||
* Monitor API extraction success/failure for detecting changes
|
||||
*/
|
||||
let extractionStats = {
|
||||
totalExtractions: 0,
|
||||
successfulExtractions: 0,
|
||||
failedExtractions: 0,
|
||||
lastApiChangeDetected: null as Date | null,
|
||||
};
|
||||
|
||||
/**
|
||||
* Log extraction metrics for monitoring API stability
|
||||
*/
|
||||
function logExtractionMetrics(success: boolean, itemId?: string) {
|
||||
extractionStats.totalExtractions++;
|
||||
if (success) {
|
||||
extractionStats.successfulExtractions++;
|
||||
} else {
|
||||
extractionStats.failedExtractions++;
|
||||
}
|
||||
|
||||
// Log warning if extraction success rate drops below 80%
|
||||
const successRate = extractionStats.successfulExtractions / extractionStats.totalExtractions;
|
||||
if (extractionStats.totalExtractions > 10 && successRate < 0.8 && !extractionStats.lastApiChangeDetected) {
|
||||
console.warn("⚠️ Facebook Marketplace API extraction success rate dropped below 80%. This may indicate API changes.");
|
||||
extractionStats.lastApiChangeDetected = new Date();
|
||||
}
|
||||
|
||||
if (success) {
|
||||
console.log(`📊 Facebook API extraction stats: ${extractionStats.successfulExtractions}/${extractionStats.totalExtractions} successful`);
|
||||
} else {
|
||||
console.warn(`❌ Facebook API extraction failed for item ${itemId || 'unknown'}`);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Turns cents to localized currency string.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user