class NewRelic::Agent::ServerlessHandlerEventSources

ServerlessHandlerEventSources - New Relic’s language agent devs maintain a cross-agent JSON map of all AWS resources with the potential to invoke an AWS Lambda function by issuing it an event. This map is used to glean source specific attributes while instrumenting the function’s invocation.

Given that the event arrives as a Ruby hash argument to the AWS Lambda function, the JSON map’s values need to be converted into arrays that can be passed to ‘Hash#dig`. So a value such as `’records.name’‘ needs to be converted to `[’records’, 0, ‘name’]‘. This class’s ‘.to_hash` method yields the converted data.

Furthermore, ‘.length` calls are converted to Ruby `#size` notation to denote that a method call must be performed on the dug value.

Constants

JSON_RAW
JSON_SOURCE

Public Class Methods

to_hash() click to toggle source
# File lib/new_relic/agent/serverless_handler_event_sources.rb, line 26
def self.to_hash
  JSON_RAW.each_with_object({}) do |(type, info), hash|
    hash[type] = {'attributes' => {},
                  'name' => info['name'],
                  'required_keys' => []}
    info['attributes'].each { |attr, value| hash[type]['attributes'][attr] = transform(value) }
    info['required_keys'].each { |key| hash[type]['required_keys'].push(transform(key)) }
  end.freeze
end
transform(value) click to toggle source
# File lib/new_relic/agent/serverless_handler_event_sources.rb, line 36
def self.transform(value)
  value.gsub(/\[(\d+)\]/, '.\1').split('.').map do |e|
    if e.match?(/^\d+$/)
      e.to_i
    elsif e == 'length'
      '#size'
    else
      e
    end
  end
end