Copilot commented on code in PR #13265:
URL: https://github.com/apache/apisix/pull/13265#discussion_r3151436370
##########
t/plugin/opentelemetry.t:
##########
@@ -488,3 +488,154 @@ opentracing
tail -n 1 ci/pod/otelcol-contrib/data-otlp.json
--- response_body eval
qr/.*opentelemetry-lua.*/
+
+
+
+=== TEST 23: setup consumer_name in additional_attributes
+--- extra_yaml_config
+plugins:
+ - opentelemetry
+ - key-auth
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/consumers',
+ ngx.HTTP_PUT,
+ [[{
+ "username": "john",
+ "plugins": {
+ "key-auth": {
+ "key": "john-key"
+ }
+ }
+ }]]
+ )
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(body)
+ return
+ end
+
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PUT,
+ [[{
+ "plugins": {
+ "key-auth": {},
+ "opentelemetry": {
+ "sampler": {
+ "name": "always_on"
+ },
+ "additional_attributes": [
+ "consumer_name"
+ ]
+ }
+ },
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:1980": 1
+ },
+ "type": "roundrobin"
+ },
+ "uri": "/opentracing"
+ }]]
+ )
+ if code >= 300 then
+ ngx.status = code
+ end
+ ngx.say(body)
+ }
+ }
+--- request
+GET /t
+
+
+
+=== TEST 24: trigger opentelemetry with consumer
+--- extra_yaml_config
+plugins:
+ - opentelemetry
+ - key-auth
+--- request
+GET /opentracing
+--- more_headers
+X-Request-Id: 01010101010101010101010101010102
+apikey: john-key
+--- wait: 2
+--- response_body
+opentracing
+
+
+
+=== TEST 25: check consumer_name in span attributes
+--- exec
+tail -n 1 ci/pod/otelcol-contrib/data-otlp.json
Review Comment:
Using `tail -n 1` plus a broad regex can make the test flaky if another span
is exported after the request (or if exports are reordered). To make this
deterministic, match the exported record for the triggering request (e.g.,
grep/filter for the specific `X-Request-Id` value in the JSON or parse and
assert on the span whose request-id attribute matches
`01010101010101010101010101010102`).
```suggestion
grep '01010101010101010101010101010102' ci/pod/otelcol-contrib/data-otlp.json
```
##########
t/plugin/opentelemetry.t:
##########
@@ -488,3 +488,154 @@ opentracing
tail -n 1 ci/pod/otelcol-contrib/data-otlp.json
--- response_body eval
qr/.*opentelemetry-lua.*/
+
+
+
+=== TEST 23: setup consumer_name in additional_attributes
+--- extra_yaml_config
+plugins:
+ - opentelemetry
+ - key-auth
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/consumers',
+ ngx.HTTP_PUT,
+ [[{
+ "username": "john",
+ "plugins": {
+ "key-auth": {
+ "key": "john-key"
+ }
+ }
+ }]]
+ )
+ if code >= 300 then
+ ngx.status = code
+ ngx.say(body)
+ return
+ end
+
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PUT,
+ [[{
+ "plugins": {
+ "key-auth": {},
+ "opentelemetry": {
+ "sampler": {
+ "name": "always_on"
+ },
+ "additional_attributes": [
+ "consumer_name"
+ ]
+ }
+ },
+ "upstream": {
+ "nodes": {
+ "127.0.0.1:1980": 1
+ },
+ "type": "roundrobin"
+ },
+ "uri": "/opentracing"
+ }]]
+ )
+ if code >= 300 then
+ ngx.status = code
+ end
+ ngx.say(body)
+ }
+ }
+--- request
+GET /t
+
+
+
+=== TEST 24: trigger opentelemetry with consumer
+--- extra_yaml_config
+plugins:
+ - opentelemetry
+ - key-auth
+--- request
+GET /opentracing
+--- more_headers
+X-Request-Id: 01010101010101010101010101010102
+apikey: john-key
+--- wait: 2
+--- response_body
+opentracing
+
+
+
+=== TEST 25: check consumer_name in span attributes
+--- exec
+tail -n 1 ci/pod/otelcol-contrib/data-otlp.json
+--- response_body eval
+qr/.*consumer_name.*john.*/
+
+
+
+=== TEST 26: set additional_header_prefix_attributes with header added by
lower-priority plugin
+--- extra_yaml_config
+plugins:
+ - opentelemetry
+ - serverless-pre-function
+--- config
+ location /t {
+ content_by_lua_block {
+ local t = require("lib.test_admin").test
+ local code, body = t('/apisix/admin/routes/1',
+ ngx.HTTP_PUT,
+ [[{
+ "plugins": {
+ "serverless-pre-function": {
+ "phase": "rewrite",
+ "functions": ["return function(conf, ctx)
ngx.req.set_header('x-injected-by-plugin', 'test-value') end"]
+ },
+ "opentelemetry": {
+ "sampler": {
+ "name": "always_on"
+ },
+ "additional_header_prefix_attributes": [
+ "x-injected-*"
+ ]
+ }
+ },
Review Comment:
The test intent is “header added by lower-priority plugin”, but
`serverless-pre-function` priority may not be obviously lower (and could
change), which weakens the regression signal. Consider using a plugin with a
well-known, clearly lower priority than `opentelemetry` that can set request
headers (e.g., `proxy-rewrite`), or otherwise ensure the chosen plugin is
definitively executed after `opentelemetry` in `rewrite`.
--
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]