Skip to content

Commit

Permalink
Optimize label building
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Ker-Seymer <i.kerseymer@gmail.com>
  • Loading branch information
ianks committed Jul 14, 2020
1 parent aa41f5f commit f50ee67
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions lib/prometheus/middleware/collector.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,20 +68,10 @@ def trace(env)

def record(env, code, duration)
path = env[Rack::SCRIPT_NAME] + env[Rack::PATH_INFO]
shared_labels = { method: env['REQUEST_METHOD'].downcase, path: strip_ids_from_path(path) }

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

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

@requests.increment(labels: counter_labels)
@durations.observe(duration, labels: duration_labels)
@requests.increment(labels: { code: code, **shared_labels })
@durations.observe(duration, labels: shared_labels)
rescue
# TODO: log unexpected exception during request recording
nil
Expand Down

0 comments on commit f50ee67

Please sign in to comment.