|
64 | 64 | expect(data["db.name"]).to include("db")
|
65 | 65 | expect(data["db.system"]).to eq("sqlite3")
|
66 | 66 | end
|
| 67 | + |
| 68 | + it "records database configuration if connection.pool is not available" do |
| 69 | + # Some adapters (like CockroachDB) don't provide ConnectionPool, |
| 70 | + # so we have to grab the configuration off the Connection itself. |
| 71 | + # See https://github.com/getsentry/sentry-ruby/issues/2110 |
| 72 | + config = { adapter: "sqlite3", database: "dummy-database" } |
| 73 | + allow_any_instance_of(ActiveRecord::ConnectionAdapters::SQLite3Adapter).to receive(:pool).and_return(nil) |
| 74 | + allow_any_instance_of(ActiveRecord::ConnectionAdapters::SQLite3Adapter).to receive(:instance_variable_get).with(:@config).and_return(config) |
| 75 | + |
| 76 | + transaction = Sentry::Transaction.new(sampled: true, hub: Sentry.get_current_hub) |
| 77 | + Sentry.get_current_scope.set_span(transaction) |
| 78 | + |
| 79 | + Post.all.to_a |
| 80 | + |
| 81 | + transaction.finish |
| 82 | + |
| 83 | + expect(transport.events.count).to eq(1) |
| 84 | + |
| 85 | + transaction = transport.events.first.to_hash |
| 86 | + expect(transaction[:type]).to eq("transaction") |
| 87 | + expect(transaction[:spans].count).to eq(1) |
| 88 | + |
| 89 | + span = transaction[:spans][0] |
| 90 | + expect(span[:op]).to eq("db.sql.active_record") |
| 91 | + expect(span[:description]).to eq("SELECT \"posts\".* FROM \"posts\"") |
| 92 | + expect(span[:tags].key?(:cached)).to eq(false) |
| 93 | + expect(span[:trace_id]).to eq(transaction.dig(:contexts, :trace, :trace_id)) |
| 94 | + |
| 95 | + data = span[:data] |
| 96 | + expect(data["db.name"]).to eq("dummy-database") |
| 97 | + expect(data["db.system"]).to eq("sqlite3") |
| 98 | + end |
67 | 99 | end
|
68 | 100 |
|
69 | 101 | context "when transaction is not sampled" do
|
|
0 commit comments