Module: Rails::Instrumentation::ActionControllerSubscriber

Includes:
Subscriber
Defined in:
lib/rails/instrumentation/subscribers/action_controller_subscriber.rb

Constant Summary collapse

EVENT_NAMESPACE =
'action_controller'.freeze
EVENTS =
%w[
  write_fragment
  read_fragment
  expire_fragment
  exist_fragment?
  write_page
  expire_page
  start_processing
  process_action
  send_file
  send_data
  redirect_to
  halted_callback
  unpermitted_parameters
].freeze
BASE_TAGS =

rubocop:disable Style/MutableConstant

{ 'component' => 'ActionController' }

Class Method Summary collapse

Methods included from Subscriber

included

Class Method Details

.exist_fragment?(event) ⇒ Boolean

Returns:

  • (Boolean)


53
54
55
56
57
58
59
# File 'lib/rails/instrumentation/subscribers/action_controller_subscriber.rb', line 53

def exist_fragment?(event)
  tags = span_tags(
    'key.exist' => event.payload[:key]
  )

  Utils.trace_notification(event: event, tags: tags)
end

.expire_fragment(event) ⇒ Object



45
46
47
48
49
50
51
# File 'lib/rails/instrumentation/subscribers/action_controller_subscriber.rb', line 45

def expire_fragment(event)
  tags = span_tags(
    'key.expire' => event.payload[:key]
  )

  Utils.trace_notification(event: event, tags: tags)
end

.expire_page(event) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/rails/instrumentation/subscribers/action_controller_subscriber.rb', line 69

def expire_page(event)
  tags = span_tags(
    'path.expire' => event.payload[:path]
  )

  Utils.trace_notification(event: event, tags: tags)
end

.halted_callback(event) ⇒ Object



145
146
147
148
149
150
151
# File 'lib/rails/instrumentation/subscribers/action_controller_subscriber.rb', line 145

def halted_callback(event)
  tags = span_tags(
    'filter' => event.payload[:filter]
  )

  Utils.trace_notification(event: event, tags: tags)
end

.process_action(event) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/rails/instrumentation/subscribers/action_controller_subscriber.rb', line 90

def process_action(event)
  span_name = "#{event.payload[:controller]}.#{event.payload[:action]}"

  tags = span_tags(
    'controller' => event.payload[:controller],
    'controller.action' => event.payload[:action],
    'request.params' => event.payload[:params],
    'request.format' => event.payload[:format],
    'http.method' => event.payload[:method],
    'http.url' => event.payload[:path],
    'http.status_code' => event.payload[:status],
    'view.runtime.ms' => event.payload[:view_runtime],
    'db.runtime.ms' => event.payload[:db_runtime],
    'span.kind' => 'server'
  )

  # Only append these tags onto the active span created by the patched 'process_action'
  # Otherwise, create a new span for this notification as usual
  active_span = ::Rails::Instrumentation.tracer.active_span
  if active_span && active_span.operation_name == span_name
    tags.each do |key, value|
      ::Rails::Instrumentation.tracer.active_span.set_tag(key, value)
    end
  else
    Utils.trace_notification(event: event, tags: tags)
  end
end

.read_fragment(event) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/rails/instrumentation/subscribers/action_controller_subscriber.rb', line 37

def read_fragment(event)
  tags = span_tags(
    'key.read' => event.payload[:key]
  )

  Utils.trace_notification(event: event, tags: tags)
end

.redirect_to(event) ⇒ Object



136
137
138
139
140
141
142
143
# File 'lib/rails/instrumentation/subscribers/action_controller_subscriber.rb', line 136

def redirect_to(event)
  tags = span_tags(
    'http.status_code' => event.payload[:status],
    'redirect.url' => event.payload[:location]
  )

  Utils.trace_notification(event: event, tags: tags)
end

.send_data(event) ⇒ Object



129
130
131
132
133
134
# File 'lib/rails/instrumentation/subscribers/action_controller_subscriber.rb', line 129

def send_data(event)
  # no defined keys, but user keys may be passed in. Might want to add
  # them at some point

  Utils.trace_notification(event: event, tags: BASE_TAGS)
end

.send_file(event) ⇒ Object



118
119
120
121
122
123
124
125
126
127
# File 'lib/rails/instrumentation/subscribers/action_controller_subscriber.rb', line 118

def send_file(event)
  tags = span_tags(
    'path.send' => event.payload[:path]
  )

  # there may be additional keys in the payload. It might be worth
  # trying to tag them too

  Utils.trace_notification(event: event, tags: tags)
end

.start_processing(event) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/rails/instrumentation/subscribers/action_controller_subscriber.rb', line 77

def start_processing(event)
  tags = span_tags(
    'controller' => event.payload[:controller],
    'controller.action' => event.payload[:action],
    'request.params' => event.payload[:params],
    'request.format' => event.payload[:format],
    'http.method' => event.payload[:method],
    'http.url' => event.payload[:path]
  )

  Utils.trace_notification(event: event, tags: tags)
end

.unpermitted_parameters(event) ⇒ Object



153
154
155
156
157
158
159
# File 'lib/rails/instrumentation/subscribers/action_controller_subscriber.rb', line 153

def unpermitted_parameters(event)
  tags = span_tags(
    'unpermitted_keys' => event.payload[:keys]
  )

  Utils.trace_notification(event: event, tags: tags)
end

.write_fragment(event) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/rails/instrumentation/subscribers/action_controller_subscriber.rb', line 29

def write_fragment(event)
  tags = span_tags(
    'key.write' => event.payload[:key]
  )

  Utils.trace_notification(event: event, tags: tags)
end

.write_page(event) ⇒ Object



61
62
63
64
65
66
67
# File 'lib/rails/instrumentation/subscribers/action_controller_subscriber.rb', line 61

def write_page(event)
  tags = span_tags(
    'path.write' => event.payload[:path]
  )

  Utils.trace_notification(event: event, tags: tags)
end