feat: Add ability to inject headers via prefix to otel traces#7822
Conversation
| end | ||
| if is_key_a_match then | ||
| for possible_key, value in pairs(source) do | ||
| if string.sub(possible_key, 0, prefix_size) == prefix then |
There was a problem hiding this comment.
We already have a has_prefix method in apisix.core.string.
Co-authored-by: tzssangglass <[email protected]>
spacewander
left a comment
There was a problem hiding this comment.
I am afraid we can't iterate the ctx.var and filter with prefixes to get the variables as it uses a lazy-load mechanism. The wanted attribute may not be loaded when we iterate this object.
Moreover, we already support injecting header via variable http_x_client_version.
However, the headers can be filtered by prefixes. So there is still a new feature "inject headers via prefix". Maybe you can change the title of this PR and also the configuration?
|
@spacewander do you prefer me to change the function |
LGTM |
| local function inject_attributes(attributes, wanted_attributes, source) | ||
| for _, key in ipairs(wanted_attributes) do | ||
| local is_key_a_match = #key >= 2 and key:sub(-1, -1) == "*" | ||
| local prefix = key:sub(0, -2) |
There was a problem hiding this comment.
We can only calculate the prefix only if is_key_a_match is true since it will generate a new string object. What about re-organizing the code to:
local is_prefix_key = #key >= 2 and key:byte(-1, -1) == str_byte("*")
if is_prefix_key then
local prefix = key:sub(0, -2)
for possible_key, value in pairs(source) do
if core.string.has_prefix(possible_key, prefix) then
core.table.insert(attributes, attr.string(possible_key, value))
end
end
else
local val = source[key]
if val then
core.table.insert(attributes, attr.string(key, val))
end
endNote it's just a pseudo code.
| @$(call func_echo_success_status, "$@ -> [ Done ]") | ||
|
|
||
|
|
||
| ### eclint: Validate files against editorconfig |
There was a problem hiding this comment.
Could you move the dev kit stuff to a separate PR? Thanks!
There was a problem hiding this comment.
i've dropped the commit
| minLength = 1, | ||
| } | ||
| }, | ||
| additional_header_attributes = { |
There was a problem hiding this comment.
Better to rename this conf to show it is used for prefix. Otherwise, people will ask why additional_attributes can use http_header but we have another conf called additional_header_attributes.
|
|
||
| local function inject_attributes(attributes, wanted_attributes, source, with_prefix) | ||
| for _, key in ipairs(wanted_attributes) do | ||
| local is_key_a_match = #key >= 2 and key:sub(-1, -1) == "*" and with_prefix |
There was a problem hiding this comment.
key:sub(-1, -1)
Would be better to use :byte?
b5287fb to
c82db59
Compare
c82db59 to
a19a27b
Compare
* upstream/master: (214 commits) feat: set constants.apisix_lua_home for used by plugins (apache#7893) fix: response-rewrite plugin might cause Apache AIPSIX hanging (apache#7836) test: sleep 1 second in t/cli/test_upstream_mtls.sh (apache#7889) fix: reload once when log rotate (apache#7869) change: move etcd conf under deployment (apache#7860) fix: plugin metadata missing v3 adapter call (apache#7877) docs: add ClickHouse and Elasticsearch loggers. (apache#7848) docs(plugin): refactor limit-conn.md (apache#7857) feat: call `destroy` method when Nginx exits (apache#7866) feat: Add ability to inject headers via prefix to otel traces (apache#7822) docs(plugin): refactor proxy-cache.md (apache#7858) fix: don't enable passive healthcheck by default (apache#7850) feat: add openfunction plugin (apache#7634) fix(zipkin): send trace IDs with a reject sampling decision (apache#7833) fix: Change opentelemetry's span kind to server (apache#7830) docs(hmac-auth): additional details for generating signing_string (apache#7816) docs: correct the test-nginx description (apache#7818) docs: add docs of workflow plugin (apache#7813) docs(FAQ): add how to detect APISIX alive status (apache#7812) feat: add elasticsearch-logger (apache#7643) ...
…#7822) Co-authored-by: tzssangglass <[email protected]>
Description
This adds a new feature that allows to inject headers into traces, like, if you have internal headers that would make sense to live as an attribute like x-client-uuid, x-client-version.
It also adds the ability to using prefixes to get the variables, like:
x-client-*Checklist