feat(smartScrape): better loggin

This commit is contained in:
Gergő Móricz 2025-04-15 23:34:00 -07:00
parent b6abe4f26b
commit 0935ec210e

View File

@ -1,5 +1,5 @@
import { z } from "zod"; import { z } from "zod";
import { logger } from "../../../lib/logger"; import { logger as _logger } from "../../../lib/logger";
import { robustFetch } from "./fetch"; import { robustFetch } from "./fetch";
import fs from "fs/promises"; import fs from "fs/promises";
import { configDotenv } from "dotenv"; import { configDotenv } from "dotenv";
@ -51,8 +51,16 @@ export async function smartScrape(
sessionId?: string, sessionId?: string,
extractId?: string, extractId?: string,
): Promise<SmartScrapeResult> { ): Promise<SmartScrapeResult> {
let logger = _logger.child({
method: "smartScrape",
module: "smartScrape",
extractId,
url,
prompt,
sessionId,
});
try { try {
logger.info("Initiating smart scrape request", { url, prompt, sessionId }); logger.info("Initiating smart scrape request");
// Pass schema type as generic parameter to robustFeth // Pass schema type as generic parameter to robustFeth
const response = await robustFetch<typeof smartScrapeResultSchema>({ const response = await robustFetch<typeof smartScrapeResultSchema>({
@ -116,8 +124,6 @@ export async function smartScrape(
} }
logger.info("Smart scrape successful", { logger.info("Smart scrape successful", {
url,
prompt,
sessionId: response.sessionId, sessionId: response.sessionId,
}); });
@ -155,8 +161,6 @@ export async function smartScrape(
}; };
logger.error("Smart scrape request failed", { logger.error("Smart scrape request failed", {
url,
prompt,
error: JSON.stringify(errorInfo), error: JSON.stringify(errorInfo),
}); });