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

- old
+ new

@@ -1,5 +1,6 @@ +# typed: false require 'sinatra/base' require 'ddtrace/ext/app_types' require 'ddtrace/ext/errors' require 'ddtrace/ext/http' @@ -102,19 +103,28 @@ return super unless tracer.enabled tracer.trace( Ext::SPAN_ROUTE, service: configuration[:service_name], - span_type: Datadog::Ext::HTTP::TYPE_INBOUND + span_type: Datadog::Ext::HTTP::TYPE_INBOUND, + resource: "#{request.request_method} #{@datadog_route}", ) do |span| - span.resource = "#{request.request_method} #{@datadog_route}" - 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 # DEV: Is it possible for sinatra_request_span to ever be nil here? + sinatra_request_span.resource = span.resource + end Contrib::Analytics.set_measured(span) super end