prometheus/client_ruby — pull request #4 by porras (2014-05-12 15:32:05+00:00)
Title: Allow labels configuration in Rack middleware

This change address a problem I've recently had, but I'm not sure it's the best solution. Let me know what you think.

The problem lies in the `Rack::Collector` using the requested path as a label. Depending on the URL schema of your app (e.g. `/users/:id` in a sinatra handler), this can lead to infinite different values for the `path` label, which is not how labels are meant to be used in prometheus.

With this PR, the user is allowed to provide a block to specify how labels will be generated from the `env`. One can, for example, just ignore the path:

```ruby
use Prometheus::Client::Rack::Collector do |env|
{ method: env['REQUEST_METHOD'].downcase }
end
```

Or use some arbitrary logic to merge multiple paths into one:

```ruby
use Prometheus::Client::Rack::Collector do |env|
{
method: env['REQUEST_METHOD'].downcase,
path: env['PATH_INFO'].to_s.gsub(/\d+/, 'XXX')
# turns /users/12345/items/54321 into /users/XXX/items/XXX
}
end
```

The previous defaults are used if no block is passed.