Class: Sentry::Rails::Tracing::ActiveSupportSubscriber

Inherits:
AbstractSubscriber show all
Defined in:
lib/sentry/rails/tracing/active_support_subscriber.rb

Constant Summary collapse

READ_EVENT_NAMES =
%w[
  cache_read.active_support
].freeze
WRITE_EVENT_NAMES =
%w[
  cache_write.active_support
  cache_increment.active_support
  cache_decrement.active_support
].freeze
REMOVE_EVENT_NAMES =
%w[
  cache_delete.active_support
].freeze
FLUSH_EVENT_NAMES =
%w[
  cache_prune.active_support
].freeze
EVENT_NAMES =
READ_EVENT_NAMES + WRITE_EVENT_NAMES + REMOVE_EVENT_NAMES + FLUSH_EVENT_NAMES
SPAN_ORIGIN =
"auto.cache.rails"

Class Method Summary collapse

Methods inherited from AbstractSubscriber

record_on_current_span, #subscribe_to_event, unsubscribe!

Class Method Details

.operation_name(event_name) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/sentry/rails/tracing/active_support_subscriber.rb', line 46

def self.operation_name(event_name)
  case
  when READ_EVENT_NAMES.include?(event_name)
    "cache.get"
  when WRITE_EVENT_NAMES.include?(event_name)
    "cache.put"
  when REMOVE_EVENT_NAMES.include?(event_name)
    "cache.remove"
  when FLUSH_EVENT_NAMES.include?(event_name)
    "cache.flush"
  else
    "other"
  end
end

.subscribe!Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/sentry/rails/tracing/active_support_subscriber.rb', line 31

def self.subscribe!
  subscribe_to_event(EVENT_NAMES) do |event_name, duration, payload|
    record_on_current_span(
      op: operation_name(event_name),
      origin: SPAN_ORIGIN,
      start_timestamp: payload[START_TIMESTAMP_NAME],
      description: payload[:store],
      duration: duration
    ) do |span|
      span.set_data("cache.key", [*payload[:key]].select { |key| Utils::EncodingHelper.valid_utf_8?(key) })
      span.set_data("cache.hit", payload[:hit] == true) # Handle nil case
    end
  end
end