Module: Datadog::Contrib::Rails::ActionView

Includes:
Patcher
Defined in:
lib/ddtrace/contrib/rails/action_view.rb

Overview

Code used to create and handle ‘rails.render_template’ and ‘rails.render_partial’ spans.

Class Method Summary collapse

Methods included from Patcher

included

Methods included from Patcher::CommonMethods

#do_once, #without_warnings

Class Method Details

.finish_render_partial(payload) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/ddtrace/contrib/rails/action_view.rb', line 62

def self.finish_render_partial(payload)
  # retrieve the tracing context and the latest active span
  tracing_context = payload.fetch(:tracing_context)
  span = tracing_context[:dd_rails_partial_span]
  return if !span || span.finished?

  # finish the tracing and update the execution time
  begin
    template_name = tracing_context[:template_name]
    exception = tracing_context[:exception]

    span.set_tag('rails.template_name', template_name) if template_name
    span.set_error(exception) if exception
  ensure
    span.finish()
  end
rescue StandardError => e
  Datadog::Tracer.log.debug(e.message)
end

.finish_render_template(payload) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/ddtrace/contrib/rails/action_view.rb', line 29

def self.finish_render_template(payload)
  # retrieve the tracing context and the latest active span
  tracing_context = payload.fetch(:tracing_context)
  span = tracing_context[:dd_rails_template_span]
  return if !span || span.finished?

  # finish the tracing and update the execution time
  begin
    template_name = tracing_context[:template_name]
    layout = tracing_context[:layout]
    exception = tracing_context[:exception]

    span.set_tag('rails.template_name', template_name) if template_name
    span.set_tag('rails.layout', layout) if layout
    span.set_error(exception) if exception
  ensure
    span.finish()
  end
rescue StandardError => e
  Datadog::Tracer.log.debug(e.message)
end

.instrumentObject



10
11
12
13
14
15
# File 'lib/ddtrace/contrib/rails/action_view.rb', line 10

def self.instrument
  # patch Rails core components
  do_once(:instrument) do
    Datadog::RailsRendererPatcher.patch_renderer
  end
end

.start_render_partial(payload) ⇒ Object



51
52
53
54
55
56
57
58
59
60
# File 'lib/ddtrace/contrib/rails/action_view.rb', line 51

def self.start_render_partial(payload)
  # retrieve the tracing context
  tracing_context = payload.fetch(:tracing_context)

  tracer = Datadog.configuration[:rails][:tracer]
  span = tracer.trace('rails.render_partial', span_type: Datadog::Ext::HTTP::TEMPLATE)
  tracing_context[:dd_rails_partial_span] = span
rescue StandardError => e
  Datadog::Tracer.log.debug(e.message)
end

.start_render_template(payload) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ddtrace/contrib/rails/action_view.rb', line 17

def self.start_render_template(payload)
  # retrieve the tracing context
  tracing_context = payload.fetch(:tracing_context)

  # create a new Span and add it to the tracing context
  tracer = Datadog.configuration[:rails][:tracer]
  span = tracer.trace('rails.render_template', span_type: Datadog::Ext::HTTP::TEMPLATE)
  tracing_context[:dd_rails_template_span] = span
rescue StandardError => e
  Datadog::Tracer.log.debug(e.message)
end