diff --git a/lib/new_relic/agent/instrumentation/active_record_helper.rb b/lib/new_relic/agent/instrumentation/active_record_helper.rb index 4fb323004d..814668410c 100644 --- a/lib/new_relic/agent/instrumentation/active_record_helper.rb +++ b/lib/new_relic/agent/instrumentation/active_record_helper.rb @@ -232,7 +232,6 @@ module InstanceIdentification DEFAULT = 'default'.freeze UNKNOWN = 'unknown'.freeze - SLASH = '/'.freeze LOCALHOST = 'localhost'.freeze def adapter_from_config(config) @@ -288,7 +287,7 @@ def supported_adapter?(config) private def postgres_unix_domain_socket_case?(host, adapter) - adapter == :postgres && host && host.start_with?(SLASH) + adapter == :postgres && host && host.start_with?(NewRelic::SLASH) end def mysql_default_case?(config, adapter) diff --git a/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb b/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb index 57ced73286..db4bb7994e 100644 --- a/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb +++ b/lib/new_relic/agent/instrumentation/mongodb_command_subscriber.rb @@ -131,10 +131,8 @@ def port_path_or_id_from_address(address) UNKNOWN end - SLASH = '/'.freeze - def unix_domain_socket?(host) - host.start_with?(SLASH) + host.start_with?(NewRelic::SLASH) end end end diff --git a/lib/new_relic/agent/instrumentation/roda/roda_transaction_namer.rb b/lib/new_relic/agent/instrumentation/roda/roda_transaction_namer.rb index 82b284694e..5eef7f14dc 100644 --- a/lib/new_relic/agent/instrumentation/roda/roda_transaction_namer.rb +++ b/lib/new_relic/agent/instrumentation/roda/roda_transaction_namer.rb @@ -9,13 +9,12 @@ module Roda module TransactionNamer extend self - ROOT = '/'.freeze REGEX_MULTIPLE_SLASHES = %r{^[/^]*(.*?)[/$?]*$}.freeze def transaction_name(request) path = request.path || ::NewRelic::Agent::UNKNOWN_METRIC name = path.gsub(REGEX_MULTIPLE_SLASHES, '\1') # remove any rogue slashes - name = ROOT if name.empty? + name = NewRelic::ROOT if name.empty? name = "#{request.request_method} #{name}" if request.respond_to?(:request_method) name diff --git a/lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb b/lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb index b5f553c68d..54ce363ea8 100644 --- a/lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb +++ b/lib/new_relic/agent/instrumentation/sinatra/transaction_namer.rb @@ -25,14 +25,12 @@ def initial_transaction_name(request) transaction_name(::NewRelic::Agent::UNKNOWN_METRIC, request) end - ROOT = '/'.freeze - def transaction_name(route_text, request) verb = http_verb(request) route_text = route_text.source if route_text.is_a?(Regexp) name = route_text.gsub(%r{^[/^\\A]*(.*?)[/\$\?\\z]*$}, '\1') - name = ROOT if name.empty? + name = NewRelic::ROOT if name.empty? name = "#{verb} #{name}" unless verb.nil? name rescue => e diff --git a/lib/new_relic/agent/messaging.rb b/lib/new_relic/agent/messaging.rb index 9ead4adb9c..01bc9b38c3 100644 --- a/lib/new_relic/agent/messaging.rb +++ b/lib/new_relic/agent/messaging.rb @@ -329,9 +329,9 @@ def segment_parameters_enabled? def transaction_name(library, destination_type, destination_name) transaction_name = Transaction::MESSAGE_PREFIX + library - transaction_name << Transaction::MessageBrokerSegment::SLASH + transaction_name << NewRelic::SLASH transaction_name << Transaction::MessageBrokerSegment::TYPES[destination_type] - transaction_name << Transaction::MessageBrokerSegment::SLASH + transaction_name << NewRelic::SLASH case destination_type when :queue diff --git a/lib/new_relic/agent/rules_engine.rb b/lib/new_relic/agent/rules_engine.rb index 3bdf27e278..bb4c29ac14 100644 --- a/lib/new_relic/agent/rules_engine.rb +++ b/lib/new_relic/agent/rules_engine.rb @@ -9,7 +9,7 @@ module NewRelic module Agent class RulesEngine - SEGMENT_SEPARATOR = '/'.freeze + SEGMENT_SEPARATOR = NewRelic::SLASH LEADING_SLASH_REGEX = %r{^/}.freeze include Enumerable diff --git a/lib/new_relic/agent/transaction/message_broker_segment.rb b/lib/new_relic/agent/transaction/message_broker_segment.rb index 4d0d145ff1..c511fed283 100644 --- a/lib/new_relic/agent/transaction/message_broker_segment.rb +++ b/lib/new_relic/agent/transaction/message_broker_segment.rb @@ -15,7 +15,6 @@ class MessageBrokerSegment < Segment PRODUCE = 'Produce'.freeze QUEUE = 'Queue'.freeze PURGE = 'Purge'.freeze - SLASH = '/'.freeze TEMP = 'Temp'.freeze TOPIC = 'Topic'.freeze UNKNOWN = 'Unknown'.freeze @@ -73,7 +72,7 @@ def name return @name if @name @name = METRIC_PREFIX + library - @name << SLASH << TYPES[destination_type] << SLASH << ACTIONS[action] << SLASH + @name << NewRelic::SLASH << TYPES[destination_type] << NewRelic::SLASH << ACTIONS[action] << NewRelic::SLASH if destination_type == :temporary_queue || destination_type == :temporary_topic @name << TEMP diff --git a/lib/new_relic/agent/transaction/request_attributes.rb b/lib/new_relic/agent/transaction/request_attributes.rb index 1a1cb941f7..60486ae94c 100644 --- a/lib/new_relic/agent/transaction/request_attributes.rb +++ b/lib/new_relic/agent/transaction/request_attributes.rb @@ -103,12 +103,10 @@ def referer_from_request(request) # rails construct the PATH_INFO enviroment variable improperly and we're generally # being defensive. - ROOT_PATH = '/'.freeze - def path_from_request(request) path = attribute_from_request(request, :path) || '' path = HTTPClients::URIUtil.strip_query_string(path) - path.empty? ? ROOT_PATH : path + path.empty? ? NewRelic::ROOT : path end def content_length_from_request(request) diff --git a/lib/new_relic/agent/utilization/gcp.rb b/lib/new_relic/agent/utilization/gcp.rb index 06d67cac29..b5260a037d 100644 --- a/lib/new_relic/agent/utilization/gcp.rb +++ b/lib/new_relic/agent/utilization/gcp.rb @@ -24,10 +24,8 @@ def prepare_response(response) body end - SLASH = '/'.freeze - def trim_leading(value) - value.split(SLASH).last + value.split(NewRelic::SLASH).last end end end diff --git a/lib/new_relic/constants.rb b/lib/new_relic/constants.rb index 847b73a994..2a8aafb1c2 100644 --- a/lib/new_relic/constants.rb +++ b/lib/new_relic/constants.rb @@ -35,4 +35,7 @@ module NewRelic CONNECT_RETRY_PERIODS = [15, 15, 30, 60, 120, 300] MAX_RETRY_PERIOD = 300 + + SLASH = '/' + ROOT = SLASH end