Skip to content

bug: Skywalking plugin can not be enabled both in Global and Route rules. #4571

Description

@gxthrj

Issue description

WhenSkywalking plugin is enabled both in Global and Route rules.
The route will be failed.

curl: (52) Empty reply from server

Environment

  • apisix version (cmd: apisix version): 2.6
  • OS (cmd: uname -a): centos 7 and docker

Minimal test code / Steps to reproduce the issue

Bug report without steps to reproduce will be ignored or closed.

  1. Binding skywalking plugin in route
curl http://127.0.0.1:9080/apisix/admin/routes/1  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
    "methods": ["GET"],
    "uris": [
        "/*"
    ],
    "plugins": {
        "skywalking": {
            "sample_ratio": 1
        }
    },
    "upstream": {
        "type": "roundrobin",
        "nodes": {
            "httpbin.org": 1
        }
    }
}'
  1. take a request
curl -i http://127.0.0.1:9080/ip
HTTP/1.1 200 OK
Content-Type: application/json
Content-Length: 45
Connection: keep-alive
Date: Fri, 09 Jul 2021 03:29:39 GMT
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Server: APISIX/2.6

{
  "origin": "172.19.0.1, 58.208.180.202"
}

3.Now add Global rule with skywalking plugin.

curl -X PUT \
  http://127.0.0.1:9080/apisix/admin/global_rules/1 \
  -H 'Content-Type: application/json' \
  -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' \
  -d '{
        "plugins": {
            "skywalking": {
                "sample_ratio":1
            }
        }
    }'
  1. take a request
curl -iv http://127.0.0.1:9080/ip
*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to 127.0.0.1 (127.0.0.1) port 9080 (#0)
> GET /ip HTTP/1.1
> Host: 127.0.0.1:9080
> User-Agent: curl/7.64.1
> Accept: */*
>
* Empty reply from server
* Connection #0 to host 127.0.0.1 left intact
curl: (52) Empty reply from server
* Closing connection 0

And the error log

2021/07/09 03:37:03 [error] 45#45: *1029911 failed to run body_filter_by_lua*: /usr/local/apisix//deps/share/lua/5.1/skywalking/span.lua:196: attempt to index local 'span' (a nil value)
stack traceback:
        /usr/local/apisix//deps/share/lua/5.1/skywalking/span.lua:196: in function 'setComponentId'
        /usr/local/apisix/apisix/plugins/skywalking.lua:94: in function 'phase_func'
        /usr/local/apisix/apisix/plugin.lua:689: in function 'run_plugin'
        /usr/local/apisix/apisix/init.lua:530: in function 'common_phase'
        /usr/local/apisix/apisix/init.lua:581: in function 'http_body_filter_phase'
        body_filter_by_lua:2: in main chunk while sending to client, client: 172.19.0.1, server: _, request: "GET /ip HTTP/1.1", upstream: "http://18.235.124.214:80/ip", host: "127.0.0.1:9080"
2021/07/09 03:37:03 [error] 45#45: *1029911 failed to run log_by_lua*: /usr/local/apisix//deps/share/lua/5.1/skywalking/span.lua:190: attempt to index field 'owner' (a nil value)
stack traceback:
        /usr/local/apisix//deps/share/lua/5.1/skywalking/span.lua:190: in function 'finish'
        /usr/local/apisix//deps/share/lua/5.1/skywalking/tracer.lua:108: in function 'prepareForReport'
        /usr/local/apisix/apisix/plugins/skywalking.lua:104: in function 'phase_func'
        /usr/local/apisix/apisix/plugin.lua:689: in function 'run_plugin'
        /usr/local/apisix/apisix/init.lua:530: in function 'common_phase'
        /usr/local/apisix/apisix/init.lua:639: in function 'http_log_phase'
        log_by_lua(nginx.conf:268):2: in main chunk while logging request, client: 172.19.0.1, server: _, request: "GET /ip HTTP/1.1", upstream: "http://18.235.124.214:80/ip", host: "127.0.0.1:9080"

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions