Sha256: 7245c2c5670a352e427cf227a9d6b80a180b9c1a3da64e558b26f67241f70f8a

Contents?: true

Size: 1.97 KB

Versions: 13

Compression:

Stored size: 1.97 KB

Contents

# encoding: utf-8
# This file is distributed under New Relic's license terms.
# See https://github.com/newrelic/rpm/blob/master/LICENSE for complete details.

require 'new_relic/helper'
require 'new_relic/agent/transaction/trace'
require 'new_relic/agent/transaction/trace_node'

module NewRelic
  module Agent
    class Transaction
      module TraceBuilder
        extend self

        def build_trace transaction
          trace = Trace.new transaction.start_time
          trace.root_node.exit_timestamp = transaction.end_time - transaction.start_time
          copy_attributes transaction, trace
          first, *rest = transaction.segments
          relationship_map = rest.group_by { |s| s.parent }
          trace.root_node.children << process_segments(transaction, first, trace.root_node, relationship_map)
          trace
        end

        private

        # recursively builds a transaction trace from the flat list of segments
        def process_segments transaction, segment, parent, relationship_map
          current = create_trace_node transaction, segment, parent

          if children = relationship_map[segment]
            current.children = children.map! do |child|
              process_segments transaction, child, current, relationship_map
            end
          end

          current
        end

        def create_trace_node transaction, segment, parent
          relative_start = segment.start_time - transaction.start_time
          relative_end = segment.end_time - transaction.start_time
          TraceNode.new segment.name, relative_start, relative_end, segment.params, parent
        end

        def copy_attributes transaction, trace
          trace.transaction_name = transaction.best_name
          trace.guid = transaction.guid
          trace.attributes = transaction.attributes
          trace.threshold = transaction.threshold
          trace.xray_session_id = transaction.xray_session_id
          trace.finished = true
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
newrelic_rpm-6.3.0.355 lib/new_relic/agent/transaction/trace_builder.rb
newrelic_rpm-6.2.0.354 lib/new_relic/agent/transaction/trace_builder.rb
newrelic_rpm-6.1.0.352 lib/new_relic/agent/transaction/trace_builder.rb
newrelic_rpm-6.0.0.351 lib/new_relic/agent/transaction/trace_builder.rb
newrelic_rpm-5.7.0.350 lib/new_relic/agent/transaction/trace_builder.rb
newrelic_rpm-5.6.0.349 lib/new_relic/agent/transaction/trace_builder.rb
newrelic_rpm-5.5.0.348 lib/new_relic/agent/transaction/trace_builder.rb
newrelic_rpm-5.4.0.347 lib/new_relic/agent/transaction/trace_builder.rb
newrelic_rpm-5.3.0.346 lib/new_relic/agent/transaction/trace_builder.rb
newrelic_rpm-5.2.0.345 lib/new_relic/agent/transaction/trace_builder.rb
newrelic_rpm-5.1.0.344 lib/new_relic/agent/transaction/trace_builder.rb
newrelic_rpm-5.0.0.342 lib/new_relic/agent/transaction/trace_builder.rb
newrelic_rpm-4.8.0.341 lib/new_relic/agent/transaction/trace_builder.rb