You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/09/02 09:29:18 UTC
[GitHub] [apisix] tokers commented on a diff in pull request #7822: feat: Add ability to inject headers via prefix to otel traces
tokers commented on code in PR #7822:
URL: https://github.com/apache/apisix/pull/7822#discussion_r961484339
##########
apisix/plugins/opentelemetry.lua:
##########
@@ -273,6 +280,25 @@ local function create_tracer_obj(conf)
end
+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)
Review 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:
```lua
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
end
```
Note it's just a pseudo code.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@apisix.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org