module OneApm::Agent::Instrumentation::Grape

Constants

OA_API_ENDPOINT
OA_EMPTY_STRING
OA_FORMAT_REGEX
OA_MIN_VERSION
OA_VERSION_REGEX

Public Instance Methods

capture_params(endpoint) click to toggle source
# File lib/one_apm/inst/framework/grape.rb, line 52
def capture_params(endpoint)
  txn = Transaction.tl_current
  env = endpoint.request.env
  params = OneApm::Support::ParameterFiltering::apply_filters(env, endpoint.params)
  params.delete("route_info")
  txn.filtered_params = params
end
handle_transaction(endpoint, class_name) click to toggle source
# File lib/one_apm/inst/framework/grape.rb, line 17
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]
end
name_for_transaction(route, class_name) click to toggle source
# File lib/one_apm/inst/framework/grape.rb, line 29
def name_for_transaction(route, class_name)
  route_path, route_method, route_version = path_method_version_of(route)
  action_name = route_path.sub(OA_FORMAT_REGEX, OA_EMPTY_STRING)
  method_name = route_method

  if route_version
    action_name = action_name.sub(OA_VERSION_REGEX, OA_EMPTY_STRING)
    "#{class_name}-#{route_version}#{action_name} (#{method_name})"
  else
    "#{class_name}#{action_name} (#{method_name})"
  end
end
name_transaction(route, class_name) click to toggle source
# File lib/one_apm/inst/framework/grape.rb, line 23
def name_transaction(route, class_name)
  txn_name = name_for_transaction(route, class_name)
  segment_name = "Middleware/Grape/#{class_name}/call"
  Transaction.set_default_transaction_name(txn_name, :grape, segment_name)
end
path_method_version_of(route) click to toggle source
# File lib/one_apm/inst/framework/grape.rb, line 43
def path_method_version_of(route)
  [route.path, route.request_method, route.version]
end