Class: NewRelic::Agent::TransactionSampleBuilder
- Inherits:
-
Object
- Object
- NewRelic::Agent::TransactionSampleBuilder
show all
- Includes:
- CollectionHelper
- Defined in:
- lib/new_relic/agent/transaction_sample_builder.rb
Overview
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.
Constant Summary
CollectionHelper::DEFAULT_ARRAY_TRUNCATION_SIZE, CollectionHelper::DEFAULT_TRUNCATION_SIZE
Instance Attribute Summary collapse
Instance Method Summary
collapse
#normalize_params, #strip_nr_from_backtrace
Constructor Details
Returns a new instance of TransactionSampleBuilder.
15
16
17
18
19
|
# File 'lib/new_relic/agent/transaction_sample_builder.rb', line 15
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_segment ⇒ Object
Returns the value of attribute current_segment.
11
12
13
|
# File 'lib/new_relic/agent/transaction_sample_builder.rb', line 11
def current_segment
@current_segment
end
|
#sample ⇒ Object
Returns the value of attribute sample.
11
12
13
|
# File 'lib/new_relic/agent/transaction_sample_builder.rb', line 11
def sample
@sample
end
|
Instance Method Details
#finish_trace(time = Time.now.to_f) ⇒ Object
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
# File 'lib/new_relic/agent/transaction_sample_builder.rb', line 58
def finish_trace(time=Time.now.to_f)
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(NewRelic::Agent::Instrumentation::MetricFrame.custom_parameters))
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
|
#freeze ⇒ Object
88
89
90
|
# File 'lib/new_relic/agent/transaction_sample_builder.rb', line 88
def freeze
@sample.freeze unless sample.frozen?
end
|
#ignore_transaction ⇒ Object
29
30
31
|
# File 'lib/new_relic/agent/transaction_sample_builder.rb', line 29
def ignore_transaction
@ignore = true
end
|
#ignored? ⇒ Boolean
25
26
27
|
# File 'lib/new_relic/agent/transaction_sample_builder.rb', line 25
def ignored?
@ignore || @sample.params[:path].nil?
end
|
#rename_current_segment(new_name) ⇒ Object
Set the metric name of the current segment to new_name
if
115
116
117
118
|
# File 'lib/new_relic/agent/transaction_sample_builder.rb', line 115
def rename_current_segment( new_name )
return unless @sample.count_segments < segment_limit()
@current_segment.metric_name = new_name
end
|
#sample_id ⇒ Object
21
22
23
|
# File 'lib/new_relic/agent/transaction_sample_builder.rb', line 21
def sample_id
@sample.sample_id
end
|
#scope_depth ⇒ Object
76
77
78
79
80
81
82
83
84
85
86
|
# File 'lib/new_relic/agent/transaction_sample_builder.rb', line 76
def scope_depth
depth = -1 current = @current_segment
while(current)
depth += 1
current = current.parent_segment
end
depth
end
|
#segment_limit ⇒ Object
33
34
35
|
# File 'lib/new_relic/agent/transaction_sample_builder.rb', line 33
def segment_limit
Agent.config[:'transaction_tracer.limit_segments']
end
|
#set_profile(profile) ⇒ Object
92
93
94
|
# File 'lib/new_relic/agent/transaction_sample_builder.rb', line 92
def set_profile(profile)
@sample.profile = profile
end
|
#set_transaction_cpu_time(cpu_time) ⇒ Object
109
110
111
112
|
# File 'lib/new_relic/agent/transaction_sample_builder.rb', line 109
def set_transaction_cpu_time(cpu_time)
@sample.params[:custom_params] ||= {}
@sample.params[:custom_params][:cpu_time] = cpu_time
end
|
#set_transaction_info(path, uri, params) ⇒ Object
96
97
98
99
100
101
102
103
104
105
106
107
|
# File 'lib/new_relic/agent/transaction_sample_builder.rb', line 96
def set_transaction_info(path, uri, params)
@sample.params[:path] = path
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
|
#trace_entry(metric_name, time) ⇒ Object
37
38
39
40
41
42
43
44
45
46
47
|
# File 'lib/new_relic/agent/transaction_sample_builder.rb', line 37
def trace_entry(metric_name, time)
if @sample.count_segments < segment_limit()
segment = @sample.create_segment(time.to_f - @sample_start, metric_name)
@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
@current_segment
end
end
|
#trace_exit(metric_name, time) ⇒ Object
49
50
51
52
53
54
55
56
|
# File 'lib/new_relic/agent/transaction_sample_builder.rb', line 49
def trace_exit(metric_name, time)
return unless @sample.count_segments < segment_limit()
if metric_name != @current_segment.metric_name
fail "unbalanced entry/exit: #{metric_name} != #{@current_segment.metric_name}"
end
@current_segment.end_trace(time.to_f - @sample_start)
@current_segment = @current_segment.parent_segment
end
|