From f37d79af3b1239dc15619b6d6305f7648d9ecc60 Mon Sep 17 00:00:00 2001 From: Pat Allan Date: Fri, 9 Feb 2024 12:31:45 +1100 Subject: [PATCH] Tracing ActiveRecord if ActiveSupport is present MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the suite that’s being monitored doesn’t have ActiveSupport, then it definitely doesn’t have ActiveRecord, and so no tracing is required. --- lib/buildkite/test_collector.rb | 6 ++++-- spec/spec_helper.rb | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/buildkite/test_collector.rb b/lib/buildkite/test_collector.rb index 97e1df4..4f10b3a 100644 --- a/lib/buildkite/test_collector.rb +++ b/lib/buildkite/test_collector.rb @@ -12,8 +12,6 @@ module TestCollector require "timeout" require "tmpdir" -require "active_support/notifications" - require_relative "test_collector/version" require_relative "test_collector/error" require_relative "test_collector/ci" @@ -70,6 +68,10 @@ def self.enable_tracing! Buildkite::TestCollector::Network.configure Buildkite::TestCollector::Object.configure + return unless defined?(ActiveSupport) + + require "active_support/notifications" + ActiveSupport::Notifications.subscribe("sql.active_record") do |name, start, finish, id, payload| Buildkite::TestCollector::Uploader.tracer&.backfill(:sql, finish - start, **{ query: payload[:sql] }) end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index aae93ad..69fa230 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require "buildkite/test_collector" +require "active_support/notifications" Dir["spec/support/**/*.rb"].each { |f| require File.expand_path(f) }