Module: OneApm::Agent::Instrumentation::Grape

Extended by:
Grape
Included in:
Grape
Defined in:
lib/one_apm/inst/framework/grape.rb

Constant Summary collapse

OA_API_ENDPOINT =
'api.endpoint'.freeze
OA_FORMAT_REGEX =
/\(\/?\.(:format|json)?\)/.freeze
OA_VERSION_REGEX =
/:version(\/|$)/.freeze
OA_EMPTY_STRING =
''.freeze
OA_MIN_VERSION =
VersionNumber.new('0.2.0')

Instance Method Summary collapse

Instance Method Details

#capture_params(endpoint) ⇒ Object



52
53
54
55
56
57
58
# 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) ⇒ Object



17
18
19
20
21
# 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) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
# 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) ⇒ Object



23
24
25
26
27
# 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) ⇒ Object



43
44
45
# File 'lib/one_apm/inst/framework/grape.rb', line 43

def path_method_version_of(route)
  [route.path, route.request_method, route.version]
end