Module: OpenTelemetry::Instrumentation::Mysql2

Extended by:
Mysql2
Included in:
Mysql2
Defined in:
lib/opentelemetry/instrumentation/mysql2.rb,
lib/opentelemetry/instrumentation/mysql2/version.rb,
lib/opentelemetry/instrumentation/mysql2/patches/client.rb,
lib/opentelemetry/instrumentation/mysql2/instrumentation.rb

Overview

Contains the OpenTelemetry instrumentation for the Mysql2 gem

Defined Under Namespace

Modules: Patches Classes: Instrumentation

Constant Summary collapse

VERSION =
'0.20.1'

Instance Method Summary collapse

Instance Method Details

#attributes(context = nil) ⇒ Object

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

Parameters:

  • context (optional Context) (defaults to: nil)

    The context to lookup the current attributes hash. Defaults to Context.current



25
26
27
28
# File 'lib/opentelemetry/instrumentation/mysql2.rb', line 25

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.

Parameters:

  • context (optional Context)

    The context to use as the parent for the returned context



35
36
37
38
# File 'lib/opentelemetry/instrumentation/mysql2.rb', line 35

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.

Parameters:

  • span (Span)

    the span to activate

Yields:

  • (Hash, Context)

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



49
50
51
52
# File 'lib/opentelemetry/instrumentation/mysql2.rb', line 49

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