Skip to content

Commit

Permalink
fix(opentelemetry): tostring header_type avoid concatenation nil er…
Browse files Browse the repository at this point in the history
…ror in log (#10137)

The require of header_type is false, so the consumer can choose `header_type` to be nil in Kong Manager; if this is, Kong Manager would pass `json.null` to Kong, `header_type` could be nil in this case.

This PR respects this behavior and handles concatenation nil error when `header_type` is nil.

Note that this is a fix that only exists in the 3.4 series.

Fix: [FTI-6119](https://konghq.atlassian.net/browse/FTI-6119)

Signed-off-by: tzssangglass <[email protected]>
  • Loading branch information
tzssangglass committed Sep 4, 2024
1 parent 7301c49 commit 7818afe
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
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

0 comments on commit 7818afe

Please sign in to comment.