class ElasticAPM::Spies::SNSSpy

@api private

Constants

AP_REGEX
AP_REGION_REGEX
SUBTYPE
TYPE

Public Class Methods

arn_region(arn) click to toggle source
# File lib/elastic_apm/spies/sns.rb, line 60
def self.arn_region(arn)
  if arn && (match = AP_REGION_REGEX.match(arn))
    match[1]
  end
end
get_topic(params) click to toggle source
# File lib/elastic_apm/spies/sns.rb, line 40
def self.get_topic(params)
  return '<PHONE_NUMBER>' if params[:phone_number]

  last_after_slash_or_colon(
    params[:topic_arn] || params[:target_arn]
  )
end
last_after_slash_or_colon(arn) click to toggle source
# File lib/elastic_apm/spies/sns.rb, line 48
def self.last_after_slash_or_colon(arn)
  if index = arn.rindex(AP_REGEX)
    return arn[index+1..-1]
  end

  if arn.include?('/')
    arn.split('/')[-1]
  else
    arn.split(':')[-1]
  end
end
span_context(topic, region) click to toggle source
# File lib/elastic_apm/spies/sns.rb, line 66
def self.span_context(topic, region)
  ElasticAPM::Span::Context.new(
    message: { queue_name: topic },
    destination: {
      service: { resource: "#{SUBTYPE}/#{topic}" },
      cloud: { region: region }
    }
  )
end
without_net_http() { || ... } click to toggle source
# File lib/elastic_apm/spies/sns.rb, line 30
def self.without_net_http
  return yield unless defined?(NetHTTPSpy)

  # rubocop:disable Style/ExplicitBlockArgument
  ElasticAPM::Spies::NetHTTPSpy.disable_in do
    yield
  end
  # rubocop:enable Style/ExplicitBlockArgument
end

Public Instance Methods

install() click to toggle source
# File lib/elastic_apm/spies/sns.rb, line 115
def install
  ::Aws::SNS::Client.prepend(Ext)
end