class Dalli::Tracer

Attributes

active_span[R]
tracer[R]

Public Class Methods

instrument(tracer: OpenTracing.global_tracer, active_span: nil) click to toggle source
# File lib/rails/active_support/cache/dalli_tracer.rb, line 6
def instrument(tracer: OpenTracing.global_tracer, active_span: nil)
  ::Dalli::Server.class_eval do
    @tracer = tracer
    @active_span = active_span

    class << self
      attr_reader :tracer, :active_span
    end

    def tracer
      self.class.tracer
    end

    def active_span
      self.class.active_span
    end

    alias_method :request_without_instrumentation, :request

    def request(op, *args)
      tags = {
        'component' => 'Dalli::Server',
        'span.kind' => 'client',
        'db.statement' => op.to_s,
        'db.type' => 'memcached',
        'peer.hostname' => hostname,
        'peer.port' => port,
        'peer.weight' => weight
      }
      Method::Tracer.trace("Dalli::Server#request", tracer: tracer, child_of: active_span, tags: tags) do
        request_without_instrumentation(op, *args)
      end
    end
  end

  ::Dalli::Client.class_eval do
    @tracer = tracer
    @active_span = active_span

    class << self
      attr_reader :tracer, :active_span
    end

    def tracer
      self.class.tracer
    end

    def active_span
      self.class.active_span
    end

    alias_method :perform_without_instrumentation, :perform

    def perform(*args)
      Method::Tracer.trace("Dalli::Client#perform", tracer: tracer, child_of: active_span) do
        perform_without_instrumentation(*args)
      end
    end
  end
end
perform(*args) click to toggle source
# File lib/rails/active_support/cache/dalli_tracer.rb, line 59
def perform(*args)
  Method::Tracer.trace("Dalli::Client#perform", tracer: tracer, child_of: active_span) do
    perform_without_instrumentation(*args)
  end
end
remove_instrumentation() click to toggle source
# File lib/rails/active_support/cache/dalli_tracer.rb, line 67
def remove_instrumentation
  ::Dalli::Server.class_eval do
    alias_method :request, :request_without_instrumentation
    remove_method :request_without_instrumentation
  end

  ::Dalli::Client.class_eval do
    alias_method :perform, :perform_without_instrumentation
    remove_method :perform_without_instrumentation
  end
end
request(op, *args) click to toggle source
# File lib/rails/active_support/cache/dalli_tracer.rb, line 25
def request(op, *args)
  tags = {
    'component' => 'Dalli::Server',
    'span.kind' => 'client',
    'db.statement' => op.to_s,
    'db.type' => 'memcached',
    'peer.hostname' => hostname,
    'peer.port' => port,
    'peer.weight' => weight
  }
  Method::Tracer.trace("Dalli::Server#request", tracer: tracer, child_of: active_span, tags: tags) do
    request_without_instrumentation(op, *args)
  end
end