Sn0rt commented on issue #9921:
URL: https://github.com/apache/apisix/issues/9921#issuecomment-1659502783

   @EverHopeful are you try this feature at newest version ? 
   
   I have try the follow test case at newest version and the result is pass.
   
   and I try this test case in yours version (2.15) can't pass. 
   
   so can you help me try the feature at newest release (3.4.1) currently for 
walk around ?
   
   
   
   ```lua
   === TEST 19: set additional_attributes
   --- config
       location /t {
           content_by_lua_block {
               local t = require("lib.test_admin").test
               local code, body = t('/apisix/admin/services/1',
                   ngx.HTTP_PUT,
                   [[{
                       "name": "service_name",
                       "upstream": {
                           "nodes": {
                               "127.0.0.1:1980": 1
                           },
                           "type": "roundrobin"
                       }
                   }]]
               )
               if code >= 300 then
                   ngx.status = code
                   ngx.say(body)
                   return
               end
               local code, body = t('/apisix/admin/routes/1',
                   ngx.HTTP_PUT,
                   [[{
                       "name": "route_name",
                       "plugins": {
                           "opentelemetry": {
                               "sampler": {
                                   "name": "always_on"
                               },
                               "additional_attributes": [
                                   "http_user_agent",
                                   "arg_foo",
                                   "cookie_token",
                                   "remote_addr",
                                   "upstream_response_time",
                                   "request_time"
   
                               ]
                           }
                       },
                       "uri": "/opentracing",
                       "service_id": "1"
                   }]]
                   )
   
               if code >= 300 then
                   ngx.status = code
               end
               ngx.say(body)
           }
       }
   
   
   
   === TEST 20: trigger opentelemetry, test trace_id_source=x-request-id, 
custom resource, additional_attributes
   --- extra_yaml_config
   plugins:
       - opentelemetry
   plugin_attr:
       opentelemetry:
           trace_id_source: x-request-id
           resource:
               service.name: test
               test_key: test_val
           batch_span_processor:
               max_export_batch_size: 1
               inactive_timeout: 0.5
   --- extra_init_by_lua
       local core = require("apisix.core")
       local otlp = require("opentelemetry.trace.exporter.otlp")
       local span_kind = require("opentelemetry.trace.span_kind")
       otlp.export_spans = function(self, spans)
           if (#spans ~= 1) then
               ngx.log(ngx.ERR, "unexpected spans length: ", #spans)
               return
           end
   
           local span = spans[1]
           if span:context().trace_id ~= "01010101010101010101010101010101" then
               ngx.log(ngx.ERR, "unexpected trace id: ", 
span:context().trace_id)
               return
           end
   
           local current_span_kind = span:plain().kind
           if current_span_kind ~= span_kind.server then
               ngx.log(ngx.ERR, "expected span.kind to be server but got ", 
current_span_kind)
               return
           end
   
           if span.name ~= "/opentracing?foo=bar&a=b" then
               ngx.log(ngx.ERR, "expect span name: /opentracing?foo=bar&a=b, 
but got ", span.name)
               return
           end
   
           local expected_resource_attrs = {
               test_key = "test_val",
           }
           expected_resource_attrs["service.name"] = "test"
           expected_resource_attrs["telemetry.sdk.language"] = "lua"
           expected_resource_attrs["telemetry.sdk.name"] = "opentelemetry-lua"
           expected_resource_attrs["telemetry.sdk.version"] = "0.1.1"
           expected_resource_attrs["hostname"] = core.utils.gethostname()
           local actual_resource_attrs = 
span.tracer.provider.resource:attributes()
           if #actual_resource_attrs ~= 6 then
               ngx.log(ngx.ERR, "expect len(actual_resource) = 6, but got ", 
#actual_resource_attrs)
               return
           end
           for _, attr in ipairs(actual_resource_attrs) do
               local expected_val = expected_resource_attrs[attr.key]
               if not expected_val then
                   ngx.log(ngx.ERR, "unexpected resource attr key: ", attr.key)
                   return
               end
               if attr.value.string_value ~= expected_val then
                   ngx.log(ngx.ERR, "unexpected resource attr val: ", 
attr.value.string_value)
                   return
               end
           end
   
           local expected_attributes = {
               service = "service_name",
               route = "route_name",
               http_user_agent = "test_nginx",
               arg_foo = "bar",
               cookie_token = "auth_token",
               remote_addr = "127.0.0.1",
           }
           if #span.attributes ~= 6 then
               ngx.log(ngx.ERR, "expect len(span.attributes) = 6, but got ", 
#span.attributes)
               return
           end
           for _, attr in ipairs(span.attributes) do
               local expected_val = expected_attributes[attr.key]
               if not expected_val then
                   ngx.log(ngx.ERR, "unexpected attr key: ", attr.key)
                   return
               end
               if attr.value.string_value ~= expected_val then
                   ngx.log(ngx.ERR, "unexpected attr val: ", 
attr.value.string_value)
                   return
               end
           end
   
           ngx.log(ngx.INFO, "opentelemetry export span")
       end
   --- request
   GET /opentracing?foo=bar&a=b
   --- more_headers
   X-Request-Id: 01010101010101010101010101010101
   User-Agent: test_nginx
   Cookie: token=auth_token;
   --- response_body
   opentracing
   --- wait: 1
   --- grep_error_log eval
   qr/opentelemetry export span/
   --- grep_error_log_out
   opentelemetry export span
   
   ```


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