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
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.



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

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)



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

def action
  @action
end

#destination_nameObject (readonly)



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

def destination_name
  @destination_name
end

#destination_typeObject (readonly)



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

def destination_type
  @destination_type
end

#headersObject (readonly)



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

def headers
  @headers
end

#libraryObject (readonly)



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

def library
  @library
end

Instance Method Details

#nameObject



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

def name
  return @name if @name

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

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

  @name
end

#transaction_assignedObject



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

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