Skip to content

Commit

Permalink
Add output description to latency functions (#297)
Browse files Browse the repository at this point in the history
  • Loading branch information
yngvar-antonsson authored Sep 9, 2021
1 parent 79f6b15 commit ec73907
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
14 changes: 9 additions & 5 deletions metrics/collectors/shared.lua
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,14 @@ local function observe_latency_tail(collector, label_pairs, start_time, ok, resu
if type(label_pairs) == 'function' then
label_pairs = label_pairs(ok, result, ...)
end
xpcall(function()
collector:observe(latency, label_pairs) end,
function(err)
log.error(debug.traceback('Saving metrics failed: ' .. tostring(err)))
end)
xpcall(
function()
collector:observe(latency, label_pairs)
end,
function(err)
log.error(debug.traceback('Saving metrics failed: ' .. tostring(err)))
end
)
if not ok then
error(result)
end
Expand All @@ -104,6 +107,7 @@ end
-- If function is given its called with the results of pcall.
-- @param fn function for pcall to instrument
-- ... - args for function fn
-- @return value from fn
function Shared:observe_latency(label_pairs, fn, ...)
return observe_latency_tail(self, label_pairs, clock.monotonic(), pcall(fn, ...))
end
Expand Down
1 change: 1 addition & 0 deletions metrics/http_middleware.lua
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ end
-- @string route.path
-- @string route.method
-- ... arguments for pcall to instrument
-- @return value from observable function
function export.observe(collector, route, ...)
return collector:observe_latency(function(ok, result)
return {
Expand Down

0 comments on commit ec73907

Please sign in to comment.