Class: Appsignal::EventFormatter::ActionView::RenderFormatter

Inherits:
Appsignal::EventFormatter show all
Defined in:
lib/appsignal/event_formatter/action_view/render_formatter.rb

Constant Summary collapse

BLANK =
""

Constants inherited from Appsignal::EventFormatter

DEFAULT, SQL_BODY_FORMAT

Instance Method Summary collapse

Methods inherited from Appsignal::EventFormatter

register, registered?, unregister

Instance Method Details

#format(payload) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/appsignal/event_formatter/action_view/render_formatter.rb', line 14

def format(payload)
  # The title is the template's path made relative to the application's
  # root, so a template rendered outside an application gets no title.
  return unless payload[:identifier] && root_path

  [payload[:identifier].sub(root_path, BLANK), nil]
end

#opentelemetry_attributes(_payload) ⇒ Object



10
11
12
# File 'lib/appsignal/event_formatter/action_view/render_formatter.rb', line 10

def opentelemetry_attributes(_payload)
  Appsignal::OpenTelemetry::Rendering.attributes
end

#root_pathObject

The application's root, which a template's path is made relative to.

Whether there is an application is decided here, when the event is formatted, rather than when this file is loaded. AppSignal can be required before Rails is, and deciding it at load time would leave every template render in the application without a title.



28
29
30
31
32
# File 'lib/appsignal/event_formatter/action_view/render_formatter.rb', line 28

def root_path
  return unless defined?(Rails)

  @root_path ||= "#{Rails.root}/"
end