class ElasticAPM::Spies::SNSSpy

@api private

def self.arn_region(arn)

def self.arn_region(arn)
  if arn && (match = AP_REGION_REGEX.match(arn))
    match[1]
  end
end

def self.get_topic(params)

def self.get_topic(params)
  return '[PHONENUMBER]' if params[:phone_number]
  last_after_slash_or_colon(
    params[:topic_arn] || params[:target_arn]
  )
end

def self.last_after_slash_or_colon(arn)

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

def self.span_context(topic, region)

def self.span_context(topic, region)
  ElasticAPM::Span::Context.new(
    message: { queue_name: topic },
    destination: {
      service: { resource: "#{SUBTYPE}/#{topic}" },
      cloud: { region: region }
    }
  )
end

def self.without_net_http

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

def install

def install
  ::Aws::SNS::Client.prepend(Ext)
end