Module: Datadog::Tracing::Contrib::ActionView::Utils

Defined in:
lib/datadog/tracing/contrib/action_view/utils.rb

Overview

common utilities for Rails

Class Method Summary collapse

Class Method Details

.normalize_template_name(name) ⇒ Object

in Rails the template name includes the template full path and it’s better to avoid storing such information. This method returns the relative path from ‘views/` or the template name if a `views/` folder is not in the template full path. A wrong usage ensures that this method will not crash the tracing system.



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/datadog/tracing/contrib/action_view/utils.rb', line 18

def normalize_template_name(name)
  return if name.nil?

  base_path = Datadog.configuration.tracing[:action_view][:template_base_path]
  sections_view = name.split(base_path)

  if sections_view.length == 1
    name.split('/')[-1]
  else
    sections_view[-1]
  end
rescue
  name.to_s
end