Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(zipkin): avoid getting a nil value in log phase(#10590) #10666

Merged
merged 2 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions apisix/plugins/zipkin.lua
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,15 @@ end


function _M.log(conf, ctx)
if ctx.zipkin then
core.tablepool.release("zipkin_ctx", ctx.zipkin)
ctx.zipkin = nil
end

if not ctx.opentracing_sample then
return
end

local opentracing = ctx.opentracing

local log_end_time = opentracing.tracer:time()
Expand All @@ -302,11 +311,6 @@ function _M.log(conf, ctx)
opentracing.request_span:set_tag("http.status_code", upstream_status)

opentracing.request_span:finish(log_end_time)

if ctx.zipkin then
core.tablepool.release("zipkin_ctx", ctx.zipkin)
ctx.zipkin = nil
end
end

return _M
15 changes: 15 additions & 0 deletions t/plugin/zipkin.t
Original file line number Diff line number Diff line change
Expand Up @@ -467,3 +467,18 @@ GET /t
--- response_body
1
0



=== TEST 23: no error in log phase while b3 header invalid
--- request
GET /echo
--- more_headers
b3: 80f198ee56343ba864fe8b2a57d3eff7
--- response_headers
x-b3-sampled:
--- error_code: 400
--- error_log
invalid b3 header
--- no_error_log
attempt to index local 'opentracing' (a nil value)
Loading