From 8dee21cc8c3286285e40051697239c6b9737c1ac Mon Sep 17 00:00:00 2001 From: xuan-cao-swi Date: Thu, 2 Jan 2025 13:57:59 -0500 Subject: [PATCH] revision --- lib/solarwinds_apm/patch/tag_sql/sw_pg_patch.rb | 10 +++++++--- test/patch/sw_pg_patch_integrate_test.rb | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/solarwinds_apm/patch/tag_sql/sw_pg_patch.rb b/lib/solarwinds_apm/patch/tag_sql/sw_pg_patch.rb index 6d29505..3c02824 100644 --- a/lib/solarwinds_apm/patch/tag_sql/sw_pg_patch.rb +++ b/lib/solarwinds_apm/patch/tag_sql/sw_pg_patch.rb @@ -8,6 +8,9 @@ module SolarWindsAPM module Patch module TagSql module SWOPgPatch + # These are all alike in that they will have a SQL + # statement as the first parameter, and they are all + # non-prepared statement execute. EXEC_ISH_METHODS = %i[ exec query @@ -19,10 +22,10 @@ module SWOPgPatch ].freeze EXEC_ISH_METHODS.each do |method| - define_method method do |*args, &block| + define_method method do |*args| annotated_sql = ::SolarWindsAPM::Patch::TagSql::SWODboUtils.annotate_span_and_sql(args[0]) args[0] = annotated_sql - super(*args, &block) + super(*args) end end end @@ -30,5 +33,6 @@ module SWOPgPatch end end -# need to prepend before pg instrumentation +# need to prepend before pg instrumentation patch itself +# upstream instrumentation -> our patch -> original function PG::Connection.prepend(SolarWindsAPM::Patch::TagSql::SWOPgPatch) if defined?(PG::Connection) diff --git a/test/patch/sw_pg_patch_integrate_test.rb b/test/patch/sw_pg_patch_integrate_test.rb index 14f9236..80e9690 100644 --- a/test/patch/sw_pg_patch_integrate_test.rb +++ b/test/patch/sw_pg_patch_integrate_test.rb @@ -50,7 +50,7 @@ def pg_dbo_integration_verification(sql, finished_spans) pg_client = PG::Connection.new - args = ['SELECT * FROM ABC;', 'a1'] + args = ['SELECT * FROM ABC;'] sql = pg_client.query(*args) finished_spans = exporter.finished_spans