# encoding: utf-8
module OneApm
class Transaction
module ThreadLocalAccess
def tl_current
TransactionState.tl_get.current_transaction
end
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
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
# Indicate that you don't want to keep the currently saved transaction
# information
def abort_transaction! #THREAD_LOCAL_ACCESS
state = OneApm::TransactionState.tl_get
txn = state.current_transaction
txn.abort_transaction!(state) if txn
end
# 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
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::Agent.instance.error_collector.notice_error(e, options)
end
end
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
def recording_web_transaction?
txn = tl_current
txn && txn.recording_web_transaction?
end
end
end
end