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/08/16 10:25:02 UTC

[GitHub] [apisix] kingluo commented on issue #7674: help request: opentelemetry error in lua script

kingluo commented on issue #7674:
URL: https://github.com/apache/apisix/issues/7674#issuecomment-1216450883

   @akalittle The `hex2bytes` assumes the input string is in valid hex format (`[0-9a-f]{32}`), and transforms each hex u8 number into char. The `char()` assumes the number ranges from 0~255, otherwise it would throw error.
   It's likely your `span.ctx.trace_id` (https://github.com/yangxikun/opentelemetry-lua/blob/v0.1.3/lib/opentelemetry/trace/exporter/otlp.lua#L50) contains `-`, which means negative number and cause `char()` failed. It means your trace id comes from `x-request-id` in invalid format.
   
   ```lua
   local function hex2bytes(str)
       return (str:gsub('..', function (cc)
           local n = tonumber(cc, 16)
           if n then
               print(n)
               return string.char(n)
           end
       end))
   end
   
   hex2bytes("xx-1")
   ```
   
   ```
   /usr/local/openresty-debug/luajit/bin/luajit: bad argument #1 to '?' (invalid value)
   stack traceback:
           [builtin#80]: at 0x5571dae60530
           [C]: in function 'gsub'
           /tmp/test_gsub.lua:2: in function 'hex2bytes'
           /tmp/test_gsub.lua:11: in main chunk
           [C]: at 0x5571dadfc320
   
   ```
   


-- 
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