Skip to content

Commit

Permalink
Fix grape endpoint resource name after upgrading grape
Browse files Browse the repository at this point in the history
  • Loading branch information
mattdisipio committed May 15, 2020
1 parent 4be8fef commit dcd0bd0
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions lib/ddtrace/contrib/grape/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,22 @@ def endpoint_run(name, start, finish, id, payload)
begin
# collect endpoint details
api = payload[:endpoint].options[:for]
# If the API inherits from Grape::API in version >= 1.2.0
# then the API will be an instance and the name must be derived from the base.
# See https://github.com/ruby-grape/grape/issues/1825
api_view = if defined?(::Grape::API::Instance) && api <= ::Grape::API::Instance
api.base.to_s
else
api.to_s
end

# BRAZE MODIFICATION
# The changes here https://github.com/ruby-grape/grape/issues/1825 don't work with the way we use grape
api_view = api.to_s

if api_view.blank?
# If the API inherits from Grape::API in version >= 1.2.0
# then the API will be an instance and the name must be derived from the base.
# See https://github.com/ruby-grape/grape/issues/1825
api_view = if defined?(::Grape::API::Instance) && api <= ::Grape::API::Instance
api.base.to_s
else
api.to_s
end
end

path = payload[:endpoint].options[:path].join('/')
resource = "#{api_view}##{path}"
span.resource = resource
Expand Down

0 comments on commit dcd0bd0

Please sign in to comment.