Skip to content

Commit b99eee8

Browse files
committed
squash: update pg gem
1 parent fd373e8 commit b99eee8

File tree

3 files changed

+5
-68
lines changed
  • instrumentation

3 files changed

+5
-68
lines changed

instrumentation/mysql2/lib/opentelemetry/instrumentation/mysql2.rb

Lines changed: 2 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,50 +6,13 @@
66

77
require 'opentelemetry'
88
require 'opentelemetry-instrumentation-base'
9+
require 'opentelemetry-helpers-sql'
910

1011
module OpenTelemetry
1112
module Instrumentation
1213
# Contains the OpenTelemetry instrumentation for the Mysql2 gem
1314
module Mysql2
14-
extend self
15-
16-
CURRENT_ATTRIBUTES_KEY = Context.create_key('mysql-attributes-hash')
17-
18-
private_constant :CURRENT_ATTRIBUTES_KEY
19-
20-
# Returns the attributes hash representing the Mysql2 context found
21-
# in the optional context or the current context if none is provided.
22-
#
23-
# @param context [optional Context] The context to lookup the current
24-
# attributes hash. Defaults to Context.current
25-
def attributes(context = nil)
26-
context ||= Context.current
27-
context.value(CURRENT_ATTRIBUTES_KEY) || {}
28-
end
29-
30-
# @param attributes_hash [Hash] The attributes to add to the context
31-
# @param parent_context [optional Context] The context to use as the parent for
32-
# the returned context
33-
# @return A context containing the merged attributes hash, derived from the
34-
# optional parent context, or the current context if one was not provided.
35-
def context_with_attributes(attributes_hash, parent_context: Context.current)
36-
attributes_hash = attributes(parent_context).merge(attributes_hash)
37-
parent_context.set_value(CURRENT_ATTRIBUTES_KEY, attributes_hash)
38-
end
39-
40-
# Activates/deactivates the merged attributes hash within the current Context,
41-
# which makes the "current attributes hash" available implicitly.
42-
#
43-
# On exit, the attributes hash that was active before calling this method
44-
# will be reactivated.
45-
#
46-
# @param [Span] span the span to activate
47-
# @yield [Hash, Context] yields attributes hash and a context containing the
48-
# attributes hash to the block.
49-
def with_attributes(attributes_hash)
50-
attributes_hash = attributes.merge(attributes_hash)
51-
Context.with_value(CURRENT_ATTRIBUTES_KEY, attributes_hash) { |c, h| yield h, c }
52-
end
15+
extend ::OpenTelemetry::Helpers::Sql
5316
end
5417
end
5518
end

instrumentation/pg/Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ gemspec
1111
group :test do
1212
gem 'activerecord', '>= 7.0.0'
1313
gem 'opentelemetry-instrumentation-base', path: '../base'
14+
gem 'opentelemetry-helpers-sql', path: '../../helpers/sql'
1415
gem 'opentelemetry-helpers-sql-obfuscation', path: '../../helpers/sql-obfuscation'
1516
end

instrumentation/pg/lib/opentelemetry/instrumentation/pg.rb

Lines changed: 2 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,40 +6,13 @@
66

77
require 'opentelemetry'
88
require 'opentelemetry-instrumentation-base'
9+
require 'opentelemetry-helpers-sql'
910

1011
module OpenTelemetry
1112
module Instrumentation
1213
# Contains the OpenTelemetry instrumentation for the Pg gem
1314
module PG
14-
extend self
15-
16-
CURRENT_ATTRIBUTES_KEY = Context.create_key('pg-attributes-hash')
17-
18-
private_constant :CURRENT_ATTRIBUTES_KEY
19-
20-
# Returns the attributes hash representing the postgres client context found
21-
# in the optional context or the current context if none is provided.
22-
#
23-
# @param [optional Context] context The context to lookup the current
24-
# attributes hash. Defaults to Context.current
25-
def attributes(context = nil)
26-
context ||= Context.current
27-
context.value(CURRENT_ATTRIBUTES_KEY) || {}
28-
end
29-
30-
# Activates/deactivates the merged attributes hash within the current Context,
31-
# which makes the "current attributes hash" available implicitly.
32-
#
33-
# On exit, the attributes hash that was active before calling this method
34-
# will be reactivated.
35-
#
36-
# @param [Span] span the span to activate
37-
# @yield [Hash, Context] yields attributes hash and a context containing the
38-
# attributes hash to the block.
39-
def with_attributes(attributes_hash)
40-
attributes_hash = attributes.merge(attributes_hash)
41-
Context.with_value(CURRENT_ATTRIBUTES_KEY, attributes_hash) { |c, h| yield h, c }
42-
end
15+
extend ::OpenTelemetry::Helpers::Sql
4316
end
4417
end
4518
end

0 commit comments

Comments
 (0)