Skip to content

Commit

Permalink
fixup! feat(observability): add OpenTelemetry logs
Browse files Browse the repository at this point in the history
  • Loading branch information
samugi committed Jul 4, 2024
1 parent e351d9f commit f17eb6e
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions kong/globalpatches.lua
Original file line number Diff line number Diff line change
Expand Up @@ -596,20 +596,29 @@ return function(options)
local hook_called = false
_G.ngx.log = function(...)
if hook_called then
-- avoid recursive loops: relies on the hook handler to NOT yield
-- detect recursive loops and yielding from the hook:
old_ngx_log(ngx.ERR, debug.traceback("concurrent execution detected for: ngx.log", 2))
return old_ngx_log(...)
end

-- stack level = 5:
-- The pcall surrounding `run_hook` is to ensure `hook_called` is always
-- reset to `false` after hook execution, even in case an error is thrown
-- by `run_hook`.
--
-- stack level = 6:
-- 1: maybe_push
-- 2: dynamic_hook.pcall
-- 3: dynamic_hook.run_hook
-- 4: patched function
-- 5: caller
-- 5: pcall
-- 6: caller
hook_called = true
dynamic_hook.run_hook("observability_logs", "push", 5, ...)
local ok, err = pcall(dynamic_hook.run_hook, "observability_logs", "push", 6, ...)
hook_called = false

if not ok then
old_ngx_log(ngx.ERR, debug.traceback("observability_logs hook failed: " .. err, 2))
end
return old_ngx_log(...)
end
-- export native ngx.log to be used where
Expand Down

0 comments on commit f17eb6e

Please sign in to comment.