kys1230 opened a new issue, #7572:
URL: https://github.com/apache/apisix/issues/7572

   ### Description
   
   我需要在请求中通过自定义lua插件来生成一个统一变量。并希望将这个变量通过 file-logger 或 kafka-logger 等日志插件进行输出。
   
   以前使用 openresty 是在 server {} 配置中通过 set $var_name ""; 定义了空变量后,在 rewite 阶段执行 
lua 脚本以 ngx.var.$var_name = "xxx" 的方式实现变量的赋值,最终在日志中通过 $var_name 进行输出的。 
   
   但在 apisix 2.15.0 版本中我尝试使用同样的方法,得到的错误是
   
   ```
   2022/07/29 15:26:00 [warn] 49#49: *26280 [lua] _G write guard:12: 
__newindex(): writing a global Lua variable ('$var_name') which may lead to 
race conditions between concurrent requests, so prefer the use of 'local' 
variables
   stack traceback:
        /usr/local/apisix/apisix/plugins/rongcloud-get-appkey.lua:50: in 
function 'phase_func'
        /usr/local/apisix/apisix/plugin.lua:897: in function 'run_plugin'
        /usr/local/apisix/apisix/plugin.lua:961: in function 'run_global_rules'
        /usr/local/apisix/apisix/init.lua:425: in function 'http_access_phase'
        access_by_lua(nginx.conf:287):2: in main chunk, client: 192.168.16.1, 
server: _, request: "HEAD / HTTP/1.1", host: "127.0.0.1:9080"
   ```
   请问有什么其他方法可以更优雅的实现我的需求?感谢!
   
   
   ### Environment
   
   - APISIX version (run `apisix version`): 
   2.15.0
   
   - Operating system (run `uname -a`): 
   Linux c7341dd4c5e9 5.18.7-arch1-1 #1 SMP PREEMPT_DYNAMIC Sat, 25 Jun 2022 
20:22:01 +0000 x86_64 Linux
   
   - OpenResty / Nginx version (run `openresty -V` or `nginx -V`):
   nginx version: openresty/1.21.4.1
   
   - etcd version, if relevant (run `curl 
http://127.0.0.1:9090/v1/server_info`):
   
{"hostname":"c7341dd4c5e9","version":"2.15.0","boot_time":1659108142,"etcd_version":"3.4.0","id":"813de1fd-d3fe-45e4-84e4-462fce20cf9b"}
   
   - APISIX Dashboard version, if relevant:
   
   - Plugin runner version, for issues related to plugin runners:
   自定义插件
   
   - LuaRocks version, for installation issues (run `luarocks --version`):
   /usr/local/bin/luarocks 3.8.0
   LuaRocks main command-line interface
   
   


-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to