bug: datadog plugin drops service_name tag when service has no name configured
Maintainers usually reply within 2 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 85/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- lua
- Domain
- backend, observability
Research direction
Start in apisix/plugins/datadog.lua at the prefer_name service-name resolution shown in the issue. Check how a service with no configured name is handled, then run or add a focused test for the Datadog plugin with prefer_name enabled and a nameless service. Done when the emitted metric tags retain service_name:s1 rather than omitting the tag.
Written by the indexing model from the issue text.
Description
Current Behavior
In apisix/plugins/datadog.lua, when prefer_name is enabled (default is true), the plugin attempts to resolve the service name:
-- if prefer_name is set, fetch the service/route name. If the name is nil, fall back to id.
if conf.prefer_name then
if entry.service_id and entry.service_id ~= "" then
local svc = service_fetch(entry.service_id)
if svc and svc.value.name ~= "" then
entry.service_id = svc.value.name
end
end
...
In Lua, nil ~= "" evaluates to true. When a service exists in APISIX but has no name property set (the name field in Service schema is optional), svc.value.name is nil.
Because nil ~= "" is true, the condition if svc and svc.value.name ~= "" evaluates to true, and entry.service_id is assigned svc.value.name (nil), overwriting the valid service ID.
Consequently, when generate_tag() builds the metric tags:
local variable_tags = {
...
{"service_name", entry.service_id},
...
}
entry.service_id is nil, so the service_name tag is completely omitted from the emitted DogStatsD metric datagrams instead of falling back to the service ID as intended.
Expected Behavior
When a Service does not have a name configured (svc.value.name == nil), entry.service_id should remain set to the service's ID, and service_name:<id> should be emitted in Datadog metrics tags.
Error Logs
No error logs are printed because Lua executes the assignment silently. However, inspecting the emitted UDP DogStatsD datagrams reveals that service_name is missing from the tags list whenever the associated service lacks an explicit name.
Steps to Reproduce
- Create an upstream and a service without specifying a
name:curl -i http://127.0.0.1:9180/apisix/admin/services/s1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' { "upstream": { "type": "roundrobin", "nodes": {"127.0.0.1:1980": 1} } }' - Create a route referencing service
s1withdatadogplugin enabled (prefer_name: trueby default):curl -i http://127.0.0.1:9180/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' { "uri": "/hello", "service_id": "s1", "plugins": { "datadog": {} } }' - Send a request to
/hello. - Observe the DogStatsD UDP packets received at port 8125: the tags contain
route_name:1,path:..., butservice_name:s1is completely absent becauseentry.service_idwas overwritten withnil.
Environment
- APISIX version (run
apisix version): 3.19.0 (master @ c6b2adc3) - Operating system (run
uname -a): Linux / POSIX - OpenResty / Nginx version (run
openresty -Vornginx -V): OpenResty 1.25+ - etcd version, if relevant: N/A
- APISIX Dashboard version, if relevant: N/A
- Plugin runner version, for issues related to plugin runners: N/A
- LuaRocks version, for installation issues: N/A
- Dominant language
- Lua
- Stars
- 17.2k
- Forks
- 3k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 37
Getting set up
Starts the project's dev container in your browser, under your own GitHub account.
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apache/apisix
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
Maintainers usually reply within 2 days
-
bug: syslog plugin crashes with nil-index error instead of returning an error when logger init failsOpen
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
apache/apisix#13944 · 3 comments ·
Maintainers usually reply within 2 days
-
doc good first issue
Difficulty 1/5 1-3 hours Newbie friendliness 76/100
apache/apisix#13395 · 2 comments ·
Maintainers usually reply within 2 days
Similar issues
-
Zenmap
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 5 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
-
revisit-at-release statusline
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
neovim/neovim#42188 · 1 comment ·
Maintainers usually reply within 1 day
-
[Aska] IssueOpen
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
pterodactyl/game-eggs#640 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day