Skip to content

Commit a96ca50

Browse files
committed
Call telemetry built-in at initialization time
I enhanced the initialize function to call the increment_feature_counter built-in (if supported). This triggers telemetry on usage of the adapter.
1 parent d730a85 commit a96ca50

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

lib/active_record/connection_adapters/cockroachdb_adapter.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,26 @@ def initialize(connection, logger, conn_params, config)
209209
version_num = 202
210210
end
211211
@crdb_version = version_num
212+
213+
if @config[:disable_cockroachdb_telemetry]
214+
return
215+
end
216+
Thread.new do
217+
pool.with_connection do |conn|
218+
if !conn.active?
219+
return
220+
end
221+
begin
222+
query = "SELECT crdb_internal.increment_feature_counter('ActiveRecord %d.%d')"
223+
conn.execute(query % [ActiveRecord::VERSION::MAJOR, ActiveRecord::VERSION::MINOR])
224+
rescue ActiveRecord::StatementInvalid
225+
# The increment_feature_counter built-in is not supported on this
226+
# CockroachDB version. Ignore.
227+
rescue => error
228+
logger.warn "Unexpected error when incrementing feature counter: #{error}"
229+
end
230+
end
231+
end
212232
end
213233

214234
def self.database_exists?(config)

0 commit comments

Comments
 (0)