Skip to content

chore(server): structured logging Phase 2 — workers slice - #335

Merged
gkhngyk merged 1 commit into
mainfrom
feature/logging-phase2-workers
Jul 4, 2026
Merged

gkhngyk merged 1 commit into
mainfrom
feature/logging-phase2-workers

Conversation

@gkhngyk

@gkhngyk gkhngyk commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Summary

Third incremental slice of #303 (structured logging Phase 2), following #330 (lib/config) and the routes slice. Migrates the console.* calls in server/src/workers/ to the module-level pino logger.

Workers run outside the request lifecycle, so there is no req.log — they use the module logger with structured fields instead of interpolated strings.

Files migrated (~21 calls):

  • tracking-worker.js (20):
    • per-task progress chatter (Polling task=…, Submitted …, result saved) → logger.debug({ taskId, scraperId })
    • operational milestones (Submitting N scraper tasks, N results stored) → logger.info({ brandId, count, … })
    • failures → logger.error({ err, … }); poll/stall retries → logger.warn
    • Customer prompt text is no longer written to logs — taskId / scraperId / model / region identify the work instead.
  • content-worker.js (1): generation summary → logger.info({ brandId, generated })

Level mapping follows the issue (console.log → info/debug by operational value, warn → warn, error → error). Behaviour is unchanged.

Related issue

Part of #303 (Phase 2 of #245). Remaining lib/ (job-manager, job-runner, cloro-scraper) and server.js / middleware follow as separate PRs.

Type of change

  • chore — Maintenance

How to test

  1. From server/: npm run lint, npm run format:check, npm run test (93 tests) all pass.
  2. grep -rn "console\." server/src/workers/ returns nothing.
  3. Running a tracking job now emits structured JSON log lines (debug for per-task chatter, info for milestones, error for failures) instead of console.* strings, with no customer prompt text in the log body.

Checklist

  • Branch follows the naming convention (feature/, fix/, chore/, docs/) — see CONTRIBUTING.md
  • Commits follow Conventional Commits
  • npm run lint passes (from server/)
  • npm run format:check passes (from server/)
  • Changes are focused — one concern per PR

Migrate the console.* calls in server/src/workers/ to the module-level
pino logger. Workers run outside the request lifecycle, so they use the
module logger (not req.log), with structured fields instead of
interpolated strings.

- tracking-worker.js (20): per-task progress chatter → logger.debug
  ({ taskId, scraperId }); operational milestones → logger.info
  ({ brandId, count, … }); failures → logger.error({ err, … });
  poll/stall retries → logger.warn. Customer prompt text is no longer
  written to logs — task/scraper ids identify the work instead.
- content-worker.js (1): generation summary → logger.info
  ({ brandId, generated })

Part of #303 (Phase 2 of #245), part 3 after #330 (lib/config) and the
routes slice. Level mapping per the issue; behaviour unchanged.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR continues the structured logging Phase 2 migration by replacing console.* usage in background workers with the module-level pino logger (server/src/lib/logger.js), emitting leveled JSON logs with structured fields. This aligns worker logging with the broader server logging approach while avoiding request-scoped req.log (not available in workers).

Changes:

  • Migrate ~20+ console.* calls in tracking-worker.js to logger.debug/info/warn/error with structured metadata.
  • Migrate the final console.log in content-worker.js to logger.info with { brandId, generated }.
  • Remove logging of customer prompt text from worker log lines (favoring identifiers/metadata instead).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
server/src/workers/tracking-worker.js Replaces console.* with structured pino logging across task submission, polling, milestones, and error paths.
server/src/workers/content-worker.js Converts generation summary line to structured logger.info.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +160 to 163
logger.error(
{ err: sub.reason, scraperId: failedTask.scraperId },
'failed to submit scraper task',
);
Comment on lines +261 to 264
logger.warn(
{ brandId, pending, expected: expectedSubmitted },
'cloro delivery stalled — some tasks never returned; continuing',
);
Comment on lines +274 to 277
logger.info(
{ submitted: submitted.length, total: scraperTasks.length },
'tasks submitted, polling for results',
);

if (modelTasks.length > 0) {
console.log(`[tracking] Running ${modelTasks.length} AI model tasks concurrently...`);
logger.info({ count: modelTasks.length }, 'running ai model tasks concurrently');
`[tracking] Failed prompt "${prompt.text.slice(0, 50)}..." model=${modelName} region=${region}:`,
err.message,
);
logger.error({ err, model: modelName, region }, 'ai model task failed');
@gkhngyk
gkhngyk merged commit 070b3f0 into main Jul 4, 2026
6 checks passed
gkhngyk added a commit that referenced this pull request Jul 6, 2026
…e) (#351)

Migrate the last console.* calls (lib/cloro-scraper.js) to the module-level
pino logger. This file was deliberately held back from the earlier slices
to avoid churn with the query fan-out work (#341, now merged).

- submit/poll per-task chatter (task submitted, completed, polling) →
  logger.debug({ taskId, scraperId, ... }); operational start → logger.info
  ({ taskType, scraperId, region }); failures/timeouts → logger.error
  ({ ..., status/reason }). Customer prompt text is no longer written to the
  submit log — taskType/scraperId/region identify the task instead.

Closes #303: every non-script console.* in server/src now routes through the
structured logger. Phase 2 of #245 is complete (parts: #330, #334, #335,
#336, #337, and this).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants