feat: switch to Pino logger with per-request context#64
feat: switch to Pino logger with per-request context#64neekolas merged 3 commits intoxmtplabs:mainfrom
Conversation
Replace custom ConsoleLogger with Pino for structured logging. - LOG_FORMAT=json env var for production JSON output, pino-pretty for local dev - Per-request child loggers with requestId, deliveryId, eventName context - Child logger propagated through dispatcher to all handlers - Rename warning() to warn() to match Pino convention - TestLogger updated with child() support for test assertions Resolves xmtplabs#63 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Uh oh. CI is failing |
dist/server.js
Outdated
| @@ -1,5 +1,35 @@ | |||
| // @bun | |||
There was a problem hiding this comment.
This file should be gitignored and removed from the repo
There was a problem hiding this comment.
Why didn't you respond to this?
There was a problem hiding this comment.
You're right — removed dist/server.js from the repo, added dist/ to .gitignore, and removed the "verify dist is up to date" CI step. The Dockerfile already builds dist at container build time so it was never needed in the repo.
src/server.ts
Outdated
| } | ||
|
|
||
| // Create per-request child logger with request context | ||
| const requestId = crypto.randomUUID(); |
There was a problem hiding this comment.
You should be able to get this from the webhook somewhere
There was a problem hiding this comment.
Good call — the X-GitHub-Delivery header already uniquely identifies each webhook request. Replaced the crypto.randomUUID() with deliveryId from the header. The child logger now binds deliveryId and eventName as context.
The Bun bundler inlines __dirname from pino's thread-stream module, embedding absolute paths into dist/server.js. This makes the build non-reproducible across environments (local vs CI). Marking pino and pino-pretty as --external keeps them as runtime imports instead. Also switches from pino transport (worker threads) to direct pino-pretty stream for dev mode, which is simpler and avoids thread-stream entirely at runtime. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Address PR review feedback: - Remove dist/server.js from repo and add dist/ to .gitignore - Remove "verify dist is up to date" CI step (dist is built at deploy time via Dockerfile) - Update Dockerfile build command with --external pino flags - Use X-GitHub-Delivery header as request identifier instead of generating a random UUID — the delivery ID already uniquely identifies each webhook request Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Resolves #63
Summary
ConsoleLoggerwith Pino —createLogger()factory returns a Pino-backed logger that adapts Pino's(fields, msg)API to the codebase's(msg, fields?)conventionLOG_FORMAT=jsonenv var — JSON output in production,pino-prettyfor local dev (default)requestId,deliveryId,eventNamebound as context, propagated through the dispatcher to all handlerswarning()→warn()(Pino convention),child(bindings)method added toLoggerinterfaceTestLoggerpreserved — Updated withchild()support; child loggers share the parent's messages array for easy assertionsFiles changed
src/logger.tscreateLogger(), updatedLoggerinterface, updatedTestLoggersrc/config.tslogFormatfield (fromLOG_FORMATenv var)src/main.tscreateLogger(), pass per-request logger through callbacksrc/server.tsrequestId/deliveryId/eventName, pass tohandleWebhooksrc/handler-dispatcher.tsdispatch()src/handlers/close-task.tswarning()→warn()src/handlers/pr-comment.tswarning()→warn()src/github-client.tswarning()→warn()src/task-utils.tswarning()→warn()package.jsonpinoandpino-prettydependenciesTest plan
requestId,deliveryId,eventNameTestLogger.child()shares messages array, merges bindingscreateLogger()returns logger with all methods includingchild()bun run checkpasses (typecheck + lint + format + test)Note
Switch logger to Pino with per-request child loggers bound to delivery ID and event name
ConsoleLoggerwith a Pino-backedcreateLoggerfactory in src/logger.ts; supports JSON or pretty-print output via theLOG_FORMATenv var.child()method to theLoggerinterface; src/server.ts creates a per-request child logger pre-bound withdeliveryIdandeventNamefor structured log correlation.HandlerDispatcher.dispatchand all downstream handler constructors so every log line carries request context.warning()towarn()across all handlers and test helpers to align with the Pino API.pinoandpino-prettyare excluded from the bundled output and must be present as runtime dependencies;LOG_FORMAT=jsonselects structured output, otherwise pretty-print is used.Macroscope summarized c6d3aa6.