Skip to content

Commit aa41f5f

Browse files
committed
Include SCRIPT_NAME when determining path
When determining the path for a request, `Rack::Request` prefixes the `SCRIPT_NAME`, [as seen here][1]. This makes sure the relative path is included. At work, we use [Iodine](https://github.com/boazsegev/iodine) and Turbolinks, and without this patch most of our requests paths in Promethus are `""`. This patch fixes that. [1]: https://github.com/rack/rack/blob/294fd239a71aab805877790f0a92ee3c72e67d79/lib/rack/request.rb#L512 Signed-off-by: Ian Ker-Seymer <i.kerseymer@gmail.com>
1 parent 872a8eb commit aa41f5f

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

lib/prometheus/middleware/collector.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,17 @@ def trace(env)
6767
end
6868

6969
def record(env, code, duration)
70+
path = env[Rack::SCRIPT_NAME] + env[Rack::PATH_INFO]
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)

0 commit comments

Comments
 (0)