-
Notifications
You must be signed in to change notification settings - Fork 4.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(plugin): OTEL exporting with translate #10332
Changes from 10 commits
abb3cf6
db0d403
2065cfc
9ce8c63
ce60216
bde853a
4aba447
331415d
dc3813d
610bafb
a5a8008
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -10,8 +10,13 @@ local insert = table.insert | |||||||||
local tablepool_fetch = tablepool.fetch | ||||||||||
local tablepool_release = tablepool.release | ||||||||||
local deep_copy = utils.deep_copy | ||||||||||
local shallow_copy = utils.shallow_copy | ||||||||||
local table_merge = utils.table_merge | ||||||||||
local getmetatable = getmetatable | ||||||||||
local setmetatable = setmetatable | ||||||||||
|
||||||||||
local TRACE_ID_LEN = 16 | ||||||||||
local NULL = "\0" | ||||||||||
local POOL_OTLP = "KONG_OTLP" | ||||||||||
local EMPTY_TAB = {} | ||||||||||
|
||||||||||
|
@@ -72,9 +77,39 @@ local function transform_events(events) | |||||||||
return pb_events | ||||||||||
end | ||||||||||
|
||||||||||
-- this function is to translate the span to otlp span, but of universal span format | ||||||||||
local function translate_span(span) | ||||||||||
local trace_id = span.trace_id | ||||||||||
local len = #trace_id | ||||||||||
local new_id = trace_id | ||||||||||
|
||||||||||
StarlightIbuki marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
if len == TRACE_ID_LEN then | ||||||||||
return span | ||||||||||
end | ||||||||||
|
||||||||||
-- make sure the trace id is of 16 bytes | ||||||||||
if len > TRACE_ID_LEN then | ||||||||||
new_id = trace_id:sub(-TRACE_ID_LEN) | ||||||||||
|
||||||||||
elseif len < TRACE_ID_LEN then | ||||||||||
new_id = NULL:rep(TRACE_ID_LEN - len) .. trace_id | ||||||||||
end | ||||||||||
|
||||||||||
local translated = shallow_copy(span) | ||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is a I would have expected this function to do something like:
And the usage would be, when creating the root span:
And inside
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, I don't recommend using abstract names (like There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The span passed in may also be used by other plugins. We need to preserve as much original information as possible, and only do the transformation for exporting/propagating. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I agree naming is a problem, but There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And the function is in the file "otlp.lua" so I think we do not need to suffix it with "_otlp". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
We cannot just modify the |
||||||||||
setmetatable(translated, getmetatable(span)) | ||||||||||
|
||||||||||
translated.trace_id = new_id | ||||||||||
span = translated | ||||||||||
|
||||||||||
return span | ||||||||||
Comment on lines
+105
to
+107
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick, not needed if we don't do a shallow copy.
Suggested change
|
||||||||||
end | ||||||||||
|
||||||||||
-- this function is to tranform universal span to otlp span that fits the protobuf | ||||||||||
local function transform_span(span) | ||||||||||
assert(type(span) == "table") | ||||||||||
|
||||||||||
span = translate_span(span) | ||||||||||
|
||||||||||
local pb_span = { | ||||||||||
trace_id = span.trace_id, | ||||||||||
span_id = span.span_id, | ||||||||||
|
@@ -161,6 +196,7 @@ do | |||||||||
end | ||||||||||
|
||||||||||
return { | ||||||||||
translate_span = translate_span, | ||||||||||
transform_span = transform_span, | ||||||||||
encode_traces = encode_traces, | ||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand what "but of universal span format" means.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The original design to support arbitrary types of tracing plugins has not made it clear: