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
ADD-SP committed Jul 5, 2024
1 parent f17eb6e commit d4d9110
Showing 1 changed file with 4 additions and 13 deletions.
17 changes: 4 additions & 13 deletions kong/globalpatches.lua
Original file line number Diff line number Diff line change
Expand Up @@ -596,29 +596,20 @@ return function(options)
local hook_called = false
_G.ngx.log = function(...)
if hook_called then
-- detect recursive loops and yielding from the hook:
-- avoid recursive loops: relies on the hook handler to NOT yield
old_ngx_log(ngx.ERR, debug.traceback("concurrent execution detected for: ngx.log", 2))
return old_ngx_log(...)
end

-- 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:
-- stack level = 5:
-- 1: maybe_push
-- 2: dynamic_hook.pcall
-- 3: dynamic_hook.run_hook
-- 4: patched function
-- 5: pcall
-- 6: caller
-- 5: caller
hook_called = true
local ok, err = pcall(dynamic_hook.run_hook, "observability_logs", "push", 6, ...)
dynamic_hook.run_hook("observability_logs", "push", 5, ...)
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 d4d9110

Please sign in to comment.