Module: D13n::Metric::Instrumentation::Sinatra::StreamNamer

Extended by:
StreamNamer
Included in:
StreamNamer
Defined in:
lib/d13n/metric/instrumentation/sinatra/stream_namer.rb

Constant Summary collapse

SINATRA_ROUTE =
'sinatra.route'
UNKNOWN =
'unknown'.freeze
ROOT =
'.'.freeze

Instance Method Summary collapse

Instance Method Details

#for_route(env, request) ⇒ Object



7
8
9
# File 'lib/d13n/metric/instrumentation/sinatra/stream_namer.rb', line 7

def for_route(env, request)
  env[SINATRA_ROUTE]
end

#http_verb(request) ⇒ Object



31
32
33
# File 'lib/d13n/metric/instrumentation/sinatra/stream_namer.rb', line 31

def http_verb(request)
  request.request_method if request.respond_to?(:request_method)
end

#initial_stream_name(request) ⇒ Object



11
12
13
# File 'lib/d13n/metric/instrumentation/sinatra/stream_namer.rb', line 11

def initial_stream_name(request)
  stream_name(UNKNOWN, request)
end

#stream_name(route_text, request) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/d13n/metric/instrumentation/sinatra/stream_namer.rb', line 18

def stream_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 = "#{verb}#{name}" unless verb.nil?
  name
rescue => e
  ::D13n.logger.debug("#{e.class} : #{e.message} - Error encountered trying to identify Sinatra transaction name")
  UNKNOWN
end