module ActiveSupport::Cache::Tracer

Public Class Methods

clear_subscribers()
Alias for: disable
disable() click to toggle source
# File lib/rails/active_support/cache/tracer.rb, line 24
def disable
  if  @subscribers
    @subscribers.each { |subscriber| ActiveSupport::Notifications.unsubscribe(subscriber) }
    @subscribers.clear
  end

  self
end
Also aliased as: clear_subscribers
instrument(tracer: OpenTracing.global_tracer, active_span: nil, dalli: false) click to toggle source
# File lib/rails/active_support/cache/tracer.rb, line 9
def instrument(tracer: OpenTracing.global_tracer, active_span: nil, dalli: false)
  clear_subscribers
  events = %w(read write generate delete clear)
  @subscribers = events.map do |event|
    subscriber = ActiveSupport::Cache::Tracer::Subscriber.new(tracer: tracer,
                                                              active_span: active_span,
                                                              event: event)
    ActiveSupport::Notifications.subscribe("cache_#{event}.active_support", subscriber)
  end

  instrument_dalli(tracer: tracer, active_span: active_span) if dalli

  self
end
instrument_dalli(tracer:, active_span:) click to toggle source
# File lib/rails/active_support/cache/tracer.rb, line 35
def instrument_dalli(tracer:, active_span:)
  return unless defined?(ActiveSupport::Cache::DalliStore)
  require 'rails/active_support/cache/dalli_tracer'

  Dalli::Tracer.instrument(tracer: tracer, active_span: active_span)
  instrument_dalli_logger(active_span: active_span)
end
instrument_dalli_logger(active_span:, level: Logger::ERROR) click to toggle source
# File lib/rails/active_support/cache/tracer.rb, line 43
def instrument_dalli_logger(active_span:, level: Logger::ERROR)
  return unless defined?(Tracing::Logger)
  return unless active_span
  return if [Tracing::Logger, Tracing::CompositeLogger].any? { |t| Dalli.logger.is_a?(t) }

  tracing_logger = Tracing::Logger.new(active_span: active_span, level: level)
  loggers = [tracing_logger, Dalli.logger].compact
  Dalli.logger = Tracing::CompositeLogger.new(*loggers)
end
start_span(operation_name, tracer: OpenTracing.global_tracer, active_span: nil, start_time: Time.now, event:, **fields) click to toggle source
# File lib/rails/active_support/cache/manual_tracer.rb, line 5
def start_span(operation_name, tracer: OpenTracing.global_tracer, active_span: nil, start_time: Time.now, event:, **fields)
  span = tracer.start_span(operation_name,
                           child_of: active_span.respond_to?(:call) ? active_span.call : active_span,
                           start_time: start_time,
                           tags: {
                            'component' => 'ActiveSupport::Cache',
                            'span.kind' => 'client',
                            'cache.key' => fields.fetch(:key, 'unknown')
                           })

  if event == 'read'
    span.set_tag('cache.hit', fields.fetch(:hit, false))
  end

  span
end