Class: NewRelic::Agent::TransactionSampleBuilder
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.
Instance Attribute Summary collapse
Instance Method Summary
collapse
#normalize_params, #strip_nr_from_backtrace
Constructor Details
Returns a new instance of TransactionSampleBuilder.
225
226
227
228
229
|
# File 'lib/new_relic/agent/transaction_sampler.rb', line 225
def initialize(time=Time.now.to_f)
@sample = NewRelic::TransactionSample.new(time)
@sample_start = time
@current_segment = @sample.root_segment
end
|
Instance Attribute Details
#current_segment ⇒ Object
Returns the value of attribute current_segment.
221
222
223
|
# File 'lib/new_relic/agent/transaction_sampler.rb', line 221
def current_segment
@current_segment
end
|
Instance Method Details
#finish_trace(time) ⇒ Object
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
|
# File 'lib/new_relic/agent/transaction_sampler.rb', line 249
def finish_trace(time)
if @sample.frozen?
log = NewRelic::Control.instance.log
log.warn "Unexpected double-freeze of Transaction Trace Object."
log.info "Please send this diagnostic data to New Relic"
log.info @sample.to_s
return
end
@sample.root_segment.end_trace(time - @sample_start)
@sample.params[:custom_params] = normalize_params(NewRelic::Agent.instance.custom_params)
@sample.freeze
@current_segment = nil
end
|
278
279
280
|
# File 'lib/new_relic/agent/transaction_sampler.rb', line 278
def freeze
@sample.freeze unless sample.frozen?
end
|
304
305
306
307
|
# File 'lib/new_relic/agent/transaction_sampler.rb', line 304
def sample
fail "Not finished building" unless @sample.frozen?
@sample
end
|
#sample_id ⇒ Object
231
232
233
|
# File 'lib/new_relic/agent/transaction_sampler.rb', line 231
def sample_id
@sample.sample_id
end
|
#scope_depth ⇒ Object
266
267
268
269
270
271
272
273
274
275
276
|
# File 'lib/new_relic/agent/transaction_sampler.rb', line 266
def scope_depth
depth = -1 current = @current_segment
while(current)
depth += 1
current = current.parent_segment
end
depth
end
|
#set_profile(profile) ⇒ Object
282
283
284
|
# File 'lib/new_relic/agent/transaction_sampler.rb', line 282
def set_profile(profile)
@sample.profile = profile
end
|
#set_transaction_cpu_time(cpu_time) ⇒ Object
299
300
301
|
# File 'lib/new_relic/agent/transaction_sampler.rb', line 299
def set_transaction_cpu_time(cpu_time)
@sample.params[:cpu_time] = cpu_time
end
|
#set_transaction_info(path, request, params) ⇒ Object
286
287
288
289
290
291
292
293
294
295
296
297
|
# File 'lib/new_relic/agent/transaction_sampler.rb', line 286
def set_transaction_info(path, request, 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] = request.path if request
end
|
#trace_entry(metric_name, time) ⇒ Object
235
236
237
238
239
|
# File 'lib/new_relic/agent/transaction_sampler.rb', line 235
def trace_entry(metric_name, time)
segment = @sample.create_segment(time - @sample_start, metric_name)
@current_segment.add_called_segment(segment)
@current_segment = segment
end
|
#trace_exit(metric_name, time) ⇒ Object
241
242
243
244
245
246
247
|
# File 'lib/new_relic/agent/transaction_sampler.rb', line 241
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 - @sample_start)
@current_segment = @current_segment.parent_segment
end
|