class NewRelic::Agent::Transaction::Segment

Attributes

custom_transaction_attributes[R]

unscoped_metrics can be nil, a string, or array. we do this to save object allocations. if allocations weren’t important then we would initialize it as an array that would be empty, have one item, or many items.

unscoped_metrics[R]

unscoped_metrics can be nil, a string, or array. we do this to save object allocations. if allocations weren’t important then we would initialize it as an array that would be empty, have one item, or many items.

Public Class Methods

finish(segment) click to toggle source
# File lib/new_relic/agent/transaction/segment.rb, line 49
def self.finish(segment)
  return unless segment

  segment.finish
end
merge_untrusted_agent_attributes(attributes, prefix, default_destinations) click to toggle source
# File lib/new_relic/agent/transaction/segment.rb, line 31
def self.merge_untrusted_agent_attributes(attributes, prefix, default_destinations)
  if segment = NewRelic::Agent::Tracer.current_segment
    segment.merge_untrusted_agent_attributes(attributes, prefix, default_destinations)
  else
    NewRelic::Agent.logger.debug('Attempted to merge untrusted attributes without segment')
  end
end
new(name = nil, unscoped_metrics = nil, start_time = nil) click to toggle source
# File lib/new_relic/agent/transaction/segment.rb, line 18
def initialize(name = nil, unscoped_metrics = nil, start_time = nil)
  @unscoped_metrics = unscoped_metrics
  super(name, start_time)
end

Public Instance Methods

add_agent_attribute(key, value, default_destinations = AttributeFilter::DST_SPAN_EVENTS) click to toggle source
# File lib/new_relic/agent/transaction/segment.rb, line 27
def add_agent_attribute(key, value, default_destinations = AttributeFilter::DST_SPAN_EVENTS)
  attributes.add_agent_attribute(key, value, default_destinations)
end
add_custom_attributes(p) click to toggle source
# File lib/new_relic/agent/transaction/segment.rb, line 45
def add_custom_attributes(p)
  attributes.merge_custom_attributes(p)
end
attributes() click to toggle source
# File lib/new_relic/agent/transaction/segment.rb, line 23
def attributes
  @attributes ||= Attributes.new(NewRelic::Agent.instance.attribute_filter)
end
merge_untrusted_agent_attributes(agent_attributes, prefix, default_destinations) click to toggle source
# File lib/new_relic/agent/transaction/segment.rb, line 39
def merge_untrusted_agent_attributes(agent_attributes, prefix, default_destinations)
  return if agent_attributes.nil?

  attributes.merge_untrusted_agent_attributes(agent_attributes, prefix, default_destinations)
end

Private Instance Methods

append_unscoped_metric(metric) click to toggle source
# File lib/new_relic/agent/transaction/segment.rb, line 68
def append_unscoped_metric(metric)
  if @unscoped_metrics
    if Array === @unscoped_metrics
      if unscoped_metrics.frozen?
        @unscoped_metrics += [name]
      else
        @unscoped_metrics << name
      end
    else
      @unscoped_metrics = [@unscoped_metrics, metric]
    end
  else
    @unscoped_metrics = metric
  end
end
record_metrics() click to toggle source
# File lib/new_relic/agent/transaction/segment.rb, line 57
def record_metrics
  if record_scoped_metric?
    metric_cache.record_scoped_and_unscoped(name, duration, exclusive_duration)
  else
    append_unscoped_metric(name)
  end
  if unscoped_metrics
    metric_cache.record_unscoped(unscoped_metrics, duration, exclusive_duration)
  end
end
record_span_event() click to toggle source
# File lib/new_relic/agent/transaction/segment.rb, line 88
def record_span_event
  # don't record a span event if the transaction is ignored
  return if transaction.ignore?

  aggregator = ::NewRelic::Agent.agent.span_event_aggregator
  priority = transaction.priority

  aggregator.record(priority: priority) do
    SpanEventPrimitive.for_segment(self)
  end
end
segment_complete() click to toggle source
# File lib/new_relic/agent/transaction/segment.rb, line 84
def segment_complete
  record_span_event if transaction.sampled?
end