Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

feat(pdf): add success/failure logging to pdfParse (#3336)

Abimael Martellb021dd37630d
diff --git a/apps/api/src/scraper/scrapeURL/engines/pdf/pdfParse.ts b/apps/api/src/scraper/scrapeURL/engines/pdf/pdfParse.ts
index 9cf8a1207..62fc1b211 100644
--- a/apps/api/src/scraper/scrapeURL/engines/pdf/pdfParse.ts
+++ b/apps/api/src/scraper/scrapeURL/engines/pdf/pdfParse.ts
@@ -10,11 +10,24 @@ export async function scrapePDFWithParsePDF(
): Promise<PDFProcessorResult> {
meta.logger.debug("Processing PDF document with parse-pdf", { tempFilePath });
- const result = await PdfParse(await readFile(tempFilePath));
- const escaped = escapeHtml(result.text);
+ try {
+ const startedAt = Date.now();
+ const result = await PdfParse(await readFile(tempFilePath));
+ const durationMs = Date.now() - startedAt;
+ const escaped = escapeHtml(result.text);
- return {
- markdown: escaped,
- html: escaped,
- };
+ meta.logger.info("pdfParse succeeded", {
+ durationMs,
+ markdownLength: escaped.length,
+ numPages: result.numpages,
+ });
+
+ return {
+ markdown: escaped,
+ html: escaped,
+ };
+ } catch (error) {
+ meta.logger.error("pdfParse failed", { error });
+ throw error;
+ }
}