Class: NewRelic::Agent::TransactionSampleBuilder Private

Inherits:
Object
  • Object
show all
Includes:
CollectionHelper
Defined in:
lib/new_relic/agent/transaction_sample_builder.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

a builder is created with every sampled transaction, to dynamically generate the sampled data. It is a thread-local object, and is not accessed by any other thread so no need for synchronization.

Defined Under Namespace

Classes: PlaceholderSegment

Constant Summary

Constants included from CollectionHelper

CollectionHelper::DEFAULT_ARRAY_TRUNCATION_SIZE, CollectionHelper::DEFAULT_TRUNCATION_SIZE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from CollectionHelper

#normalize_params, #strip_nr_from_backtrace

Constructor Details

#initialize(time = Time.now) ⇒ TransactionSampleBuilder

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of TransactionSampleBuilder.



49
50
51
52
53
# File 'lib/new_relic/agent/transaction_sample_builder.rb', line 49

def initialize(time=Time.now)
  @sample = NewRelic::TransactionSample.new(time.to_f)
  @sample_start = time.to_f
  @current_segment = @sample.root_segment
end

Instance Attribute Details

#current_segmentObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



45
46
47
# File 'lib/new_relic/agent/transaction_sample_builder.rb', line 45

def current_segment
  @current_segment
end

#sampleObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



45
46
47
# File 'lib/new_relic/agent/transaction_sample_builder.rb', line 45

def sample
  @sample
end

Instance Method Details

#finish_trace(time = Time.now.to_f, custom_params = {}) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/new_relic/agent/transaction_sample_builder.rb', line 102

def finish_trace(time=Time.now.to_f, custom_params={})
  # This should never get called twice, but in a rare case that we can't reproduce in house it does.
  # log forensics and return gracefully
  if @sample.frozen?
    ::NewRelic::Agent.logger.error "Unexpected double-freeze of Transaction Trace Object: \n#{@sample.to_s}"
    return
  end
  @sample.root_segment.end_trace(time.to_f - @sample_start)
  @sample.params[:custom_params] ||= {}
  @sample.params[:custom_params].merge!(normalize_params(custom_params))

  txn_info = NewRelic::Agent::TransactionInfo.get
  @sample.force_persist = txn_info.force_persist_sample?(sample)
  @sample.threshold = txn_info.transaction_trace_threshold
  @sample.freeze
  @current_segment = nil
end

#freezeObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



132
133
134
# File 'lib/new_relic/agent/transaction_sample_builder.rb', line 132

def freeze
  @sample.freeze unless sample.frozen?
end

#ignore_transactionObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



63
64
65
# File 'lib/new_relic/agent/transaction_sample_builder.rb', line 63

def ignore_transaction
  @ignore = true
end

#ignored?Boolean

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Boolean)


59
60
61
# File 'lib/new_relic/agent/transaction_sample_builder.rb', line 59

def ignored?
  @ignore
end

#sample_idObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



55
56
57
# File 'lib/new_relic/agent/transaction_sample_builder.rb', line 55

def sample_id
  @sample.sample_id
end

#scope_depthObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



120
121
122
123
124
125
126
127
128
129
130
# File 'lib/new_relic/agent/transaction_sample_builder.rb', line 120

def scope_depth
  depth = -1        # have to account for the root
  current = @current_segment

  while(current)
    depth += 1
    current = current.parent_segment
  end

  depth
end

#segment_limitObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



67
68
69
# File 'lib/new_relic/agent/transaction_sample_builder.rb', line 67

def segment_limit
  Agent.config[:'transaction_tracer.limit_segments']
end

#set_profile(profile) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



136
137
138
# File 'lib/new_relic/agent/transaction_sample_builder.rb', line 136

def set_profile(profile)
  @sample.profile = profile
end

#set_transaction_cpu_time(cpu_time) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



155
156
157
# File 'lib/new_relic/agent/transaction_sample_builder.rb', line 155

def set_transaction_cpu_time(cpu_time)
  @sample.set_custom_param(:cpu_time, cpu_time)
end

#set_transaction_info(uri, params) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



140
141
142
143
144
145
146
147
148
149
# File 'lib/new_relic/agent/transaction_sample_builder.rb', line 140

def set_transaction_info(uri, params)
  if Agent.config[:capture_params]
    params = normalize_params params

    @sample.params[:request_params].merge!(params)
    @sample.params[:request_params].delete :controller
    @sample.params[:request_params].delete :action
  end
  @sample.params[:uri] ||= uri || params[:uri]
end

#set_transaction_name(name) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



151
152
153
# File 'lib/new_relic/agent/transaction_sample_builder.rb', line 151

def set_transaction_name(name)
  @sample.params[:path] = name
end

#trace_entry(time) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



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

def trace_entry(time)
  if @sample.count_segments < segment_limit
    segment = @sample.create_segment(time.to_f - @sample_start)
    @current_segment.add_called_segment(segment)
    @current_segment = segment
    if @sample.count_segments == segment_limit()
      ::NewRelic::Agent.logger.debug("Segment limit of #{segment_limit} reached, ceasing collection.")
    end
  else
    if @current_segment.is_a?(PlaceholderSegment)
      @current_segment.depth += 1
    else
      @current_segment = PlaceholderSegment.new(@current_segment)
    end
  end
  @current_segment
end

#trace_exit(metric_name, time) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



89
90
91
92
93
94
95
96
97
98
99
100
# File 'lib/new_relic/agent/transaction_sample_builder.rb', line 89

def trace_exit(metric_name, time)
  if @current_segment.is_a?(PlaceholderSegment)
    @current_segment.depth -= 1
    if @current_segment.depth == 0
      @current_segment = @current_segment.parent_segment
    end
  else
    @current_segment.metric_name = metric_name
    @current_segment.end_trace(time.to_f - @sample_start)
    @current_segment = @current_segment.parent_segment
  end
end