Module: Datadog::Contrib::Sinatra::Tracer::Base
- Defined in:
- lib/ddtrace/contrib/sinatra/tracer.rb
Overview
Method overrides for Sinatra::Base
Instance Method Summary collapse
- #render(engine, data) ⇒ Object
-
#route_eval ⇒ Object
Invoked when a matching route is found.
Instance Method Details
#render(engine, data) ⇒ Object
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/ddtrace/contrib/sinatra/tracer.rb', line 83 def render(engine, data, *) tracer = Datadog.configuration[:sinatra][:tracer] return super unless tracer.enabled tracer.trace(Ext::SPAN_RENDER_TEMPLATE, span_type: Datadog::Ext::HTTP::TEMPLATE) do |span| 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_eval ⇒ Object
Invoked when a matching route is found. This method yields directly to user code.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/ddtrace/contrib/sinatra/tracer.rb', line 103 def route_eval configuration = Datadog.configuration[:sinatra] tracer = configuration[:tracer] return super unless tracer.enabled tracer.trace( Ext::SPAN_ROUTE, service: configuration[:service_name], span_type: Datadog::Ext::HTTP::TYPE_INBOUND, resource: "#{request.request_method} #{@datadog_route}", ) do |span| span.set_tag(Ext::TAG_APP_NAME, settings.name || settings.superclass.name) span.set_tag(Ext::TAG_ROUTE_PATH, @datadog_route) span.set_tag(Ext::TAG_SCRIPT_NAME, request.script_name) if request.script_name && !request.script_name.empty? rack_request_span = env[Datadog::Contrib::Rack::TraceMiddleware::RACK_REQUEST_SPAN] rack_request_span.resource = span.resource if rack_request_span sinatra_request_span = if self.class <= ::Sinatra::Application # Classic style (top-level) application Sinatra::Env.datadog_span(env, ::Sinatra::Application) else Sinatra::Env.datadog_span(env, self.class) end if sinatra_request_span sinatra_request_span.resource = span.resource else MISSING_REQUEST_SPAN_ONLY_ONCE.run do Datadog.logger.warn do 'Sinatra integration is misconfigured, reported traces will be missing request metadata ' \ 'such as path and HTTP status code. ' \ 'Did you forget to add `register Datadog::Contrib::Sinatra::Tracer` to your ' \ '`Sinatra::Base` subclass? ' \ 'See <https://docs.datadoghq.com/tracing/setup_overview/setup/ruby/#sinatra> for more details.' end end end Contrib::Analytics.set_measured(span) super end end |