lib/elastic_apm/spies/sqs.rb in elastic-apm-3.15.1 vs lib/elastic_apm/spies/sqs.rb in elastic-apm-4.0.0.beta.1

- old
+ new

@@ -63,17 +63,16 @@ cloud: cloud } ) end - def install - ::Aws::SQS::Client.class_eval do - alias :send_message_without_apm :send_message - + # @api private + module Ext + def self.prepended(mod) def send_message(params = {}, options = {}) unless (transaction = ElasticAPM.current_transaction) - return send_message_without_apm(params, options) + return super(params, options) end queue_name = ElasticAPM::Spies::SQSSpy.queue_name(params) span_name = queue_name ? "SQS SEND to #{queue_name}" : 'SQS SEND' region = ElasticAPM::Spies::SQSSpy.region_from_url(params[:queue_url]) @@ -96,20 +95,18 @@ params[:message_attributes][key][:string_value] = value params[:message_attributes][key][:data_type] = 'String' end ElasticAPM::Spies::SQSSpy.without_net_http do - send_message_without_apm(params, options) + super(params, options) end end end - alias :send_message_batch_without_apm :send_message_batch - def send_message_batch(params = {}, options = {}) unless (transaction = ElasticAPM.current_transaction) - return send_message_batch_without_apm(params, options) + return super(params, options) end queue_name = ElasticAPM::Spies::SQSSpy.queue_name(params) span_name = queue_name ? "SQS SEND_BATCH to #{queue_name}" : 'SQS SEND_BATCH' @@ -125,30 +122,29 @@ subtype: SUBTYPE, action: 'send_batch', context: context ) do |span| trace_context = span&.trace_context || transaction.trace_context + trace_context.apply_headers do |key, value| params[:entries].each do |message| message[:message_attributes] ||= {} message[:message_attributes][key] ||= {} message[:message_attributes][key][:string_value] = value message[:message_attributes][key][:data_type] = 'String' end end ElasticAPM::Spies::SQSSpy.without_net_http do - send_message_batch_without_apm(params, options) + super(params, options) end end end - alias :receive_message_without_apm :receive_message - def receive_message(params = {}, options = {}) unless ElasticAPM.current_transaction - return receive_message_without_apm(params, options) + return super(params, options) end queue_name = ElasticAPM::Spies::SQSSpy.queue_name(params) span_name = queue_name ? "SQS RECEIVE from #{queue_name}" : 'SQS RECEIVE' @@ -164,20 +160,18 @@ subtype: SUBTYPE, action: 'receive', context: context ) do ElasticAPM::Spies::SQSSpy.without_net_http do - receive_message_without_apm(params, options) + super(params, options) end end end - alias :delete_message_without_apm :delete_message - def delete_message(params = {}, options = {}) unless ElasticAPM.current_transaction - return delete_message_without_apm(params, options) + return super(params, options) end queue_name = ElasticAPM::Spies::SQSSpy.queue_name(params) span_name = queue_name ? "SQS DELETE from #{queue_name}" : 'SQS DELETE' region = ElasticAPM::Spies::SQSSpy.region_from_url(params[:queue_url]) @@ -192,20 +186,18 @@ subtype: SUBTYPE, action: 'delete', context: context ) do ElasticAPM::Spies::SQSSpy.without_net_http do - delete_message_without_apm(params, options) + super(params, options) end end end - alias :delete_message_batch_without_apm :delete_message_batch - def delete_message_batch(params = {}, options = {}) unless ElasticAPM.current_transaction - return delete_message_batch_without_apm(params, options) + return super(params, options) end queue_name = ElasticAPM::Spies::SQSSpy.queue_name(params) span_name = queue_name ? "SQS DELETE_BATCH from #{queue_name}" : 'SQS DELETE_BATCH' @@ -221,14 +213,18 @@ subtype: SUBTYPE, action: 'delete_batch', context: context ) do ElasticAPM::Spies::SQSSpy.without_net_http do - delete_message_batch_without_apm(params, options) + super(params, options) end end end end + end + + def install + ::Aws::SQS::Client.prepend(Ext) end end register( 'Aws::SQS::Client',