Skip to content

Use JSON-format structured logging in production#882

Open
mwtrew wants to merge 5 commits into
mainfrom
1455_add-structured-logging
Open

Use JSON-format structured logging in production#882
mwtrew wants to merge 5 commits into
mainfrom
1455_add-structured-logging

Conversation

@mwtrew

@mwtrew mwtrew commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Status

What's changed?

  • Adds the Semantic Logging gem and uses it to make log messages more useful. See a comparison here.
    • This includes controller and action names by default.
  • In the production environment only, logs are structured in JSON-format to make filtering easier in BetterStack.
  • Disables Flipper logging, which was at DEBUG level with no clear way of changing the level.

Steps to perform after deploying to production

None.

@cla-bot cla-bot Bot added the cla-signed label Jun 17, 2026
@github-actions

github-actions Bot commented Jun 17, 2026

Copy link
Copy Markdown

Test coverage

91.72% line coverage reported by SimpleCov.
Run: https://github.com/RaspberryPiFoundation/editor-api/actions/runs/27693546397

@mwtrew mwtrew force-pushed the 1455_add-structured-logging branch from 7b1c1fc to 7de7d5f Compare June 17, 2026 11:08
@mwtrew mwtrew temporarily deployed to editor-api-staging June 17, 2026 11:25 Inactive
This is necessary for Flipper and ActionDispatch::HostAuthorization
messages to go through Semantic Logger and be correctly formatted as JSON.
@mwtrew mwtrew force-pushed the 1455_add-structured-logging branch from a285328 to 0e2d3e8 Compare June 17, 2026 13:17
@mwtrew mwtrew temporarily deployed to editor-api-p-1455-add-s-uykyc9 June 17, 2026 13:17 Inactive
@mwtrew mwtrew temporarily deployed to editor-api-staging June 17, 2026 13:17 Inactive
@mwtrew mwtrew temporarily deployed to editor-api-p-1455-add-s-mzxouu June 17, 2026 13:29 Inactive
@mwtrew mwtrew temporarily deployed to editor-api-p-1455-add-s-xyrf7u June 17, 2026 13:45 Inactive
@mwtrew mwtrew temporarily deployed to editor-api-staging June 17, 2026 13:46 Inactive
@mwtrew mwtrew marked this pull request as ready for review June 17, 2026 14:00
Copilot AI review requested due to automatic review settings June 17, 2026 14:00

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 introduces rails_semantic_logger to improve Rails log signal (e.g., controller/action payloads) and configures JSON structured logging for production output (intended for BetterStack/Heroku).

Changes:

  • Add rails_semantic_logger (and semantic_logger) dependencies.
  • Configure production logging to emit JSON to STDOUT when RAILS_LOG_TO_STDOUT is set, and set an application identifier.
  • Adjust Flipper logging configuration (explicitly disabled).

Reviewed changes

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

Show a summary per file
File Description
Gemfile.lock Adds rails_semantic_logger and semantic_logger dependencies.
Gemfile Adds rails_semantic_logger to the app dependencies.
config/initializers/flipper.rb Explicitly disables Flipper check logging (comment needs to match behavior).
config/environments/production.rb Configures JSON logging to STDOUT on Heroku via Semantic Logger settings.
config/application.rb Sets Semantic Logger app name and (currently) globally sets JSON format.

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

Comment thread config/application.rb
Comment thread config/initializers/flipper.rb

@cursor cursor Bot 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.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit bc0e827. Configure here.

Comment thread config/application.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants