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 60febf8 commit 81a501f
Show file tree
Hide file tree
Showing 2 changed files with 18 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
17 changes: 17 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 '/some/nested/path/:uuid' do
'nested-path'
end
end
)
end
Expand Down Expand Up @@ -719,6 +723,19 @@
end
end

describe 'nested path resource' do
subject(:response) { get '/some/nested/path/:uuid' }

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 /some/nested/path/:uuid')
end
end

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

Expand Down

0 comments on commit 81a501f

Please sign in to comment.