module Sequel::Plugins::NewRelicInstrumentation::MethodWrapping

Meta-programming for creating method tracers for the Sequel::Model plugin.

Public Instance Methods

wrap_sequel_method(method_name, operation_name = method_name) click to toggle source

Install a method named method_name that will trace execution with a metric name derived from operation_name (or method_name if operation_name isn’t specified).

Calls superclass method
# File lib/sequel/plugins/new_relic_instrumentation.rb, line 19
def wrap_sequel_method(method_name, operation_name = method_name)
  define_method(method_name) do |*args, &block|
    klass = self.is_a?(Class) ? self : self.class
    product = NewRelic::Agent::Instrumentation::SequelHelper.product_name_from_adapter(db.adapter_scheme)
    segment = NewRelic::Agent::Tracer.start_datastore_segment(
      product: product,
      operation: operation_name,
      collection: klass.name
    )

    begin
      NewRelic::Agent.disable_all_tracing { super(*args, &block) }
    ensure
      ::NewRelic::Agent::Transaction::Segment.finish(segment)
    end
  end
end