File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed
lib/prometheus/middleware
spec/prometheus/middleware Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -67,15 +67,17 @@ def trace(env)
6767 end
6868
6969 def record ( env , code , duration )
70+ path = [ env [ "SCRIPT_NAME" ] , env [ 'PATH_INFO' ] ] . join
71+
7072 counter_labels = {
7173 code : code ,
7274 method : env [ 'REQUEST_METHOD' ] . downcase ,
73- path : strip_ids_from_path ( env [ 'PATH_INFO' ] ) ,
75+ path : strip_ids_from_path ( path ) ,
7476 }
7577
7678 duration_labels = {
7779 method : env [ 'REQUEST_METHOD' ] . downcase ,
78- path : strip_ids_from_path ( env [ 'PATH_INFO' ] ) ,
80+ path : strip_ids_from_path ( path ) ,
7981 }
8082
8183 @requests . increment ( labels : counter_labels )
Original file line number Diff line number Diff line change 5555 expect ( registry . get ( metric ) . get ( labels : labels ) ) . to include ( "0.1" => 0 , "0.25" => 1 )
5656 end
5757
58+ it 'includes SCRIPT_NAME in the path if provided' do
59+ metric = :http_server_requests_total
60+
61+ get '/foo'
62+ expect ( registry . get ( metric ) . values . keys . last [ :path ] ) . to eql ( "/foo" )
63+
64+ env ( 'SCRIPT_NAME' , '/engine' )
65+ get '/foo'
66+ env ( 'SCRIPT_NAME' , nil )
67+ expect ( registry . get ( metric ) . values . keys . last [ :path ] ) . to eql ( "/engine/foo" )
68+ end
69+
5870 it 'normalizes paths containing numeric IDs by default' do
5971 expect ( Benchmark ) . to receive ( :realtime ) . and_yield . and_return ( 0.3 )
6072
You can’t perform that action at this time.
0 commit comments