-
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
fa9bed9
commit e08a270
Showing
7 changed files
with
98 additions
and
2 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
57 changes: 57 additions & 0 deletions
57
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,57 @@ | ||
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 = headers["x-instana-t"] | ||
local span_id = headers["x-instana-s"] | ||
local level_id = headers["x-instana-l"] | ||
|
||
if trace_id then | ||
trace_id = trace_id:match("^(%x+)") | ||
if not trace_id then | ||
kong.log.warn("x-instana-t header invalid; ignoring.") | ||
end | ||
end | ||
|
||
if span_id then | ||
span_id = span_id:match("^(%x+)") | ||
if not span_id then | ||
kong.log.warn("x-instana-s header invalid; ignoring.") | ||
end | ||
end | ||
|
||
if level_id 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 = level_id:match("^([0-1])$") | ||
or level_id:match("^([0-1]),correlationType=(.-);correlationId=(.*)") | ||
end | ||
local should_sample = level_id or "1" | ||
|
||
|
||
|
||
trace_id = from_hex(trace_id) or nil | ||
span_id = from_hex(span_id) 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 }, | ||
span_id_size_bytes = 16, | ||
}) | ||
|
||
|
||
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