Module: Datadog::Contrib::ActionView::Instrumentation::TemplateRenderer::Rails31Plus

Included in:
RailsLessThan4
Defined in:
lib/ddtrace/contrib/action_view/instrumentation/template_renderer.rb

Overview

Legacy shared code for Rails >= 3.1 template rendering

Instance Method Summary collapse

Instance Method Details

#datadog_render_template(template, layout_name) ⇒ Object



114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/ddtrace/contrib/action_view/instrumentation/template_renderer.rb', line 114

def datadog_render_template(template, layout_name)
  # update the tracing context with computed values before the rendering
  template_name = template.try('identifier')
  template_name = Utils.normalize_template_name(template_name)
  layout = layout_name.try(:[], 'virtual_path') # Proc can be called without parameters since Rails 6

  if template_name
    active_datadog_span.resource = template_name
    active_datadog_span.set_tag(
      Ext::TAG_TEMPLATE_NAME,
      template_name
    )
  end

  if layout
    active_datadog_span.set_tag(
      Ext::TAG_LAYOUT,
      layout
    )
  end

  # Measure service stats
  Contrib::Analytics.set_measured(active_datadog_span)
end

#render(*args, &block) ⇒ Object



92
93
94
95
96
97
98
99
# File 'lib/ddtrace/contrib/action_view/instrumentation/template_renderer.rb', line 92

def render(*args, &block)
  datadog_tracer.trace(
    Ext::SPAN_RENDER_TEMPLATE,
    span_type: Datadog::Ext::HTTP::TEMPLATE
  ) do |span|
    with_datadog_span(span) { super(*args, &block) }
  end
end

#render_template(*args) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/ddtrace/contrib/action_view/instrumentation/template_renderer.rb', line 101

def render_template(*args)
  begin
    template, layout_name = datadog_parse_args(*args)

    datadog_render_template(template, layout_name)
  rescue StandardError => e
    Datadog.logger.debug(e.message)
  end

  # execute the original function anyway
  super(*args)
end