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

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

Overview

API:

  • public

Constant Summary collapse

CONSUME =

API:

  • public

'Consume'.freeze
EXCHANGE =

API:

  • public

'Exchange'.freeze
NAMED =

API:

  • public

'Named/'.freeze
PRODUCE =

API:

  • public

'Produce'.freeze
QUEUE =

API:

  • public

'Queue'.freeze
PURGE =

API:

  • public

'Purge'.freeze
STREAM =

API:

  • public

'Stream'.freeze
TEMP =

API:

  • public

'Temp'.freeze
TOPIC =

API:

  • public

'Topic'.freeze
UNKNOWN =

API:

  • public

NewRelic::UNKNOWN
DESTINATION_TYPES =

API:

  • public

[
  :exchange,
  :queue,
  :stream,
  :topic,
  :temporary_queue,
  :temporary_topic,
  :unknown
]
ACTIONS =

API:

  • public

{
  consume: CONSUME,
  produce: PRODUCE,
  purge: PURGE
}
TYPES =

API:

  • public

{
  exchange: EXCHANGE,
  temporary_queue: QUEUE,
  stream: STREAM,
  queue: QUEUE,
  temporary_topic: TOPIC,
  topic: TOPIC,
  unknown: EXCHANGE
}
METRIC_PREFIX =

API:

  • public

'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, #llm_event, #noticed_error, #parent, #record_on_finish, #record_scoped_metric, #start_time, #starting_segment_key, #thread_id, #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, set_segment_callback, #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.

API:

  • public



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

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)

API:

  • public



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

def action
  @action
end

#destination_nameObject (readonly)

API:

  • public



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

def destination_name
  @destination_name
end

#destination_typeObject (readonly)

API:

  • public



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

def destination_type
  @destination_type
end

#headersObject (readonly)

API:

  • public



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

def headers
  @headers
end

#libraryObject (readonly)

API:

  • public



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

def library
  @library
end

Instance Method Details

#nameObject

API:

  • public



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

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

API:

  • public



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

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