Class: OpenTelemetry::Instrumentation::AwsSdk::MessagingHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb

Overview

MessagingHelper class provides methods for calculating messaging span attributes

Class Method Summary collapse

Class Method Details

.apply_sns_attributes(attributes, context, client_method) ⇒ Object



40
41
42
43
44
45
46
47
# File 'lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb', line 40

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

.apply_sqs_attributes(attributes, context, client_method) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb', line 31

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]

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

.queue_name(context) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/opentelemetry/instrumentation/aws_sdk/messaging_helper.rb', line 13

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