Class: Instana::Exporter::Otlp::MessagingConverter

Inherits:
BaseConverter
  • Object
show all
Defined in:
lib/instana/exporter/otlp/messaging_converter.rb

Overview

Converter for messaging spans to OTLP format

Instance Method Summary collapse

Methods inherited from BaseConverter

#convert, #initialize

Constructor Details

This class inherits a constructor from Instana::Exporter::Otlp::BaseConverter

Instance Method Details

#convert_attributesObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/instana/exporter/otlp/messaging_converter.rb', line 35

def convert_attributes
  attributes = {}

  rabbitmq_data = span[:data]&.[](:rabbitmq)
  if rabbitmq_data
    add_attribute(attributes, OpenTelemetry::SemConv::Incubating::MESSAGING::MESSAGING_SYSTEM, 'rabbitmq')
    add_attribute(attributes, OpenTelemetry::SemConv::Incubating::MESSAGING::MESSAGING_DESTINATION_NAME,
                  rabbitmq_destination_name(rabbitmq_data))
    add_attribute(attributes, OpenTelemetry::SemConv::Incubating::MESSAGING::MESSAGING_RABBITMQ_DESTINATION_ROUTING_KEY, rabbitmq_data[:key])
    add_attribute(attributes, 'messaging.rabbitmq.queue', rabbitmq_data[:queue])
    add_attribute(attributes, OpenTelemetry::SemConv::SERVER::SERVER_ADDRESS, rabbitmq_data[:address])

    operation = rabbitmq_data[:sort] == 'publish' ? 'send' : 'receive'
    add_attribute(attributes, OpenTelemetry::SemConv::Incubating::MESSAGING::MESSAGING_OPERATION_TYPE, operation)
  end

  attributes
end

#span_nameString

Build OTel-compliant span name for messaging (RabbitMQ) spans

Formula per SPAN_NAME_PATTERNS.txt Section 3 (bunny/AMQP):

publish → "{exchange} publish"   (or "{queue} publish" when no exchange)
receive → "{queue} receive"

Returns:

  • (String)

    The span name



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/instana/exporter/otlp/messaging_converter.rb', line 21

def span_name
  rabbitmq_data = span[:data]&.[](:rabbitmq) || {}
  sort = rabbitmq_data[:sort].to_s

  if sort == 'publish'
    dest = rabbitmq_data[:exchange].to_s.strip
    dest = rabbitmq_data[:queue].to_s.strip if dest.empty?
    dest.empty? ? 'publish' : "#{dest} publish"
  else
    queue = rabbitmq_data[:queue].to_s.strip
    queue.empty? ? 'receive' : "#{queue} receive"
  end
end