diff --git a/examples/rack/README.md b/examples/rack/README.md index d96546d0..ee6472d5 100644 --- a/examples/rack/README.md +++ b/examples/rack/README.md @@ -44,21 +44,20 @@ Prometheus server can be used to [play around with the metrics][rate-query]. The example shown in [`config.ru`](config.ru) is a trivial rack application using the default collector and exporter middlewares. -In order to use custom label builders in the collector, change the line to -something like this: - -```ruby -use Prometheus::Middleware::Collector, counter_label_builder: ->(env, code) { - next { code: nil, method: nil, host: nil, path: nil } if env.empty? - - { - code: code, - method: env['REQUEST_METHOD'].downcase, - # Include the HTTP Host header as label. - host: env['HTTP_HOST'].to_s, - # Include path, but replace all numeric IDs to keep cardinality low. - # Think '/users/1234/comments' -> '/users/:id/comments' - path: env['PATH_INFO'].to_s.gsub(/\/\d+(\/|$)/, '/:id\\1'), - } -} +Modifying the labels is a subject under development (see #111) but one option is to subclass `Prometheus::Middleware::Collector` and override the methods you need. For example, if you want to [strip IDs from the path](https://github.com/prometheus/client_ruby/blob/982fe2e3c37e2940d281573c7689224152dd791f/lib/prometheus/middleware/collector.rb#L97-L101) you could override the appropriate method: + +```Ruby +require 'prometheus/middleware/collector' +module Prometheus + module Middleware + class MyCollector < Collector + def strip_ids_from_path(path) + super(path) + .gsub(/8675309/, ':jenny\\1') + end + end + end +end ``` + +and in `config.ru` use your class instead.