-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #170 from solarwinds/NH-94970
NH-94970: dbo integration for psql
- Loading branch information
Showing
24 changed files
with
252 additions
and
641 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
module SolarWindsAPM | ||
module Patch | ||
module TagSql | ||
module SWODboUtils | ||
def self.annotate_span_and_sql(sql) | ||
return sql if sql.to_s.empty? | ||
|
||
current_span = ::OpenTelemetry::Trace.current_span | ||
|
||
annotated_sql = '' | ||
if current_span.context.trace_flags.sampled? | ||
traceparent = SolarWindsAPM::Utils.traceparent_from_context(current_span.context) | ||
annotated_traceparent = "/*traceparent='#{traceparent}'*/" | ||
current_span.add_attributes({ 'sw.query_tag' => annotated_traceparent }) | ||
annotated_sql = "#{sql} #{annotated_traceparent}" | ||
else | ||
annotated_sql = sql | ||
end | ||
|
||
SolarWindsAPM.logger.debug { "[#{self.class}/#{__method__}] annotated_sql: #{annotated_sql}" } | ||
annotated_sql | ||
rescue StandardError => e | ||
SolarWindsAPM.logger.error { "[#{self.class}/#{__method__}] Failed to annotated sql. Error: #{e.message}" } | ||
sql | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
module SolarWindsAPM | ||
module Patch | ||
module TagSql | ||
module SWOPgPatch | ||
# We target operations covered by the upstream pg instrumentation. | ||
# 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 | ||
sync_exec | ||
async_exec | ||
exec_params | ||
async_exec_params | ||
sync_exec_params | ||
].freeze | ||
|
||
EXEC_ISH_METHODS.each do |method| | ||
define_method method do |*args| | ||
annotated_sql = ::SolarWindsAPM::Patch::TagSql::SWODboUtils.annotate_span_and_sql(args[0]) | ||
args[0] = annotated_sql | ||
super(*args) | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
# 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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.