# encoding: utf-8 module OneApm class Transaction module TransactionName def overridden_name=(name) @overridden_name = Helper.correctly_encoded(name) end def default_name=(name) @default_name = Helper.correctly_encoded(name) end def make_transaction_name(name, category = nil) "#{OneApm::TransactionNamer.prefix_for_category(self, category)}#{name}" end def set_default_transaction_name(name, category) return log_frozen_name(name) if name_frozen? if influences_transaction_name?(category) self.default_name = name @category = category if category end end def set_overriding_transaction_name(name, category) return log_frozen_name(name) if name_frozen? if influences_transaction_name?(category) self.overridden_name = name @category = category if category end end def name_last_frame(name) frame_stack.last.name = name end def log_frozen_name(name) OneApm::Manager.logger.warn("Attempted to rename transaction to '#{name}' after transaction name was already frozen as '#{@frozen_name}'.") nil end def influences_transaction_name?(category) !category || frame_stack.size == 1 || similar_category?(category) end def best_name @frozen_name || @overridden_name || @default_name || Transaction::UNKNOWN_METRIC end def name_set? (@overridden_name || @default_name) ? true : false end def promoted_transaction_name(name) if name.start_with?(Transaction::MIDDLEWARE_PREFIX) "#{Transaction::CONTROLLER_PREFIX}#{name}" else name end end def freeze_name_and_execute_if_not_ignored if !name_frozen? name = promoted_transaction_name(best_name) name = OneApm::Manager.agent.transaction_rules.rename(name) @name_frozen = true if name.nil? ignore! @frozen_name = best_name else @frozen_name = name end end if block_given? && !@ignore_this_transaction yield end end def name_frozen? @frozen_name ? true : false end end end end