Skip to content

help request: OpenTelemetry plugin has problems handling Nginx variables of non-string type #9921

Description

@daadc

Description

Hello,

I'm encountering an issue when using the OpenTelemetry plugin with Apache APISIX. I want to add some Nginx variables (such as $request_time and $upstream_response_time) as additional attributes in my trace data.

Here is my configuration:

{
  "plugins": {
      "opentelemetry": {
          "sampler": {
              "name": "always_on"
          },
          "additional_attributes": [
              "upstream_response_time",
              "request_time",
              "host"
          ]
      }
  }
}

However, I get the following error when APISIX tries to process a request:

2023/07/27 20:31:33 [error] 50#50: *127339 lua entry thread aborted: runtime error: ...deps/share/lua/5.1/opentelemetry/trace/exporter/otlp.lua:67: bad argument #2 to 'encode' (string expected for field 'string_value', got number)

It seems that OpenTelemetry's OTLP exporter expects all attribute values to be strings, but the values of Nginx variables like $request_time and $upstream_response_time are not strings.

Is there a recommended way to convert these non-string values to strings before adding them as additional attributes? Or could the OpenTelemetry plugin be modified to automatically handle non-string attribute values?

Thank you for your help.

Environment

  • APISIX version (run apisix version): 2.15.0
  • Operating system (run uname -a): Linux apisix-test-6cd7f9b885-cpq8b 5.15.0-60-generic
  • 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): "etcd:3.5.4-debian-11-r14" image in k8s
  • APISIX Dashboard version, if relevant:
  • Plugin runner version, for issues related to plugin runners:
  • LuaRocks version, for installation issues (run luarocks --version): 3.8.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status
    ✅ Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions