Skip to content

Commit

Permalink
Merge branch 'main' into fix-simplecov
Browse files Browse the repository at this point in the history
  • Loading branch information
arielvalentin authored Jan 28, 2025
2 parents a6108b9 + 21acdab commit 53e1c8f
Show file tree
Hide file tree
Showing 11 changed files with 15 additions and 110 deletions.
1 change: 1 addition & 0 deletions instrumentation/mysql2/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ gemspec

group :test, :development do
gem 'opentelemetry-instrumentation-base', path: '../base'
gem 'opentelemetry-helpers-sql', path: '../../helpers/sql'
gem 'opentelemetry-helpers-mysql', path: '../../helpers/mysql'
gem 'opentelemetry-helpers-sql-obfuscation', path: '../../helpers/sql-obfuscation'
end
41 changes: 2 additions & 39 deletions instrumentation/mysql2/lib/opentelemetry/instrumentation/mysql2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,13 @@

require 'opentelemetry'
require 'opentelemetry-instrumentation-base'
require 'opentelemetry-helpers-sql'

module OpenTelemetry
module Instrumentation
# Contains the OpenTelemetry instrumentation for the Mysql2 gem
module Mysql2
extend self

CURRENT_ATTRIBUTES_KEY = Context.create_key('mysql-attributes-hash')

private_constant :CURRENT_ATTRIBUTES_KEY

# Returns the attributes hash representing the Mysql2 context found
# in the optional context or the current context if none is provided.
#
# @param context [optional Context] The context to lookup the current
# attributes hash. Defaults to Context.current
def attributes(context = nil)
context ||= Context.current
context.value(CURRENT_ATTRIBUTES_KEY) || {}
end

# @param attributes_hash [Hash] The attributes to add to the context
# @param parent_context [optional Context] The context to use as the parent for
# the returned context
# @return A context containing the merged attributes hash, derived from the
# optional parent context, or the current context if one was not provided.
def context_with_attributes(attributes_hash, parent_context: Context.current)
attributes_hash = attributes(parent_context).merge(attributes_hash)
parent_context.set_value(CURRENT_ATTRIBUTES_KEY, attributes_hash)
end

# Activates/deactivates the merged attributes hash within the current Context,
# which makes the "current attributes hash" available implicitly.
#
# On exit, the attributes hash that was active before calling this method
# will be reactivated.
#
# @param [Span] span the span to activate
# @yield [Hash, Context] yields attributes hash and a context containing the
# attributes hash to the block.
def with_attributes(attributes_hash)
attributes_hash = attributes.merge(attributes_hash)
Context.with_value(CURRENT_ATTRIBUTES_KEY, attributes_hash) { |c, h| yield h, c }
end
extend ::OpenTelemetry::Helpers::Sql
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Gem::Specification.new do |spec|

spec.add_dependency 'opentelemetry-api', '~> 1.0'
spec.add_dependency 'opentelemetry-helpers-mysql'
spec.add_dependency 'opentelemetry-helpers-sql'
spec.add_dependency 'opentelemetry-helpers-sql-obfuscation'
spec.add_dependency 'opentelemetry-instrumentation-base', '~> 0.23.0'

Expand Down
1 change: 1 addition & 0 deletions instrumentation/pg/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ gemspec
group :test do
gem 'activerecord', '>= 7.0.0'
gem 'opentelemetry-instrumentation-base', path: '../base'
gem 'opentelemetry-helpers-sql', path: '../../helpers/sql'
gem 'opentelemetry-helpers-sql-obfuscation', path: '../../helpers/sql-obfuscation'
end
31 changes: 2 additions & 29 deletions instrumentation/pg/lib/opentelemetry/instrumentation/pg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,40 +6,13 @@

require 'opentelemetry'
require 'opentelemetry-instrumentation-base'
require 'opentelemetry-helpers-sql'

module OpenTelemetry
module Instrumentation
# Contains the OpenTelemetry instrumentation for the Pg gem
module PG
extend self

CURRENT_ATTRIBUTES_KEY = Context.create_key('pg-attributes-hash')

private_constant :CURRENT_ATTRIBUTES_KEY

# Returns the attributes hash representing the postgres client context found
# in the optional context or the current context if none is provided.
#
# @param [optional Context] context The context to lookup the current
# attributes hash. Defaults to Context.current
def attributes(context = nil)
context ||= Context.current
context.value(CURRENT_ATTRIBUTES_KEY) || {}
end

# Activates/deactivates the merged attributes hash within the current Context,
# which makes the "current attributes hash" available implicitly.
#
# On exit, the attributes hash that was active before calling this method
# will be reactivated.
#
# @param [Span] span the span to activate
# @yield [Hash, Context] yields attributes hash and a context containing the
# attributes hash to the block.
def with_attributes(attributes_hash)
attributes_hash = attributes.merge(attributes_hash)
Context.with_value(CURRENT_ATTRIBUTES_KEY, attributes_hash) { |c, h| yield h, c }
end
extend ::OpenTelemetry::Helpers::Sql
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
spec.required_ruby_version = '>= 3.1'

spec.add_dependency 'opentelemetry-api', '~> 1.0'
spec.add_dependency 'opentelemetry-helpers-sql'
spec.add_dependency 'opentelemetry-helpers-sql-obfuscation'
spec.add_dependency 'opentelemetry-instrumentation-base', '~> 0.23.0'

Expand Down
1 change: 1 addition & 0 deletions instrumentation/que/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ gemspec
group :test do
gem 'activerecord', '< 7.2.0', '> 7.0.0'
gem 'pg'
gem 'opentelemetry-helpers-sql', path: '../../helpers/sql'
gem 'opentelemetry-helpers-sql-obfuscation', path: '../../helpers/sql-obfuscation'
gem 'opentelemetry-instrumentation-base', path: '../base'
gem 'opentelemetry-instrumentation-pg', path: '../pg'
Expand Down
4 changes: 2 additions & 2 deletions instrumentation/rails/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ gem opentelemetry-instrumentation-rails, "<version>"
| --- | --- |
| `5.2` | `= 0.24.1` |
| `6.0` | `= 0.28.0` |
| `6.1` | `= 0.24` |
| `7.x` | `~> 0.24` |
| `6.1` | `= 0.34` |
| `7.x` | `~> 0.34` |

## Usage

Expand Down
1 change: 1 addition & 0 deletions instrumentation/trilogy/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ gemspec
group :test do
gem 'opentelemetry-instrumentation-base', path: '../base'
gem 'opentelemetry-helpers-mysql', path: '../../helpers/mysql'
gem 'opentelemetry-helpers-sql', path: '../../helpers/sql'
gem 'opentelemetry-helpers-sql-obfuscation', path: '../../helpers/sql-obfuscation'
gem 'opentelemetry-propagator-vitess', path: '../../propagator/vitess'
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,50 +6,13 @@

require 'opentelemetry'
require 'opentelemetry-instrumentation-base'
require 'opentelemetry-helpers-sql'

module OpenTelemetry
module Instrumentation
# Contains the OpenTelemetry instrumentation for the Trilogy gem
module Trilogy
extend self

CURRENT_ATTRIBUTES_KEY = Context.create_key('trilogy-attributes-hash')

private_constant :CURRENT_ATTRIBUTES_KEY

# Returns the attributes hash representing the Trilogy context found
# in the optional context or the current context if none is provided.
#
# @param [optional Context] context The context to lookup the current
# attributes hash. Defaults to Context.current
def attributes(context = nil)
context ||= Context.current
context.value(CURRENT_ATTRIBUTES_KEY) || {}
end

# Returns a context containing the merged attributes hash, derived from the
# optional parent context, or the current context if one was not provided.
#
# @param [optional Context] context The context to use as the parent for
# the returned context
def context_with_attributes(attributes_hash, parent_context: Context.current)
attributes_hash = attributes(parent_context).merge(attributes_hash)
parent_context.set_value(CURRENT_ATTRIBUTES_KEY, attributes_hash)
end

# Activates/deactivates the merged attributes hash within the current Context,
# which makes the "current attributes hash" available implicitly.
#
# On exit, the attributes hash that was active before calling this method
# will be reactivated.
#
# @param [Span] span the span to activate
# @yield [Hash, Context] yields attributes hash and a context containing the
# attributes hash to the block.
def with_attributes(attributes_hash)
attributes_hash = attributes.merge(attributes_hash)
Context.with_value(CURRENT_ATTRIBUTES_KEY, attributes_hash) { |c, h| yield h, c }
end
extend ::OpenTelemetry::Helpers::Sql
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ Gem::Specification.new do |spec|

spec.add_dependency 'opentelemetry-api', '~> 1.0'
spec.add_dependency 'opentelemetry-helpers-mysql'
spec.add_dependency 'opentelemetry-helpers-sql'
spec.add_dependency 'opentelemetry-helpers-sql-obfuscation'
spec.add_dependency 'opentelemetry-instrumentation-base', '~> 0.23.0'
spec.add_dependency 'opentelemetry-semantic_conventions', '>= 1.8.0'

spec.add_development_dependency 'appraisal', '~> 2.5'
spec.add_development_dependency 'bundler', '~> 2.4'
spec.add_development_dependency 'minitest', '~> 5.0'
spec.add_development_dependency 'opentelemetry-propagator-vitess', '~> 0.1'
spec.add_development_dependency 'opentelemetry-sdk', '~> 1.1'
spec.add_development_dependency 'opentelemetry-test-helpers', '~> 0.3'
spec.add_development_dependency 'pry'
Expand Down

0 comments on commit 53e1c8f

Please sign in to comment.