Skip to content
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

help request: 插件 request-id 与 opentelemetry 结合 #7239

Closed
shuqingzai opened this issue Jun 12, 2022 · 11 comments · Fixed by #7281
Closed

help request: 插件 request-id 与 opentelemetry 结合 #7239

shuqingzai opened this issue Jun 12, 2022 · 11 comments · Fixed by #7281

Comments

@shuqingzai
Copy link

shuqingzai commented Jun 12, 2022

Description

问题

request-id 支持三种方式生成: ["uuid", "snowflake", "nanoid"]

  1. 我想使用 request-id 作为 opentelemetry 的 trace_id 但是 trace_id 需要符合 [0-9a-f]{32} 规范,request-id 并没有这样的生成器,是否可以新增一个 request-id 的生成方式?
  2. 我想在 opentelemetry 的 additional_attributes 追加 request-id 属性,但是我试了很多种读取的方式,好像都不能读取,以下是我的配置,请问有啥方式可以读取?
{
    "id": "1",
    "create_time": 1655032228,
    "update_time": 1655045468,
    "plugins": {
        "opentelemetry": {
            "additional_attributes": [
                "route_id",
                "x-request-id",
                "request-id",
                "http_x-request-id",
                "X-Request-Id",
                "http_X-Request-Id"
            ],
            "disable": false,
            "sampler": {
                "name": "always_on",
                "options": {
                    "fraction": 1,
                    "root": {
                        "name": "always_on"
                    }
                }
            }
        },
        "request-id": {
            "algorithm": "snowflake",
            "disable": false,
            "header_name": "X-Request-Id",
            "include_in_response": true
        }
    }
}

Environment

使用版本

官方docker镜像: apache/apisix:2.14.1-centos

docker pull apache/apisix:2.14.1-centos
  • APISIX version (run apisix version):
/usr/local/openresty/luajit/bin/luajit ./apisix/cli/apisix.lua version
2.14.1
  • Operating system (run uname -a):
Linux apisix1 5.10.104-linuxkit #1 SMP Thu Mar 17 17:08:06 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
  • OpenResty / Nginx version (run openresty -V or nginx -V):
nginx version: openresty/1.19.9.1
built by gcc 9.3.1 20200408 (Red Hat 9.3.1-2) (GCC)
built with OpenSSL 1.1.1n  15 Mar 2022
TLS SNI support enabled
configure arguments: --prefix=/usr/local/openresty/nginx --with-cc-opt='-O2 -DAPISIX_BASE_VER=1.19.9.1.6 -DNGX_LUA_ABORT_AT_PANIC -I/usr/local/openresty/zlib/include -I/usr/local/openresty/pcre/include -I/usr/local/openresty/openssl111/include' --add-module=../ngx_devel_kit-0.3.1 --add-module=../echo-nginx-module-0.62 --add-module=../xss-nginx-module-0.06 --add-module=../ngx_coolkit-0.2 --add-module=../set-misc-nginx-module-0.32 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.08 --add-module=../srcache-nginx-module-0.32 --add-module=../ngx_lua-0.10.20 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.33 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.19 --add-module=../redis2-nginx-module-0.15 --add-module=../redis-nginx-module-0.3.7 --add-module=../ngx_stream_lua-0.0.10 --with-ld-opt='-Wl,-rpath,/usr/local/openresty/luajit/lib -Wl,-rpath,/usr/local/openresty/wasmtime-c-api/lib -L/usr/local/openresty/zlib/lib -L/usr/local/openresty/pcre/lib -L/usr/local/openresty/openssl111/lib -Wl,-rpath,/usr/local/openresty/zlib/lib:/usr/local/openresty/pcre/lib:/usr/local/openresty/openssl111/lib' --add-module=/tmp/tmp.itsGpY3Nfs/openresty-1.19.9.1/../mod_dubbo --add-module=/tmp/tmp.itsGpY3Nfs/openresty-1.19.9.1/../ngx_multi_upstream_module --add-module=/tmp/tmp.itsGpY3Nfs/openresty-1.19.9.1/../apisix-nginx-module --add-module=/tmp/tmp.itsGpY3Nfs/openresty-1.19.9.1/../apisix-nginx-module/src/stream --add-module=/tmp/tmp.itsGpY3Nfs/openresty-1.19.9.1/../wasm-nginx-module --add-module=/tmp/tmp.itsGpY3Nfs/openresty-1.19.9.1/../lua-var-nginx-module --with-poll_module --with-pcre-jit --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module --with-http_v2_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --with-http_stub_status_module --with-http_realip_module --with-http_addition_module --with-http_auth_request_module --with-http_secure_link_module --with-http_random_index_module --with-http_gzip_static_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-threads --with-compat --with-stream --with-http_ssl_module
  • etcd version, if relevant (run curl http://127.0.0.1:9090/v1/server_info):
  • APISIX Dashboard version, if relevant:
  • Plugin runner version, for issues related to plugin runners:
  • LuaRocks version, for installation issues (run luarocks --version):
@tzssangglass
Copy link
Member

2. 我想在 opentelemetry 的 additional_attributes 追加 request-id 属性,但是我试了很多种读取的方式,好像都不能读取,以下是我的配置,请问有啥方式可以读取?

opentelemetry and request-id both work on rewrite phase in APISIX, but opentelemetry has a higher priority and is executed before the request-id, so it can't get the id generated by request-id.

maybe we can raise the priority of request-id? what is your option? cc @spacewander @membphis

@tzssangglass
Copy link
Member

  1. 我想使用 request-id 作为 opentelemetry 的 trace_id 但是 trace_id 需要符合 [0-9a-f]{32} 规范,request-id 并没有这样的生成器,是否可以新增一个 request-id 的生成方式?

SGTM

@shuqingzai
Copy link
Author

  1. 我想在 opentelemetry 的 additional_attributes 追加 request-id 属性,但是我试了很多种读取的方式,好像都不能读取,以下是我的配置,请问有啥方式可以读取?

opentelemetry and request-id both work on rewrite phase in APISIX, but opentelemetry has a higher priority and is executed before the request-id, so it can't get the id generated by request-id.

maybe we can raise the priority of request-id? what is your option? cc @spacewander @membphis

我觉得 request-id 应该是级别最高的吧?无论请求是否成功响应,都应该记录一个 request-id 方便排查问题?

@spacewander
Copy link
Member

maybe we can raise the priority of request-id? what is your option?

LGTM.
@shuqingzai
Would you like to work on it?

@shuqingzai
Copy link
Author

maybe we can raise the priority of request-id? what is your option?

LGTM. @shuqingzai Would you like to work on it?

十分抱歉,我对 lua 不是很熟悉。。。

@jagerzhang
Copy link
Contributor

jagerzhang commented Jun 16, 2022

看了下2.11版本的插件优先级:

client-control 22000
ext-plugin-pre-req 12000
zipkin 11011
request-id 11010
fault-injection 11000
serverless-pre-function 10000
batch-requests 4010
cors 4000
ip-restriction 3000
ua-restriction 2999
referer-restriction 2990
uri-blocker 2900
request-validation 2800
openid-connect 2599
wolf-rbac 2555
hmac-auth 2530
basic-auth 2520
jwt-auth 2510
key-auth 2500
consumer-restriction 2400
authz-keycloak 2000
proxy-mirror 1010
proxy-cache 1009
proxy-rewrite 1008
api-breaker 1005
limit-conn 1003
limit-count 1002
limit-req 1001
gzip 995
server-info 990
traffic-split 966
redirect 900
response-rewrite 899
trpc-transcode 677
grpc-transcode 506
prometheus 500
echo 412
http-logger 410
skywalking-logger 408
sls-logger 406
tcp-logger 405
kafka-logger 403
syslog 401
udp-logger 400
opentelemetry -1200 -- last running plugin, but before serverless post func
serverless-post-function -2000
ext-plugin-post-req -3000

requests-id的执行阶段是比较靠前的,不过看最新的代码,opentelemetry 的优先级由-1200改为12009,排到了第二位:

priority = 12009,

priority = 11010,

所以@shuqingzai 你只需要改下插件代码里面的 priority 就能改变这个执行阶段顺序。

@spacewander 所以这里的改动很简单,不过问题是这个x-request-id应该排在第几位执行呢?

@tokers
Copy link
Contributor

tokers commented Jun 16, 2022

Maybe after request-validation?

@jagerzhang
Copy link
Contributor

jagerzhang commented Jun 16, 2022

Maybe after request-validation?

@tokers request-id现在的优先级不低(排在第四位),感觉这里的问题可能还是 opentelemetry 的优先级调得太高了,超过了request-id。

@spacewander
Copy link
Member

opentelemetry is moved to the top so we can report requests which are rejected.
If opentelemetry needs to depend on request-id, the priority of request-id should be higher.

@jagerzhang
Copy link
Contributor

opentelemetry is moved to the top so we can report requests which are rejected. If opentelemetry needs to depend on request-id, the priority of request-id should be higher.

嗯嗯,那这个调整是在apisix这边改还是用户自己改

@spacewander
Copy link
Member

opentelemetry is moved to the top so we can report requests which are rejected. If opentelemetry needs to depend on request-id, the priority of request-id should be higher.

嗯嗯,那这个调整是在apisix这边改还是用户自己改

You can change it yourselves, and submit it to APISIX.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
5 participants