Skip to content

Commit

Permalink
fix grape leading slash resource issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jethrodaniel committed Oct 27, 2024
1 parent 96294fa commit 9f46b17
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/datadog/tracing/contrib/grape/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def endpoint_expand_path(endpoint)
namespace = endpoint.routes.first && endpoint.routes.first.namespace || ''

parts = (namespace.split('/') + route_path).reject { |p| p.blank? || p.eql?('/') }
parts.join('/').prepend('/')
parts.join('/').delete_prefix('/').prepend('/')
end

def service_name
Expand Down
33 changes: 33 additions & 0 deletions spec/datadog/tracing/contrib/grape/tracer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@
'OK'
end
end

get '/path/with/leading/slash' do
'leading-slash'
end
end
)
end
Expand Down Expand Up @@ -126,6 +130,10 @@
'OK'
end
end

get '/path/with/leading/slash' do
'leading-slash'
end
end
)

Expand Down Expand Up @@ -719,6 +727,19 @@
end
end

context 'when the path has a leading slash' do
subject(:response) { get '/path/with/leading/slash' }

before do
is_expected.to be_ok
end

it 'sets the resource correctly' do
expect(trace.name).to eq('grape.endpoint_run')
expect(trace.resource).to eq('TestingAPI GET /path/with/leading/slash')
end
end

context 'when tracing is disabled' do
subject(:response) { get '/base/success' }

Expand Down Expand Up @@ -911,5 +932,17 @@
expect(trace.resource).to eq('RackTestingAPI GET /span_resource_rack/span_resource')
end
end

context 'when the path has a leading slash' do
subject(:response) { get '/api/path/with/leading/slash' }

before do
is_expected.to be_ok
end

it 'sets the resource correctly' do
expect(trace.resource).to eq('RackTestingAPI GET /path/with/leading/slash')
end
end
end
end

0 comments on commit 9f46b17

Please sign in to comment.