Sha256: cd3ccd447c0e050794f1dfcda24201a43ec47c217ba71a7059a05c4a90a19732

Contents?: true

Size: 1.85 KB

Versions: 11

Compression:

Stored size: 1.85 KB

Contents

# frozen_string_literal: true

# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0

module OpenTelemetry
  module Instrumentation
    module AwsSdk
      # MessagingHelper class provides methods for calculating messaging span attributes
      class MessagingHelper
        class << self
          def queue_name(context)
            topic_arn = context.params[:topic_arn]
            target_arn = context.params[:target_arn]

            if topic_arn || target_arn
              arn = topic_arn || target_arn
              return arn.split(':')[-1]
            end

            phone_number = context.params[:phone_number]
            return 'phone_number' if phone_number

            queue_url = context.params[:queue_url]
            return queue_url.split('/')[-1] if queue_url

            'unknown'
          end

          def apply_sqs_attributes(attributes, context, client_method)
            attributes[SemanticConventions::Trace::MESSAGING_SYSTEM] = 'aws.sqs'
            attributes[SemanticConventions::Trace::MESSAGING_DESTINATION_KIND] = 'queue'
            attributes[SemanticConventions::Trace::MESSAGING_DESTINATION] = queue_name(context)
            attributes[SemanticConventions::Trace::MESSAGING_URL] = context.params[:queue_url] if context.params[:queue_url]

            attributes[SemanticConventions::Trace::MESSAGING_OPERATION] = 'receive' if client_method == 'SQS.ReceiveMessage'
          end

          def apply_sns_attributes(attributes, context, client_method)
            attributes[SemanticConventions::Trace::MESSAGING_SYSTEM] = 'aws.sns'

            return unless client_method == 'SNS.Publish'

            attributes[SemanticConventions::Trace::MESSAGING_DESTINATION_KIND] = 'topic'
            attributes[SemanticConventions::Trace::MESSAGING_DESTINATION] = queue_name(context)
          end
        end
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
opentelemetry-instrumentation-aws_sdk-0.5.4 lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb
opentelemetry-instrumentation-aws_sdk-0.5.3 lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb
opentelemetry-instrumentation-aws_sdk-0.5.2 lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb
opentelemetry-instrumentation-aws_sdk-0.5.1 lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb
opentelemetry-instrumentation-aws_sdk-0.5.0 lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb
opentelemetry-instrumentation-aws_sdk-0.4.2 lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb
opentelemetry-instrumentation-aws_sdk-0.4.1 lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb
opentelemetry-instrumentation-aws_sdk-0.4.0 lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb
opentelemetry-instrumentation-aws_sdk-0.3.2 lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb
opentelemetry-instrumentation-aws_sdk-0.3.1 lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb
aspecto-opentelemetry-instrumentation-aws_sdk-0.3.0 lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb