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(opentelemetry): tostring header_type avoid concatenation nil error in log #13612

Draft
wants to merge 1 commit into
base: release/3.4.x
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
message: "**OpenTelemetry**: Fixed an issue where header_type being nil caused a concatenation error."
type: bugfix
scope: Plugin
2 changes: 1 addition & 1 deletion kong/tracing/propagation.lua
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ local function set(conf_header_type, found_header_type, proxy_span, conf_default
found_header_type ~= nil and
conf_header_type ~= found_header_type
then
kong.log.warn("Mismatched header types. conf: " .. conf_header_type .. ". found: " .. found_header_type)
kong.log.warn("Mismatched header types. conf: " .. tostring(conf_header_type) .. ". found: " .. found_header_type)
end

found_header_type = found_header_type or conf_default_header_type or "b3"
Expand Down
28 changes: 28 additions & 0 deletions spec/03-plugins/37-opentelemetry/03-propagation_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,11 @@ describe("propagation tests #" .. strategy, function()
service = service,
})

local null_header_type_route = bp.routes:insert({
hosts = { "null-header-type" },
service = service,
})

bp.plugins:insert({
name = "opentelemetry",
route = {id = bp.routes:insert({
Expand Down Expand Up @@ -123,6 +128,15 @@ describe("propagation tests #" .. strategy, function()
}
})

bp.plugins:insert({
name = "opentelemetry",
route = null_header_type_route,
config = {
endpoint = "http://localhost:8080/v1/traces",
header_type = require("cjson").null,
}
})

helpers.start_kong({
database = strategy,
plugins = "bundled, trace-propagator",
Expand Down Expand Up @@ -258,6 +272,20 @@ describe("propagation tests #" .. strategy, function()
assert.not_matches("00%-" .. trace_id .. "%-%x+-01", json.headers.traceparent)
end)

it("null_header_type", function()
local trace_id = gen_trace_id()
local r = proxy_client:get("/", {
headers = {
["x-b3-sampled"] = "1",
["x-b3-traceid"] = trace_id,
host = "null-header-type",
},
})
local body = assert.response(r).has.status(200)
local json = cjson.decode(body)
assert.is_nil(json.headers.traceparent)
end)

it("propagates w3c tracing headers when header_type set to w3c", function()
local trace_id = gen_trace_id()
local parent_id = gen_span_id()
Expand Down
Loading