-
Notifications
You must be signed in to change notification settings - Fork 4.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(tracing): Add instana header support in propagation
- Loading branch information
1 parent
8eaeef1
commit adfb4cb
Showing
8 changed files
with
110 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
message: | | ||
**OpenTelemetry**: include instana header support in propagation | ||
type: feature | ||
scope: Plugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 67 additions & 0 deletions
67
kong/observability/tracing/propagation/extractors/instana.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
local _EXTRACTOR = require "kong.observability.tracing.propagation.extractors._base" | ||
local propagation_utils = require "kong.observability.tracing.propagation.utils" | ||
local from_hex = propagation_utils.from_hex | ||
|
||
local INSTANA_EXTRACTOR = _EXTRACTOR:new({ | ||
headers_validate = { | ||
any = { | ||
"x-instana-t", | ||
"x-instana-s", | ||
"x-instana-l", | ||
} | ||
} | ||
}) | ||
|
||
function INSTANA_EXTRACTOR:get_context(headers) | ||
|
||
local trace_id_raw = headers["x-instana-t"] | ||
|
||
if type(trace_id_raw) ~= "string" then | ||
return | ||
end | ||
|
||
if trace_id_raw then | ||
trace_id_raw = trace_id_raw:match("^(%x+)") | ||
local trace_id_len = trace_id_raw and #trace_id_raw or 0 | ||
if not trace_id_raw or | ||
not(trace_id_len == 16 or trace_id_len == 32) | ||
then | ||
kong.log.warn("x-instana-t header invalid; ignoring.") | ||
end | ||
end | ||
|
||
local span_id_raw = headers["x-instana-s"] | ||
|
||
if type(span_id_raw) ~= "string" then | ||
return | ||
end | ||
|
||
if span_id_raw then | ||
span_id_raw = span_id_raw:match("^(%x+)") | ||
if not span_id_raw then | ||
kong.log.warn("x-instana-s header invalid; ignoring.") | ||
end | ||
end | ||
|
||
local level_id_raw = headers["x-instana-l"] | ||
|
||
if level_id_raw then | ||
-- the flag can come in as "0" or "1" | ||
-- or something like the following format | ||
-- "1,correlationType=web;correlationId=1234567890abcdef" | ||
-- here we only care about the first value | ||
level_id_raw = level_id_raw:sub(1, 1) | ||
end | ||
local should_sample = level_id_raw == "1" | ||
|
||
local trace_id = trace_id_raw and from_hex(trace_id_raw) or nil | ||
local span_id = span_id_raw and from_hex(span_id_raw) or nil | ||
|
||
return { | ||
trace_id = trace_id, | ||
span_id = span_id, | ||
should_sample = should_sample, | ||
} | ||
end | ||
|
||
return INSTANA_EXTRACTOR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
kong/observability/tracing/propagation/injectors/instana.lua
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
local _INJECTOR = require "kong.observability.tracing.propagation.injectors._base" | ||
local to_hex = require "resty.string".to_hex | ||
|
||
local INSTANA_INJECTOR = _INJECTOR:new({ | ||
name = "instana", | ||
context_validate = {}, -- all fields are optional | ||
trace_id_allowed_sizes = { 16, 8}, | ||
span_id_size_bytes = 8, | ||
}) | ||
|
||
|
||
function INSTANA_INJECTOR:create_headers(out_tracing_ctx) | ||
local headers = { | ||
["x-instana-t"] = to_hex(out_tracing_ctx.trace_id) or nil, | ||
["x-instana-s"] = to_hex(out_tracing_ctx.span_id) or nil, | ||
} | ||
|
||
if out_tracing_ctx.should_sample ~= nil then | ||
headers["x-instana-l"] = out_tracing_ctx.should_sample and "1" or "0" | ||
end | ||
|
||
return headers | ||
end | ||
|
||
|
||
function INSTANA_INJECTOR:get_formatted_trace_id(trace_id) | ||
return { instana = to_hex(trace_id) } | ||
end | ||
|
||
|
||
return INSTANA_INJECTOR |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters