lib/one_apm/inst/framework/grape.rb in oneapm_rpm-1.3.5 vs lib/one_apm/inst/framework/grape.rb in oneapm_rpm-1.3.6.rc1

- old
+ new

@@ -7,14 +7,14 @@ module Instrumentation module Grape extend self API_ENDPOINT = 'api.endpoint'.freeze - FORMAT_REGEX = /\(\/?\.:format\)/.freeze + FORMAT_REGEX = /\(\/?\.(:format|json)?\)/.freeze VERSION_REGEX = /:version(\/|$)/.freeze EMPTY_STRING = ''.freeze - MIN_VERSION = VersionNumber.new("0.2.0") + MIN_VERSION = VersionNumber.new('0.2.0') def handle_transaction(endpoint, class_name) return unless endpoint && route = endpoint.route name_transaction(route, class_name) capture_params(endpoint) if OneApm::Manager.config[:capture_params] @@ -25,17 +25,28 @@ segment_name = "Middleware/Grape/#{class_name}/call" Transaction.set_default_transaction_name(txn_name, :grape, segment_name) end def name_for_transaction(route, class_name) - action_name = route.route_path.sub(FORMAT_REGEX, EMPTY_STRING) - method_name = route.route_method + route_path, route_method, route_version = path_method_version_of(route) + action_name = route_path.sub(FORMAT_REGEX, EMPTY_STRING) + method_name = route_method - if route.route_version + if route_version action_name = action_name.sub(VERSION_REGEX, EMPTY_STRING) - "#{class_name}-#{route.route_version}#{action_name} (#{method_name})" + "#{class_name}-#{route_version}#{action_name} (#{method_name})" else "#{class_name}#{action_name} (#{method_name})" + end + end + + if defined?(::Grape::VERSION) && VersionNumber.new(::Grape::VERSION) >= VersionNumber.new('0.16.0') + def path_method_version_of(route) + [route.path, route.request_method, route.version] + end + else + def path_method_version_of(route) + [route.route_path, route.route_method, route.route_version] end end def capture_params(endpoint) txn = Transaction.tl_current