Sha256: 00f08a73a2f1d9bac5e12f1b411586b585d90e8a4a191215cf1cd2c303b8a586

Contents?: true

Size: 1.09 KB

Versions: 24

Compression:

Stored size: 1.09 KB

Contents

# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2021

module Instana
  module Instrumentation
    class Shoryuken
      def call(_worker_instance, _queue, sqs_message, _body, &block)
        if sqs_message.is_a? Array
          return yield
        end

        sqs_tags = {
          sort: 'entry',
          queue: sqs_message.queue_url
        }

        context = incomming_context_from(sqs_message.message_attributes)
        ::Instana.tracer.start_or_continue_trace(:sqs, {sqs: sqs_tags}, context, &block)
      end

      private

      def incomming_context_from(attributes)
        trace_id = read_message_header(attributes, 'X_INSTANA_T')
        span_id = read_message_header(attributes, 'X_INSTANA_S')
        level = read_message_header(attributes, 'X_INSTANA_L')

        {
          trace_id: trace_id,
          span_id: span_id,
          level: level
        }.reject { |_, v| v.nil? }
      end

      def read_message_header(attributes, key)
        attributes[key].string_value if attributes && attributes[key] && attributes[key].respond_to?(:string_value)
      end
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
instana-1.217.1 lib/instana/instrumentation/shoryuken.rb
instana-1.217.0 lib/instana/instrumentation/shoryuken.rb
instana-1.216.0 lib/instana/instrumentation/shoryuken.rb
instana-1.215.1 lib/instana/instrumentation/shoryuken.rb
instana-1.215.0 lib/instana/instrumentation/shoryuken.rb
instana-1.214.4 lib/instana/instrumentation/shoryuken.rb
instana-1.214.3 lib/instana/instrumentation/shoryuken.rb
instana-1.214.2 lib/instana/instrumentation/shoryuken.rb
instana-1.214.1 lib/instana/instrumentation/shoryuken.rb
instana-1.214.0 lib/instana/instrumentation/shoryuken.rb
instana-1.213.3 lib/instana/instrumentation/shoryuken.rb
instana-1.213.2 lib/instana/instrumentation/shoryuken.rb
instana-1.213.1 lib/instana/instrumentation/shoryuken.rb
instana-1.213.0 lib/instana/instrumentation/shoryuken.rb
instana-1.212.0 lib/instana/instrumentation/shoryuken.rb
instana-1.211.0 lib/instana/instrumentation/shoryuken.rb
instana-1.210.1 lib/instana/instrumentation/shoryuken.rb
instana-1.210.0 lib/instana/instrumentation/shoryuken.rb
instana-1.209.8 lib/instana/instrumentation/shoryuken.rb
instana-1.209.7 lib/instana/instrumentation/shoryuken.rb