Class: Tarantool::OpenTelemetry::Instrumenter

Inherits:
Object
  • Object
show all
Defined in:
tarantool-opentelemetry/lib/tarantool/opentelemetry/instrumenter.rb

Overview

An instrumenter for Tarantool::Client and Pool: one client span per event, the block run inside it. Another instrumenter (ActiveSupport::Notifications, a logger wrapper) can be chained; it runs inside the span too.

Instance Method Summary collapse

Constructor Details

#initialize(instrumenter: nil, tracer: nil, db_statement: :omit) ⇒ Instrumenter

Returns a new instance of Instrumenter.



11
12
13
14
15
16
17
18
19
# File 'tarantool-opentelemetry/lib/tarantool/opentelemetry/instrumenter.rb', line 11

def initialize(instrumenter: nil, tracer: nil, db_statement: :omit)
  unless DB_STATEMENT.include?(db_statement)
    raise ArgumentError, "db_statement must be :omit or :include, got #{db_statement.inspect}"
  end

  @instrumenter = instrumenter
  @tracer = tracer || ::OpenTelemetry.tracer_provider.tracer('tarantool-client', Tarantool::Client::VERSION)
  @db_statement = db_statement
end

Instance Method Details

#instrument(name, payload, &block) ⇒ Object

The client fills the payload (request, space, index, ...) inside the block, once names are resolved, so the name and attributes are set when the block is done. Finishing here rather than through Tracer#in_span records an exception once, with its message as the status description.



24
25
26
27
28
29
30
31
32
33
34
# File 'tarantool-opentelemetry/lib/tarantool/opentelemetry/instrumenter.rb', line 24

def instrument(name, payload, &block)
  span = @tracer.start_span(Attributes.name(name, payload), kind: :client)
  ::OpenTelemetry::Trace.with_span(span) { run(name, payload, &block) }
rescue StandardError => e
  span&.record_exception(e)
  span&.status = ::OpenTelemetry::Trace::Status.error(e.message)
  raise
ensure
  describe(span, name, payload) if span
  span&.finish
end