Class: Appsignal::EventFormatter::ViewComponent::RenderFormatter

Inherits:
Appsignal::EventFormatter show all
Defined in:
lib/appsignal/event_formatter/view_component/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
21
# File 'lib/appsignal/event_formatter/view_component/render_formatter.rb', line 14

def format(payload)
  # The body is the component's path made relative to the application's
  # root, so a component rendered outside an application gets no title
  # and no body.
  return unless root_path

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

#opentelemetry_attributes(_payload) ⇒ Object



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

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

#root_pathObject

The application's root, which a component'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 component render in the application without a title.



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

def root_path
  return unless defined?(Rails)

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