Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Include async:true on async queries #248

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/rails_semantic_logger/active_record/log_subscriber.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ def sql(event)
log_payload[:binds] = bind_values(payload) unless (payload[:binds] || []).empty?
log_payload[:allocations] = event.allocations if event.respond_to?(:allocations)
log_payload[:cached] = event.payload[:cached]
log_payload[:async] = true if event.payload[:async]

log = {
message: name,
Expand Down
24 changes: 24 additions & 0 deletions test/active_record_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,30 @@ class ActiveRecordTest < Minitest::Test
}
)
end

it "marks async queries with async: true" do
skip "Not applicable to older rails" if Rails.version.to_f < 7.1

expected_sql = 'SELECT COUNT(*) FROM "samples"'

messages = semantic_logger_events do
Sample.count
Sample.async_count.value
end
assert_equal 2, messages.count, messages

messages.each do |message|
assert_semantic_logger_event(
message,
level: :debug,
name: "ActiveRecord",
message: "Sample Count",
payload_includes: {sql: expected_sql}
)
end
refute messages[0].payload.key?(:async)
assert_equal true, messages[1].payload[:async]
end
end
end
end
1 change: 1 addition & 0 deletions test/dummy/config/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ class Application < Rails::Application
# Configure sensitive parameters which will be filtered from the log file.
config.filter_parameters += [:password]
config.active_record.sqlite3.represent_boolean_as_integer = true if config.active_record.sqlite3
config.active_record.async_query_executor = :global_thread_pool

# Settings in config/environments/* take precedence over those specified here.
# Application configuration should go into files in config/initializers
Expand Down