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

chore(tracing): log instead of throwing error #14294

Merged
merged 1 commit into from
Feb 20, 2025
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
4 changes: 3 additions & 1 deletion kong/pdk/tracing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,9 @@ function span_mt:finish(end_time_ns)
end

if end_time_ns and end_time_ns < self.start_time_ns then
error("invalid span duration", 2)
ngx_log(ngx_ERR, "invalid span duration: ",
end_time_ns - self.start_time_ns, " for span: ", self.name)
return
end

self.end_time_ns = end_time_ns or ffi_time_unix_nano()
Expand Down
20 changes: 20 additions & 0 deletions spec/01-unit/26-observability/01-tracer_pdk_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ describe("Tracer PDK", function()
c_span.parent = nil
assert.same(tpl, c_span)

log_spy:clear()
assert.has_no.error(function () span:finish() end)
assert.spy(log_spy).was_not_called_with(
ngx.ERR, match.is_string(), match.is_number(), match.is_string(),
match.is_string())
end)

it("set_attribute validation", function ()
Expand Down Expand Up @@ -245,8 +249,12 @@ describe("Tracer PDK", function()

it("access span table after finished", function ()
local span = c_tracer.start_span("meow")
log_spy:clear()
span:finish()
assert.has_no.error(function () span:finish() end)
assert.spy(log_spy).was_not_called_with(
ngx.ERR, match.is_string(), match.is_number(), match.is_string(),
match.is_string())
end)

it("ends span", function ()
Expand All @@ -261,10 +269,22 @@ describe("Tracer PDK", function()

local active_span = c_tracer.active_span()
assert.same(span, active_span)
log_spy:clear()
assert.has_no.error(function () active_span:finish() end)
assert.spy(log_spy).was_not_called_with(
ngx.ERR, match.is_string(), match.is_number(), match.is_string(),
match.is_string())

-- span's property is still accessible
assert.same("meow", active_span.name)

-- invalid span duration does not throw errors
local invalid_span = c_tracer.start_span("invalid")
log_spy:clear()
assert.has_no.error(function () invalid_span:finish(1) end)
assert.spy(log_spy).was_called_with(
ngx.ERR, "invalid span duration: ", match.is_number(), " for span: ",
match.is_string())
end)

it("release span", function ()
Expand Down
Loading