Module: OneApm::Transaction::ThreadLocalAccess

Included in:
OneApm::Transaction
Defined in:
lib/one_apm/transaction/thread_local_access.rb

Instance Method Summary collapse

Instance Method Details

#abort_transaction!Object

Indicate that you don’t want to keep the currently saved transaction information



30
31
32
33
34
# File 'lib/one_apm/transaction/thread_local_access.rb', line 30

def abort_transaction!
  state = OneApm::TransactionState.tl_get
  txn = state.current_transaction
  txn.abort_transaction!(state) if txn
end

#extract_request_options(options) ⇒ Object



57
58
59
60
61
62
63
64
# File 'lib/one_apm/transaction/thread_local_access.rb', line 57

def extract_request_options(options)
  req = options.delete(:request)
  if req
    options[:uri]     = uri_from_request(req)
    options[:referer] = referer_from_request(req)
  end
  options
end

#notice_error(e, options = {}) ⇒ Object

If we have an active transaction, notice the error and increment the error metric. Options:

  • :request => Request object to get the uri and referer

  • :uri => The request path, minus any request params or query string.

  • :referer => The URI of the referer

  • :metric => The metric name associated with the transaction

  • :request_params => Request parameters, already filtered if necessary

  • :custom_params => Custom parameters

Anything left over is treated as custom params



46
47
48
49
50
51
52
53
54
55
# File 'lib/one_apm/transaction/thread_local_access.rb', line 46

def notice_error(e, options={})
  options = extract_request_options(options)
  state = OneApm::TransactionState.tl_get
  txn = state.current_transaction
  if txn
    txn.notice_error(e, options)
  else
    OneApm::Manager.agent.error_collector.notice_error(e, options)
  end
end

#recording_web_transaction?Boolean

Returns:

  • (Boolean)


66
67
68
69
# File 'lib/one_apm/transaction/thread_local_access.rb', line 66

def recording_web_transaction?
  txn = tl_current
  txn && txn.recording_web_transaction?
end

#set_default_transaction_name(name, category = nil, segment_name = nil) ⇒ Object



11
12
13
14
15
16
# File 'lib/one_apm/transaction/thread_local_access.rb', line 11

def set_default_transaction_name(name, category = nil, segment_name = nil)
  txn  = tl_current
  name = txn.make_transaction_name(name, category)
  txn.name_last_frame(segment_name || name)
  txn.set_default_transaction_name(name, category)
end

#set_overriding_transaction_name(name, category = nil) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/one_apm/transaction/thread_local_access.rb', line 18

def set_overriding_transaction_name(name, category = nil)
  txn = tl_current
  return unless txn

  name = txn.make_transaction_name(name, category)

  txn.name_last_frame(name)
  txn.set_overriding_transaction_name(name, category)
end

#tl_currentObject



7
8
9
# File 'lib/one_apm/transaction/thread_local_access.rb', line 7

def tl_current
  TransactionState.tl_get.current_transaction
end