From cd3fab9ccc1d281a9955263ac2cc86acd74fd6b9 Mon Sep 17 00:00:00 2001 From: David Taylor Date: Mon, 17 Feb 2020 18:14:14 +0000 Subject: [PATCH] DEV: Allow raw PG tracing to be enabled only for sidekiq processes --- config/initializers/000-trace_pg_connections.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/config/initializers/000-trace_pg_connections.rb b/config/initializers/000-trace_pg_connections.rb index add1990ba0..fcda5bb611 100644 --- a/config/initializers/000-trace_pg_connections.rb +++ b/config/initializers/000-trace_pg_connections.rb @@ -4,6 +4,9 @@ # to be streamed to files for debugging. The filenames are formatted # like tmp/pgtrace/{{PID}}_{{CONNECTION_OBJECT_ID}}.txt # +# Setting TRACE_PG_CONNECTIONS=SIDEKIQ will only trace connections +# on in sidekiq (safer, because there will be minimal user-facing perf impact) +# # Files will be automatically deleted when the connection is closed gracefully # (e.g. when activerecord closes it after a period of inactivity) # Files will not be automatically deleted when closed abruptly @@ -17,6 +20,7 @@ if ENV["TRACE_PG_CONNECTIONS"] def initialize(*args) super(*args).tap do + next if ENV["TRACE_PG_CONNECTIONS"] == "SIDEKIQ" && !Sidekiq.server? FileUtils.mkdir_p(TRACE_DIR) @trace_filename = "#{TRACE_DIR}/#{Process.pid}_#{self.object_id}.txt" trace File.new(@trace_filename, "w") @@ -25,6 +29,7 @@ if ENV["TRACE_PG_CONNECTIONS"] def close super.tap do + next if ENV["TRACE_PG_CONNECTIONS"] == "SIDEKIQ" && !Sidekiq.server? File.delete(@trace_filename) end end