Skip to content

Commit

Permalink
feat(tags) Add http.protocol and http.host tags (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
carnei-ro authored Oct 20, 2021
1 parent 4dd896b commit edb2771
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
7 changes: 7 additions & 0 deletions kong/plugins/zipkin/handler.lua
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,19 @@ if subsystem == "http" then
parent_id,
baggage)

local http_version = req.get_http_version()
local protocol = http_version and 'HTTP/'..http_version or nil

request_span.ip = kong.client.get_forwarded_ip()
request_span.port = kong.client.get_forwarded_port()

request_span:set_tag("lc", "kong")
request_span:set_tag("http.method", method)
request_span:set_tag("http.host", req.get_host())
request_span:set_tag("http.path", req.get_path())
if protocol then
request_span:set_tag("http.protocol", protocol)
end

local static_tags = conf.static_tags
if type(static_tags) == "table" then
Expand Down
8 changes: 7 additions & 1 deletion spec/zipkin_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -392,10 +392,12 @@ describe("http integration tests with zipkin server [#"
["http.method"] = "GET",
["http.path"] = "/",
["http.status_code"] = "200", -- found (matches server status)
["http.protocol"] = "HTTP/1.1",
["http.host"] = "http-route",
lc = "kong",
static = "ok",
foo = "bar",
baz = "qux",
baz = "qux"
}, request_tags)
local consumer_port = request_span.remoteEndpoint.port
assert_is_integer(consumer_port)
Expand Down Expand Up @@ -471,6 +473,8 @@ describe("http integration tests with zipkin server [#"
["http.method"] = "POST",
["http.path"] = "/hello.HelloService/SayHello",
["http.status_code"] = "200", -- found (matches server status)
["http.protocol"] = "HTTP/2",
["http.host"] = "grpc-route",
lc = "kong",
static = "ok",
}, request_tags)
Expand Down Expand Up @@ -655,6 +659,8 @@ describe("http integration tests with zipkin server [#"
["http.method"] = "GET",
["http.path"] = "/foobar",
["http.status_code"] = "404", -- note that this was "not found"
["http.protocol"] = 'HTTP/1.1',
["http.host"] = '0.0.0.0',
lc = "kong",
static = "ok",
error = "true",
Expand Down

0 comments on commit edb2771

Please sign in to comment.