Skip to content

Commit

Permalink
Include SCRIPT_NAME when determining path
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
ianks committed Jul 14, 2020
1 parent 872a8eb commit aa41f5f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/prometheus/middleware/collector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,17 @@ def trace(env)
end

def record(env, code, duration)
path = env[Rack::SCRIPT_NAME] + env[Rack::PATH_INFO]

counter_labels = {
code: code,
method: env['REQUEST_METHOD'].downcase,
path: strip_ids_from_path(env['PATH_INFO']),
path: strip_ids_from_path(path),
}

duration_labels = {
method: env['REQUEST_METHOD'].downcase,
path: strip_ids_from_path(env['PATH_INFO']),
path: strip_ids_from_path(path),
}

@requests.increment(labels: counter_labels)
Expand Down

0 comments on commit aa41f5f

Please sign in to comment.