Skip to content

Commit

Permalink
revision
Browse files Browse the repository at this point in the history
  • Loading branch information
xuan-cao-swi committed Jan 2, 2025
1 parent 2eb54f6 commit 8dee21c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
10 changes: 7 additions & 3 deletions lib/solarwinds_apm/patch/tag_sql/sw_pg_patch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -19,16 +22,17 @@ 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
end
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)
2 changes: 1 addition & 1 deletion test/patch/sw_pg_patch_integrate_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 8dee21c

Please sign in to comment.