module NewRelic::Agent::Instrumentation::AwsSqs

Constants

MESSAGING_LIBRARY

Public Instance Methods

receive_message_with_new_relic(*args) { || ... } click to toggle source
# File lib/new_relic/agent/instrumentation/aws_sqs/instrumentation.rb, line 21
def receive_message_with_new_relic(*args)
  with_tracing(:consume, args) do
    yield
  end
end
send_message_batch_with_new_relic(*args) { || ... } click to toggle source
# File lib/new_relic/agent/instrumentation/aws_sqs/instrumentation.rb, line 15
def send_message_batch_with_new_relic(*args)
  with_tracing(:produce, args) do
    yield
  end
end
send_message_with_new_relic(*args) { || ... } click to toggle source
# File lib/new_relic/agent/instrumentation/aws_sqs/instrumentation.rb, line 9
def send_message_with_new_relic(*args)
  with_tracing(:produce, args) do
    yield
  end
end
with_tracing(action, params) { || ... } click to toggle source
# File lib/new_relic/agent/instrumentation/aws_sqs/instrumentation.rb, line 27
def with_tracing(action, params)
  segment = nil
  begin
    info = get_url_info(params[0])
    segment = NewRelic::Agent::Tracer.start_message_broker_segment(
      action: action,
      library: MESSAGING_LIBRARY,
      destination_type: :queue,
      destination_name: info[:queue_name]
    )
    add_aws_attributes(segment, info)
  rescue => e
    NewRelic::Agent.logger.error('Error starting message broker segment in Aws::SQS::Client', e)
  end
  NewRelic::Agent::Tracer.capture_segment_error(segment) do
    yield
  end
ensure
  segment&.finish
end

Private Instance Methods

add_aws_attributes(segment, info) click to toggle source
# File lib/new_relic/agent/instrumentation/aws_sqs/instrumentation.rb, line 50
def add_aws_attributes(segment, info)
  return unless segment

  segment.add_agent_attribute('messaging.system', 'aws_sqs')
  segment.add_agent_attribute('cloud.region', config&.region)
  segment.add_agent_attribute('cloud.account.id', info[:account_id])
  segment.add_agent_attribute('messaging.destination.name', info[:queue_name])
end
get_url_info(params) click to toggle source
# File lib/new_relic/agent/instrumentation/aws_sqs/instrumentation.rb, line 59
def get_url_info(params)
  split = params[:queue_url].split('/')
  {
    queue_name: split.last,
    account_id: split[-2]
  }
end