|
80 | 80 | expect(log_event[:attributes]["db.query.parameter.created_at"][:value]).to include("2025-10-28 13:11:44") |
81 | 81 | expect(log_event[:attributes]["db.query.parameter.created_at"][:type]).to eql("string") |
82 | 82 | end |
| 83 | + |
| 84 | + it "logs queries with positional (unnamed) binds", skip: RAILS_VERSION >= 8.0 do |
| 85 | + Sentry.get_current_client.flush |
| 86 | + sentry_transport.events.clear |
| 87 | + sentry_transport.envelopes.clear |
| 88 | + |
| 89 | + Post.where("id = ? AND title = ?", 1, "Hello World").first |
| 90 | + |
| 91 | + Sentry.get_current_client.flush |
| 92 | + |
| 93 | + log_event = sentry_logs.find { |log| log[:body]&.include?("Database query") } |
| 94 | + expect(log_event).not_to be_nil |
| 95 | + end |
| 96 | + |
| 97 | + it "logs queries with positional (unnamed) binds", skip: RAILS_VERSION < 8.0 do |
| 98 | + Sentry.get_current_client.flush |
| 99 | + sentry_transport.events.clear |
| 100 | + sentry_transport.envelopes.clear |
| 101 | + |
| 102 | + Post.where("id = ? AND title = ?", 1, "Hello World").first |
| 103 | + |
| 104 | + Sentry.get_current_client.flush |
| 105 | + |
| 106 | + log_event = sentry_logs.find { |log| log[:body]&.include?("Database query") } |
| 107 | + expect(log_event).not_to be_nil |
| 108 | + |
| 109 | + expect(log_event[:attributes]["db.query.parameter.0"][:value]).to eq("1") |
| 110 | + expect(log_event[:attributes]["db.query.parameter.1"][:value]).to eq("Hello World") |
| 111 | + end |
| 112 | + |
| 113 | + it "handles nil binds gracefully" do |
| 114 | + Sentry.get_current_client.flush |
| 115 | + sentry_transport.events.clear |
| 116 | + sentry_transport.envelopes.clear |
| 117 | + |
| 118 | + # In theory, this should never happened |
| 119 | + ActiveSupport::Notifications.instrument("sql.active_record", |
| 120 | + sql: "SELECT 1", |
| 121 | + name: "SQL", |
| 122 | + connection: ActiveRecord::Base.connection, |
| 123 | + binds: nil |
| 124 | + ) |
| 125 | + |
| 126 | + Sentry.get_current_client.flush |
| 127 | + |
| 128 | + log_event = sentry_logs.find { |log| log[:attributes]&.dig(:sql, :value) == "SELECT 1" } |
| 129 | + expect(log_event).not_to be_nil |
| 130 | + expect(log_event[:attributes][:sql][:value]).to eq("SELECT 1") |
| 131 | + end |
| 132 | + |
| 133 | + it "when binds are empty array" do |
| 134 | + Sentry.get_current_client.flush |
| 135 | + sentry_transport.events.clear |
| 136 | + sentry_transport.envelopes.clear |
| 137 | + |
| 138 | + Post.connection.execute("SELECT posts.* FROM posts") |
| 139 | + |
| 140 | + Sentry.get_current_client.flush |
| 141 | + |
| 142 | + log_event = sentry_logs.find { |log| |
| 143 | + log[:attributes].dig(:sql, :value).include?("SELECT") && |
| 144 | + log[:attributes].dig(:sql, :value).include?("posts") |
| 145 | + } |
| 146 | + |
| 147 | + expect(log_event).not_to be_nil |
| 148 | + end |
83 | 149 | end |
84 | 150 |
|
85 | 151 | context "when send_default_pii is disabled" do |
|
0 commit comments