Module: OpenTelemetry::Helpers::Sql

Extended by:
Sql
Included in:
Sql
Defined in:
lib/opentelemetry/helpers/sql.rb,
lib/opentelemetry/helpers/sql/version.rb

Overview

Contains helpers for OpenTelemetry instrumentation related to SQL

Constant Summary collapse

VERSION =
'0.1.0'

Instance Method Summary collapse

Instance Method Details

#attributes(context = nil) ⇒ Object

Returns the attributes hash representing the SQL adapter context found in the optional context or the current context if none is provided.



24
25
26
27
# File 'lib/opentelemetry/helpers/sql.rb', line 24

def attributes(context = nil)
  context ||= Context.current
  context.value(CURRENT_ATTRIBUTES_KEY) || {}
end

#context_with_attributes(attributes_hash, parent_context: Context.current) ⇒ Object

Returns a context containing the merged attributes hash, derived from the optional parent context, or the current context if one was not provided.



34
35
36
37
# File 'lib/opentelemetry/helpers/sql.rb', line 34

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

#with_attributes(attributes_hash) {|Hash, Context| ... } ⇒ Object

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.

Yields:

  • (Hash, Context)

    yields attributes hash and a context containing the attributes hash to the block.



48
49
50
51
# File 'lib/opentelemetry/helpers/sql.rb', line 48

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