From 3af58a8ec8256c09906ed1a289f61deb0d9a2fa6 Mon Sep 17 00:00:00 2001 From: Mayo Date: Thu, 22 Sep 2022 11:33:02 +0700 Subject: [PATCH 1/2] fix(opentelemetry) set default propagation type to w3c According to the original design, the default propagation header type should be `w3c`, described in https://docs.konghq.com/hub/kong-inc/opentelemetry/#propagation. > The plugin detects the propagation format from the headers and will use the appropriate format to propagate the span context. If no appropriate format is found, the plugin will failback to the default format, which is w3c. The previous implementation didn't specify the default header type successfully, it was failbacked to the `b3` default. WIP: add tests. --- kong/plugins/opentelemetry/handler.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/kong/plugins/opentelemetry/handler.lua b/kong/plugins/opentelemetry/handler.lua index 8ca68b5225d..0df72bec6cc 100644 --- a/kong/plugins/opentelemetry/handler.lua +++ b/kong/plugins/opentelemetry/handler.lua @@ -178,7 +178,7 @@ function OpenTelemetryHandler:rewrite() root_span.parent_id = span_id end - propagation_set("w3c", header_type, root_span) + propagation_set("w3c", header_type, root_span, "w3c") end function OpenTelemetryHandler:log(conf) From e2b20203db1de5949153ce467f3345c5b5bd0227 Mon Sep 17 00:00:00 2001 From: Mayo Date: Wed, 26 Oct 2022 06:30:51 +0000 Subject: [PATCH 2/2] fix default header type --- kong/plugins/opentelemetry/handler.lua | 2 +- .../37-opentelemetry/03-propagation_spec.lua | 15 ++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/kong/plugins/opentelemetry/handler.lua b/kong/plugins/opentelemetry/handler.lua index 0df72bec6cc..3125c79f636 100644 --- a/kong/plugins/opentelemetry/handler.lua +++ b/kong/plugins/opentelemetry/handler.lua @@ -178,7 +178,7 @@ function OpenTelemetryHandler:rewrite() root_span.parent_id = span_id end - propagation_set("w3c", header_type, root_span, "w3c") + propagation_set("preserve", header_type, root_span, "w3c") end function OpenTelemetryHandler:log(conf) diff --git a/spec/03-plugins/37-opentelemetry/03-propagation_spec.lua b/spec/03-plugins/37-opentelemetry/03-propagation_spec.lua index bb7803158cc..8ce89d2a1f0 100644 --- a/spec/03-plugins/37-opentelemetry/03-propagation_spec.lua +++ b/spec/03-plugins/37-opentelemetry/03-propagation_spec.lua @@ -53,6 +53,18 @@ describe("propagation tests #" .. strategy, function() helpers.stop_kong() end) + it("default propagation headers (w3c)", function() + local r = proxy_client:get("/", { + headers = { + host = "http-route", + }, + }) + local body = assert.response(r).has.status(200) + local json = cjson.decode(body) + + assert.matches("00%-%x+-%x+-01", json.headers.traceparent) + end) + it("propagates tracing headers (b3 request)", function() local trace_id = gen_trace_id() local r = proxy_client:get("/", { @@ -65,7 +77,6 @@ describe("propagation tests #" .. strategy, function() local body = assert.response(r).has.status(200) local json = cjson.decode(body) assert.equals(trace_id, json.headers["x-b3-traceid"]) - assert.matches("00%-" .. trace_id .. "%-%x+-01", json.headers.traceparent) end) describe("propagates tracing headers (b3-single request)", function() @@ -83,7 +94,6 @@ describe("propagation tests #" .. strategy, function() local body = assert.response(r).has.status(200) local json = cjson.decode(body) assert.matches(trace_id .. "%-%x+%-1%-%x+", json.headers.b3) - assert.matches("00%-" .. trace_id .. "%-%x+-01", json.headers.traceparent) end) it("without parent_id", function() @@ -99,7 +109,6 @@ describe("propagation tests #" .. strategy, function() local body = assert.response(r).has.status(200) local json = cjson.decode(body) assert.matches(trace_id .. "%-%x+%-1", json.headers.b3) - assert.matches("00%-" .. trace_id .. "%-%x+-01", json.headers.traceparent) end) end)