Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

fix(*) timestamps and annotations #60

Merged
merged 4 commits into from
Dec 20, 2019
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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ env:
install:
- git clone --single-branch https://$GITHUB_TOKEN:@github.com/Kong/kong-ci.git ../kong-ci
- source ../kong-ci/setup_plugin_env.sh
- docker run -d --name zipkin -p 9411:9411 openzipkin/zipkin && while ! curl localhost:9411/health; do sleep 1; done

script:
- eval $LUACHECK_CMD
Expand Down
13 changes: 10 additions & 3 deletions kong/plugins/zipkin/reporter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ local cjson = require "cjson".new()
cjson.encode_number_precision(16)

local floor = math.floor
local gsub = string.gsub

local zipkin_reporter_methods = {}
local zipkin_reporter_mt = {
Expand Down Expand Up @@ -99,9 +100,15 @@ function zipkin_reporter_methods:report(span)
annotations = kong.table.new(n_logs, 0)
for i = 1, n_logs do
local log = span.logs[i]

-- Shortens the log strings into annotation values
-- for Zipkin. "kong.access.start" becomes "kas"
local value = gsub(log.key .. "." .. log.value,
"%.?(%w)[^%.]*",
"%1")
annotations[i] = {
event = log.key .. "." .. log.value,
timestamp = log.timestamp,
value = value,
timestamp = floor(log.timestamp),
}
end
end
Expand All @@ -117,7 +124,7 @@ function zipkin_reporter_methods:report(span)
parentId = span_context.parent_id and to_hex(span_context.parent_id) or nil,
id = to_hex(span_context.span_id),
kind = span_kind_map[span_kind],
timestamp = span.timestamp * 1000000,
timestamp = floor(span.timestamp * 1000000),
duration = floor(span.duration * 1000000), -- zipkin wants integer
-- shared = nil, -- We don't use shared spans (server reuses client generated spanId)
-- TODO: debug?
Expand Down
Loading