Class: NewRelic::Agent::TransactionSampleBuilder
- Inherits:
-
Object
- Object
- NewRelic::Agent::TransactionSampleBuilder
show all
- Includes:
- CollectionHelper
- Defined in:
- lib/new_relic/agent/transaction_sampler.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.
244
245
246
247
248
|
# File 'lib/new_relic/agent/transaction_sampler.rb', line 244
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.
240
241
242
|
# File 'lib/new_relic/agent/transaction_sampler.rb', line 240
def current_segment
@current_segment
end
|
#sample ⇒ Object
Returns the value of attribute sample.
240
241
242
|
# File 'lib/new_relic/agent/transaction_sampler.rb', line 240
def sample
@sample
end
|
Instance Method Details
#finish_trace(time) ⇒ Object
273
274
275
276
277
278
279
280
281
282
283
284
285
|
# File 'lib/new_relic/agent/transaction_sampler.rb', line 273
def finish_trace(time)
if @sample.frozen?
log = NewRelic::Control.instance.log
log.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] = normalize_params(NewRelic::Agent::Instrumentation::MetricFrame.custom_parameters)
@sample.freeze
@current_segment = nil
end
|
#freeze ⇒ Object
299
300
301
|
# File 'lib/new_relic/agent/transaction_sampler.rb', line 299
def freeze
@sample.freeze unless sample.frozen?
end
|
#ignore_transaction ⇒ Object
256
257
258
|
# File 'lib/new_relic/agent/transaction_sampler.rb', line 256
def ignore_transaction
@ignore = true
end
|
#ignored? ⇒ Boolean
253
254
255
|
# File 'lib/new_relic/agent/transaction_sampler.rb', line 253
def ignored?
@ignore || @sample.params[:path].nil?
end
|
#sample_id ⇒ Object
250
251
252
|
# File 'lib/new_relic/agent/transaction_sampler.rb', line 250
def sample_id
@sample.sample_id
end
|
#scope_depth ⇒ Object
287
288
289
290
291
292
293
294
295
296
297
|
# File 'lib/new_relic/agent/transaction_sampler.rb', line 287
def scope_depth
depth = -1 current = @current_segment
while(current)
depth += 1
current = current.parent_segment
end
depth
end
|
#set_profile(profile) ⇒ Object
303
304
305
|
# File 'lib/new_relic/agent/transaction_sampler.rb', line 303
def set_profile(profile)
@sample.profile = profile
end
|
#set_transaction_cpu_time(cpu_time) ⇒ Object
320
321
322
|
# File 'lib/new_relic/agent/transaction_sampler.rb', line 320
def set_transaction_cpu_time(cpu_time)
@sample.params[:cpu_time] = cpu_time
end
|
#set_transaction_info(path, uri, params) ⇒ Object
307
308
309
310
311
312
313
314
315
316
317
318
|
# File 'lib/new_relic/agent/transaction_sampler.rb', line 307
def set_transaction_info(path, uri, params)
@sample.params[:path] = path
if NewRelic::Control.instance.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
259
260
261
262
263
|
# File 'lib/new_relic/agent/transaction_sampler.rb', line 259
def trace_entry(metric_name, time)
segment = @sample.create_segment(time.to_f - @sample_start, metric_name)
@current_segment.add_called_segment(segment)
@current_segment = segment
end
|
#trace_exit(metric_name, time) ⇒ Object
265
266
267
268
269
270
271
|
# File 'lib/new_relic/agent/transaction_sampler.rb', line 265
def trace_exit(metric_name, time)
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
|