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

Included in:
Rails31To5, Rails6Plus
Defined in:
lib/ddtrace/contrib/action_view/instrumentation/template_renderer.rb

Overview

Shared code for Rails >= 3.1 template rendering

Instance Method Summary collapse

Instance Method Details

#datadog_render_template(template, layout_name) ⇒ Object



109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/ddtrace/contrib/action_view/instrumentation/template_renderer.rb', line 109

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.set_tag(
      Ext::TAG_TEMPLATE_NAME,
      template_name
    )
  end

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

#render(*args, &block) ⇒ Object



87
88
89
90
91
92
93
94
# File 'lib/ddtrace/contrib/action_view/instrumentation/template_renderer.rb', line 87

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



96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/ddtrace/contrib/action_view/instrumentation/template_renderer.rb', line 96

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

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

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