إضافة دعم لتعليقات سجل الاستعلام البادئة

What?

Add support for ActiveRecord::QueryLogs.prepend_comment as a natural extension to the existing query log tags feature. This new setting works alongside the current RAILS_QUERY_LOG_TAGS environment variable.

Why?

Query log tags are incredibly useful for debugging, but there’s a catch: when dealing with long, complex queries, PostgreSQL and other databases often truncate the logs. When this happens, the valuable context from query tags (which are appended at the end by default) gets cut off, making it difficult to trace which part of your application generated the query.

By enabling prepend_comment, the query tags are moved to the beginning of the SQL query instead of the end. This ensures that even when queries get truncated in the logs, you’ll still be able to see the critical debugging information like controller names, action names, and job information.

How?

The feature should be opt-in and follows Discourse’s existing pattern for configuration:

  1. Enable query log tags (if not already enabled):RAILS_QUERY_LOG_TAGS=1
  2. Enable prepend comment: RAILS_QUERY_LOG_PREPEND_COMMENT=1

The feature only activates when both conditions are met: query log tags must be enabled, and the prepend comment flag must be set. This maintains backward compatibility and gives operators fine-grained control over their logging configuration.

Implementation PR: Add support for ActiveRecord::QueryLogs.prepend_comment by mudit-1996 · Pull Request #35888 · discourse/discourse · GitHub