Class: NewRelic::Agent::Transaction::MessageBrokerSegment

Inherits:
Segment show all
Defined in:
lib/new_relic/agent/transaction/message_broker_segment.rb

Constant Summary collapse

CONSUME =
'Consume'.freeze
EXCHANGE =
'Exchange'.freeze
NAMED =
'Named/'.freeze
PRODUCE =
'Produce'.freeze
QUEUE =
'Queue'.freeze
PURGE =
'Purge'.freeze
SLASH =
'/'.freeze
TEMP =
'Temp'.freeze
TOPIC =
'Topic'.freeze
UNKNOWN =
'Unknown'.freeze
DESTINATION_TYPES =
[
  :exchange,
  :queue,
  :topic,
  :temporary_queue,
  :temporary_topic,
  :unknown
]
ACTIONS =
{
  consume: CONSUME,
  produce: PRODUCE,
  purge: PURGE
}
TYPES =
{
  exchange: EXCHANGE,
  temporary_queue: QUEUE,
  queue: QUEUE,
  temporary_topic: TOPIC,
  topic: TOPIC,
  unknown: EXCHANGE
}
METRIC_PREFIX =
'MessageBroker/'.freeze

Constants inherited from AbstractSegment

AbstractSegment::CALLBACK, AbstractSegment::INSPECT_IGNORE, AbstractSegment::SEGMENT

Instance Attribute Summary collapse

Attributes inherited from Segment

#custom_transaction_attributes, #unscoped_metrics

Attributes inherited from AbstractSegment

#children_time, #duration, #end_time, #exclusive_duration, #guid, #noticed_error, #parent, #record_on_finish, #record_scoped_metric, #start_time, #starting_segment_key, #transaction, #transaction_name

Instance Method Summary collapse

Methods inherited from Segment

#add_agent_attribute, #add_custom_attributes, #attributes, finish, #merge_untrusted_agent_attributes, merge_untrusted_agent_attributes

Methods inherited from AbstractSegment

#all_code_information_present?, #children_time_ranges?, #code_attributes, #code_information=, #concurrent_children?, #finalize, #finish, #finished?, #inspect, #notice_error, #noticed_error_attributes, #params, #params?, #record_metrics?, #record_on_finish?, #record_scoped_metric?, #set_noticed_error, #start, #time_range

Constructor Details

#initialize(action:, library:, destination_type:, destination_name:, headers: nil, parameters: nil, start_time: nil) ⇒ MessageBrokerSegment

Returns a new instance of MessageBrokerSegment.



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/new_relic/agent/transaction/message_broker_segment.rb', line 55

def initialize(action:,
  library:,
  destination_type:,
  destination_name:,
  headers: nil,
  parameters: nil,
  start_time: nil)

  @action = action
  @library = library
  @destination_type = destination_type
  @destination_name = destination_name
  @headers = headers
  super(nil, nil, start_time)
  params.merge!(parameters) if parameters
end

Instance Attribute Details

#actionObject (readonly)



49
50
51
# File 'lib/new_relic/agent/transaction/message_broker_segment.rb', line 49

def action
  @action
end

#destination_nameObject (readonly)



49
50
51
# File 'lib/new_relic/agent/transaction/message_broker_segment.rb', line 49

def destination_name
  @destination_name
end

#destination_typeObject (readonly)



49
50
51
# File 'lib/new_relic/agent/transaction/message_broker_segment.rb', line 49

def destination_type
  @destination_type
end

#headersObject (readonly)



49
50
51
# File 'lib/new_relic/agent/transaction/message_broker_segment.rb', line 49

def headers
  @headers
end

#libraryObject (readonly)



49
50
51
# File 'lib/new_relic/agent/transaction/message_broker_segment.rb', line 49

def library
  @library
end

Instance Method Details

#nameObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/new_relic/agent/transaction/message_broker_segment.rb', line 72

def name
  return @name if @name

  @name = METRIC_PREFIX + library
  @name << SLASH << TYPES[destination_type] << SLASH << ACTIONS[action] << SLASH

  if destination_type == :temporary_queue || destination_type == :temporary_topic
    @name << TEMP
  else
    @name << NAMED << destination_name.to_s
  end

  @name
end

#transaction_assignedObject



87
88
89
90
91
92
93
94
95
# File 'lib/new_relic/agent/transaction/message_broker_segment.rb', line 87

def transaction_assigned
  if headers && transaction && action == :produce && record_metrics?
    transaction.distributed_tracer.insert_distributed_trace_header(headers)
    transaction.distributed_tracer.insert_cat_headers(headers)
    transaction.distributed_tracer.log_request_headers(headers)
  end
rescue => e
  NewRelic::Agent.logger.error('Error during message header processing', e)
end