fix: add structured request context to all API error logs#337
Open
YizukiAme wants to merge 3 commits intoTHU-MAIC:mainfrom
Open
fix: add structured request context to all API error logs#337YizukiAme wants to merge 3 commits intoTHU-MAIC:mainfrom
YizukiAme wants to merge 3 commits intoTHU-MAIC:mainfrom
Conversation
Replace generic log.error messages across 23 API routes with structured, context-rich error logs that include provider, model, input summary, and other request parameters for faster incident triage. - Hoist key request params above try blocks for catch-block access - Add createLogger imports to routes that lacked logging - Truncate user-controlled strings (query, requirement) to prevent log flooding - No behavioral changes — purely observability improvement Closes THU-MAIC#323
Contributor
Author
Test Results — Before / After Log ComparisonTested by sending deliberately invalid credentials/inputs to 5 API routes, capturing server-side Before (original generic messages)After (structured context logs from this PR)Key improvements visible in logs
Note: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace generic
log.error('Error:', error)messages across 23 API routes with structured, context-rich error logs for faster incident triage.Closes #323
Changes
Pattern applied uniformly
What's included
let x: T | undefined) abovetryblocks so they're accessible incatchcreateLoggerimports to 4 routes that previously had no logging (classroom,classroom-media,generate-classroom/*).substring(0, 60)/.substring(0, 100)) to prevent log floodingapiError()responses are untouched; only log messages improvedAffected routes (23 files)
generate/image,generate/video,generate/tts,generate/agent-profiles,generate/scene-actions,generate/scene-content,generate/scene-outlines-streamclassroom,classroom-media,generate-classroom,generate-classroom/[jobId]chat,pbl/chatverify-model,verify-image-provider,verify-video-provider,verify-pdf-providerazure-voices,parse-pdf,proxy-media,quiz-grade,transcription,web-searchContext logged per route
Each error log now includes the most relevant request parameters for that endpoint:
Testing
apiError(...)) unchangedAs the changes are largely mechanical, all code edits in this PR were made by Claude Opus 4.6, but have been manually audited and tested.