Skip to content

Commit 85f1ccf

Browse files
committed
Unit test for the connection config
1 parent d67c265 commit 85f1ccf

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

sentry-rails/spec/sentry/rails/tracing/active_record_subscriber_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,38 @@
6464
expect(data["db.name"]).to include("db")
6565
expect(data["db.system"]).to eq("sqlite3")
6666
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
6799
end
68100

69101
context "when transaction is not sampled" do

0 commit comments

Comments
 (0)