Skip to content

Emit structured debug events in development only - #55657

Merged
skipkayhil merged 1 commit into
rails:mainfrom
Shopify:ac-no-debug-events-in-test
Sep 11, 2025
Merged

skipkayhil merged 1 commit into
rails:mainfrom
Shopify:ac-no-debug-events-in-test

Conversation

@adrianna-chang-shopify

@adrianna-chang-shopify adrianna-chang-shopify commented Sep 11, 2025 •

Copy link
Copy Markdown
Contributor

Motivation / Background

Ref: #55566

Shopify's local Event Reporter emitted debug events in local environments (test and development), so I ported the change over to Rails. However, after further discussion with the team, we decided it's strange to emit debug events in test; this causes extra noise, and tests typically want to verify production behaviour, so emitting debug events by default causes a divergence.

This PR enables debug events in development only. Tests can verify debug events by enabling debug mode explicitly, e.g.

def test_debug
  assert_event_reported("test") do
    Rails.event.with_debug do
      something_that_emits_a_debug_event()
    end
  end
end

cc @skipkayhil @Edouard-chin

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Unrelated changes should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

I haven't added a CHANGELOG entry because the prior behaviour technically wasn't documented.

We could also opt to make this configurable (and document the option), but not sure whether we want to encourage globally enabling / disabling it vs encouraging use of with_debug .

@rails-bot rails-bot Bot added the railties label Sep 11, 2025
@skipkayhil
skipkayhil merged commit 3e8cf56 into rails:main Sep 11, 2025
claudiob added a commit to claudiob/rails that referenced this pull request Nov 22, 2025
This is a follow-up to rails#55657, a PR that enables debug events in development only.

The problem is that some users might want to see debug events also in test or in production.
A real-world example is detailed in rails#55900 (comment)

This PR slightly changes the behavior replacing `Rails.env.development?` with `config.log_level == "debug"`.

As explained in [Rails documentation](https://guides.rubyonrails.org/debugging_rails_applications.html#log-levels):

> The default Rails log level is :debug. However, it is set to :info for the production environment
> in the default generated config/environments/production.rb.

As a result, this PR maintains the existing behavior when defaults are applied, but opens up
the possibility to see debug events in production for those who want to do so: they simply have
to set `RAILS_LOG_LEVEL=debug`.
claudiob added a commit to claudiob/rails that referenced this pull request Nov 22, 2025
This is a follow-up to rails#55657, a PR that enables debug events in development only.

The problem is that some users might want to see debug events also in test or in production.
A real-world example is detailed in rails#55900 (comment)

This PR slightly changes the behavior replacing `Rails.env.development?` with `config.log_level == "debug"`.

As explained in [Rails documentation](https://guides.rubyonrails.org/debugging_rails_applications.html#log-levels):

> The default Rails log level is :debug. However, it is set to :info for the production environment
> in the default generated config/environments/production.rb.

As a result, this PR maintains the existing behavior when defaults are applied, but opens up
the possibility to see debug events in production for those who want to do so: they simply have
to set `RAILS_LOG_LEVEL=debug`.
claudiob added a commit to claudiob/rails that referenced this pull request Nov 22, 2025
This is a follow-up to rails#55657, a PR that enables debug events in development only.

The problem is that some users might want to see debug events also in test or in production.
A real-world example is detailed in rails#55900 (comment)

This PR slightly changes the behavior replacing `Rails.env.development?` with `config.log_level == "debug"`.

As explained in [Rails documentation](https://guides.rubyonrails.org/debugging_rails_applications.html#log-levels):

> The default Rails log level is :debug. However, it is set to :info for the production environment
> in the default generated config/environments/production.rb.

As a result, this PR maintains the existing behavior when defaults are applied, but opens up
the possibility to see debug events in production for those who want to do so: they simply have
to set `RAILS_LOG_LEVEL=debug`.
claudiob added a commit to claudiob/rails that referenced this pull request Nov 25, 2025
This is a follow-up to rails#55657, a PR that enables debug events in development only.

The problem is that some users might want to see debug events also in test or in production.
A real-world example is detailed in rails#55900 (comment)

This PR slightly changes the behavior replacing `Rails.env.development?` with `config.log_level == "debug"`.

As explained in [Rails documentation](https://guides.rubyonrails.org/debugging_rails_applications.html#log-levels):

> The default Rails log level is :debug. However, it is set to :info for the production environment
> in the default generated config/environments/production.rb.

As a result, this PR maintains the existing behavior when defaults are applied, but opens up
the possibility to see debug events in production for those who want to do so: they simply have
to set `RAILS_LOG_LEVEL=debug`.
claudiob added a commit to claudiob/rails that referenced this pull request Nov 25, 2025
This is a follow-up to rails#55657, a PR that enables debug events in development only.

The problem is that some users might want to see debug events also in test or in production.
A real-world example is detailed in rails#55900 (comment)

This PR slightly changes the behavior replacing `Rails.env.development?` with `config.log_level == "debug"`.

As explained in [Rails documentation](https://guides.rubyonrails.org/debugging_rails_applications.html#log-levels):

> The default Rails log level is :debug. However, it is set to :info for the production environment
> in the default generated config/environments/production.rb.

As a result, this PR maintains the existing behavior when defaults are applied, but opens up
the possibility to see debug events in production for those who want to do so: they simply have
to set `RAILS_LOG_LEVEL=debug`.
claudiob added a commit to claudiob/rails that referenced this pull request Nov 27, 2025
This is a follow-up to rails#55657, a PR that enables debug events in development only.

The problem is that some users might want to see debug events also in test or in production.
A real-world example is detailed in rails#55900 (comment)

This PR slightly changes the behavior replacing `Rails.env.development?` with `config.log_level == "debug"`.

As explained in [Rails documentation](https://guides.rubyonrails.org/debugging_rails_applications.html#log-levels):

> The default Rails log level is :debug. However, it is set to :info for the production environment
> in the default generated config/environments/production.rb.

As a result, this PR maintains the existing behavior when defaults are applied, but opens up
the possibility to see debug events in production for those who want to do so: they simply have
to set `RAILS_LOG_LEVEL=debug`.
drymar pushed a commit to drymar/rails that referenced this pull request Jan 5, 2026
This is a follow-up to rails#55657, a PR that enables debug events in development only.

The problem is that some users might want to see debug events also in test or in production.
A real-world example is detailed in rails#55900 (comment)

This PR slightly changes the behavior replacing `Rails.env.development?` with `config.log_level == "debug"`.

As explained in [Rails documentation](https://guides.rubyonrails.org/debugging_rails_applications.html#log-levels):

> The default Rails log level is :debug. However, it is set to :info for the production environment
> in the default generated config/environments/production.rb.

As a result, this PR maintains the existing behavior when defaults are applied, but opens up
the possibility to see debug events in production for those who want to do so: they simply have
to set `RAILS_LOG_LEVEL=debug`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants