lib/ddtrace/contrib/sinatra/tracer.rb in ddtrace-0.52.0 vs lib/ddtrace/contrib/sinatra/tracer.rb in ddtrace-0.53.0

- old
+ new

@@ -3,11 +3,11 @@ require 'ddtrace/ext/app_types' require 'ddtrace/ext/errors' require 'ddtrace/ext/http' require 'ddtrace/propagation/http_propagator' - +require 'ddtrace/utils/only_once' require 'ddtrace/contrib/sinatra/ext' require 'ddtrace/contrib/sinatra/tracer_middleware' require 'ddtrace/contrib/sinatra/env' module Datadog @@ -75,10 +75,13 @@ end end # Method overrides for Sinatra::Base module Base + MISSING_REQUEST_SPAN_ONLY_ONCE = Datadog::Utils::OnlyOnce.new + private_constant :MISSING_REQUEST_SPAN_ONLY_ONCE + 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| @@ -119,11 +122,21 @@ 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 # DEV: Is it possible for sinatra_request_span to ever be nil here? + 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