Emit canonical JSON request log lines via rails_semantic_logger - #2862
Open
mroderick wants to merge 1 commit into
Open
Emit canonical JSON request log lines via rails_semantic_logger#2862mroderick wants to merge 1 commit into
mroderick wants to merge 1 commit into
Conversation
mroderick
force-pushed
the
feature/canonical-json-log-lines
branch
from
September 9, 2026 14:33
157c05e to
7a6dc73
Compare
Planner's request logging is multi-line and unstructured, which makes request-level analysis (latency percentiles, error rates per controller) impractical outside the app. Emit one JSON line per request instead. Switch the stdout appender to JSON when RAILS_LOG_TO_STDOUT is set and tag requests with the request id as a named tag, so it lands as a log field. Add path_template (the normalized route pattern, e.g. /workshops/:id) to the request-completion payload so lines carry no raw IDs or query strings. Drop the production config.logger override: rails_semantic_logger replaces Rails.logger regardless, so the TaggedLogging line was dead code that obscured where logging is configured.
mroderick
force-pushed
the
feature/canonical-json-log-lines
branch
from
September 10, 2026 11:32
8c77cf2 to
5cd28b5
Compare
mroderick
marked this pull request as ready for review
September 10, 2026 11:39
KimberleyCook
approved these changes
Sep 10, 2026
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.
Planner's request logging is multi-line and unstructured, which makes request-level analysis (latency percentiles, error rates per controller) impractical outside the app. This PR emits one JSON log line per request, using the already-installed rails_semantic_logger.
Four files change:
config/application.rb,config/environments/production.rb,config/initializers/canonical_log.rb, andspec/requests/canonical_log_line_spec.rb.Change:
RAILS_LOG_TO_STDOUTis set, and tag requests with the request id as a named tag, so it lands as a log field.path_templateto the request-completion payload. The value is the route's URIpattern including its optional format segment:
/faqlogs as/faq(.:format),/unsubscribe/:tokenas/unsubscribe/:token(.:format).payload.pathstill carriesthe raw path, so group on
path_template.config.loggeroverride; rails_semantic_logger replaces Rails.logger regardless, so the line was dead code.Filtered request params stay in the lines; the log destination retains them for just over a year. The pipeline side flattens the nested JSON to its field contract.
Log line example
GET /on the dashboard, anonymous user, production config (RAILS_LOG_TO_STDOUTset).Before (master), Ruby hash syntax -- not machine-parseable:
Before
After, one JSON line per request:
After
{"host":"MacBookAir.localdomain","application":"Semantic Logger","environment":"production","timestamp":"2026-09-09T18:12:58.178703Z","level":"info","level_index":2,"pid":4792,"thread":"puma srv tp 002","duration_ms":142.09,"duration":"142.1ms","named_tags":{"request_id":"ba7e6e85-4e92-4986-b0ce-aaf920da6da5"},"name":"DashboardController","message":"Completed #show","payload":{"controller":"DashboardController","action":"show","format":"*/*","method":"GET","path":"/","status":200,"view_runtime":41.33,"db_runtime":17.64,"queries_count":17,"cached_queries_count":0,"path_template":"/","allocations":293522,"cpu_time":126.35,"idle_time":15.74,"gc_time":10.62,"status_message":"OK"},"metric":"rails.controller.process_action"}Review notes
config/initializers/canonical_log.rb) prepends ontoActionController::Baseand runs from theensurein Rails'process_action, so failing requests also emit a line (status derived from the exception). That makes it global; it must also never raise while an exception is in flight. It only readsrequest.route_uri_pattern, which returns nil for unmatched routes.config/environments/production.rbremoves theconfig.loggeroverride; rails_semantic_logger replacesRails.loggerin its own initializer. Verified that nothing in the app or its gems uses TaggedLogging-specific APIs: the only consumer, ActiveJob'slogger.tagged, is API-compatible and covered by the suite, and a production-mode boot confirmsRails.loggeris a SemanticLogger with workingtagged.SemanticLoggerdoes implementpush_tags/pop_tags; nothing in the app calls them.config/initializers/filter_parameter_logging.rbis the privacy boundary; check you are comfortable with it (passwords, emails, tokens masked; free-text params not).spec/requests/canonical_log_line_spec.rbasserts the log event's fields, not the emitted JSON line, and does not cover the raising-request path.Post-Deploy Monitoring & Validation
Completedlines arrive withnamed_tags.request_idandpayload.path_templatepresent.RAILS_LOG_TO_STDOUTis unchanged from master.