Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions lib/datadog/tracing/contrib/rack/middlewares.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,17 +141,6 @@ def set_request_tags!(trace, request_span, env, status, headers, response, origi
if status != 404 && (last_route = trace.get_tag(Tracing::Metadata::Ext::HTTP::TAG_ROUTE))
last_script_name = trace.get_tag(Tracing::Metadata::Ext::HTTP::TAG_ROUTE_PATH) || ''

# If the last_script_name is empty but the env['SCRIPT_NAME'] is NOT empty
# then the current rack request was not routed and must be accounted for
# which only happens in pure nested rack requests i.e /rack/rack/hello/world
#
# To account for the unaccounted nested rack requests of /rack/hello/world,
# we use 'PATH_INFO knowing that rack cannot have named parameters
if last_script_name == '' && env['SCRIPT_NAME'] && env['SCRIPT_NAME'] != ''
last_script_name = last_route
last_route = env['PATH_INFO']
end

# Clear the route and route path tags from the request trace to avoid possibility of misplacement
trace.clear_tag(Tracing::Metadata::Ext::HTTP::TAG_ROUTE)
trace.clear_tag(Tracing::Metadata::Ext::HTTP::TAG_ROUTE_PATH)
Expand Down Expand Up @@ -218,10 +207,6 @@ def set_request_tags!(trace, request_span, env, status, headers, response, origi
request_span.set_tag(Tracing::Metadata::Ext::HTTP::TAG_USER_AGENT, user_agent)
end

if request_span.get_tag(Tracing::Metadata::Ext::HTTP::TAG_ROUTE).nil? && status != 404
request_span.set_tag(Tracing::Metadata::Ext::HTTP::TAG_ROUTE, env['PATH_INFO'])
end

HeaderTagging.tag_request_headers(request_span, request_header_collection, configuration)
HeaderTagging.tag_response_headers(request_span, headers, configuration) if headers

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,43 @@

describe '#find_routes' do
before do
engine.routes.append do
stub_const('AuthEngine', Module.new)

stub_const(
'AuthEngine::TokensController',
Class.new(ActionController::Base) do
def create
head :ok
end
end
)

auth_engine = stub_const(
'AuthEngine::Engine',
Class.new(::Rails::Engine) do
isolate_namespace AuthEngine
end
)

auth_engine.routes.append do
get '/sign-in' => 'tokens#create'
end

auth_engine = engine
rack_status_app = rack_app.new
rack_status_app = stub_const(
'RackStatusApp',
Class.new do
def call(_env)
[200, {'Content-Type' => 'text/plain'}, ['OK']]
end
end
)

rails_test_application.instance.routes.append do
namespace :api, defaults: {format: :json} do
resources :users, only: %i[show]

mount auth_engine => '/auth'

match '/status', to: rack_status_app, via: :get
mount rack_status_app.new => '/status'
end

get '/items/:id', to: 'items#by_id', id: /\d+/
Expand All @@ -47,17 +70,6 @@
end
end

let(:rack_app) do
stub_const(
'RackStatusApp',
Class.new do
def call(_env)
[200, {'Content-Type' => 'text/plain'}, ['OK']]
end
end
)
end

let(:controllers) { [users_controller, items_controller, books_controller] }

let(:users_controller) do
Expand Down Expand Up @@ -101,37 +113,6 @@ def show
)
end

let(:status_controller) do
stub_const(
'StatusesController',
Class.new(ActionController::Base) do
def show
head :ok
end
end
)
end

let(:engine) do
stub_const('AuthEngine', Module.new)

stub_const(
'AuthEngine::TokensController',
Class.new(ActionController::Base) do
def create
head :ok
end
end
)

stub_const(
'AuthEngine::Engine',
Class.new(::Rails::Engine) do
isolate_namespace AuthEngine
end
)
end

context 'with default configuration' do
before do
Datadog.configure do |c|
Expand Down Expand Up @@ -208,8 +189,8 @@ def create
expect(request_span.tags).not_to have_key('http.route.path')
end

it 'sets http.route for a route to a rack app' do
get '/api/status'
it 'sets http.route for a route to a mounted rack app' do
get '/api/status/some_path'

request_span = spans.first

Expand Down
73 changes: 0 additions & 73 deletions spec/datadog/tracing/contrib/rack/http_route_spec.rb

This file was deleted.