Module: Datadog::Tracing::Contrib::Sinatra::Tracer::Base

Defined in:
lib/datadog/tracing/contrib/sinatra/tracer.rb

Overview

Method overrides for Sinatra::Base

Instance Method Summary collapse

Instance Method Details

#render(engine, data) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/datadog/tracing/contrib/sinatra/tracer.rb', line 24

def render(engine, data, *)
  return super unless Tracing.enabled?

  Tracing.trace(Ext::SPAN_RENDER_TEMPLATE, span_type: Tracing::Metadata::Ext::HTTP::TYPE_TEMPLATE) do |span|
    span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
    span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_RENDER_TEMPLATE)

    span.set_tag(Ext::TAG_TEMPLATE_ENGINE, engine)

    # If data is a string, it is a literal template and we don't
    # want to record it.
    span.set_tag(Ext::TAG_TEMPLATE_NAME, data) if data.is_a? Symbol

    # Measure service stats
    Contrib::Analytics.set_measured(span)

    super
  end
end

#route_evalObject

Invoked when a matching route is found. This method yields directly to user code.



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/datadog/tracing/contrib/sinatra/tracer.rb', line 46

def route_eval
  configuration = Datadog.configuration.tracing[:sinatra]
  return super unless Tracing.enabled?

  datadog_route = Sinatra::Env.route_path(env)

  Tracing.trace(
    Ext::SPAN_ROUTE,
    service: configuration[:service_name],
    span_type: Tracing::Metadata::Ext::HTTP::TYPE_INBOUND,
    resource: "#{request.request_method} #{datadog_route}",
  ) do |span, trace|
    span.set_tag(Ext::TAG_APP_NAME, settings.name || settings.superclass.name)
    span.set_tag(Ext::TAG_ROUTE_PATH, datadog_route)

    if request.script_name && !request.script_name.empty?
      span.set_tag(Ext::TAG_SCRIPT_NAME, request.script_name)
    end

    span.set_tag(Tracing::Metadata::Ext::TAG_COMPONENT, Ext::TAG_COMPONENT)
    span.set_tag(Tracing::Metadata::Ext::TAG_OPERATION, Ext::TAG_OPERATION_ROUTE)

    trace.resource = span.resource

    sinatra_request_span = Sinatra::Env.datadog_span(env)

    sinatra_request_span.resource = span.resource

    Contrib::Analytics.set_measured(span)

    super
  end
end