class OpenTelemetry::Instrumentation::AwsSdk::MessagingHelper

MessagingHelper class provides methods for calculating messaging span attributes

Public Class Methods

apply_sns_attributes(attributes, context, client_method) click to toggle source
# File lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb, line 44
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] = destination_name(context)
end
apply_sqs_attributes(attributes, context, client_method) click to toggle source
# File lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb, line 35
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] = destination_name(context)
  attributes[SemanticConventions::Trace::MESSAGING_URL] = context.params[:queue_url]

  attributes[SemanticConventions::Trace::MESSAGING_OPERATION] = 'receive' if client_method == 'SQS.ReceiveMessage'
end
create_sqs_processing_spans(context, tracer, messages) click to toggle source
# File lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb, line 53
def create_sqs_processing_spans(context, tracer, messages)
  queue_name = destination_name(context)
  messages.each do |message|
    attributes = {
      SemanticConventions::Trace::MESSAGING_SYSTEM => 'aws.sqs',
      SemanticConventions::Trace::MESSAGING_DESTINATION => queue_name,
      SemanticConventions::Trace::MESSAGING_DESTINATION_KIND => 'queue',
      SemanticConventions::Trace::MESSAGING_MESSAGE_ID => message.message_id,
      SemanticConventions::Trace::MESSAGING_URL => context.params[:queue_url],
      SemanticConventions::Trace::MESSAGING_OPERATION => 'process'
    }
    tracer.in_span("#{queue_name} process", attributes: attributes, links: extract_links(message), kind: :consumer) {}
  end
end
destination_name(context) click to toggle source
# File lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb, line 13
def destination_name(context) # rubocop:disable Metrics/CyclomaticComplexity
  topic_arn = context.params[:topic_arn]
  target_arn = context.params[:target_arn]
  phone_number = context.params[:phone_number]
  queue_url = context.params[:queue_url]

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

  return 'phone_number' if phone_number

  return queue_url.split('/')[-1] if queue_url

  'unknown'
end