Skip to content

fix(datadog): preserve service_id fallback when service has no name - #14001

Open
bhuvan-somisetty wants to merge 1 commit into
apache:masterfrom
bhuvan-somisetty:fix/datadog-service-name-fallback
Open

bhuvan-somisetty wants to merge 1 commit into
apache:masterfrom
bhuvan-somisetty:fix/datadog-service-name-fallback

Conversation

@bhuvan-somisetty

Copy link
Copy Markdown

Description

In apisix/plugins/datadog.lua, when prefer_name is enabled (default true), the plugin attempts to replace entry.service_id with svc.value.name if available.

Previously, it checked if svc and svc.value.name ~= "" then. Because in Lua nil ~= "" evaluates to true, if a service did not have an optional name configured, svc.value.name was nil and overwrote entry.service_id with nil. This resulted in the service_name tag being completely dropped from emitted DogStatsD metrics instead of falling back to the service ID.

This change verifies that svc.value.name is truthy before assigning, preserving the service ID fallback as intended, and adds unit test coverage.

Which issue(s) this PR fixes:

Fixes #14000

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

When prefer_name is enabled (the default), datadog checked
`if svc and svc.value.name ~= ""`. Because in Lua `nil ~= ""` evaluates
to true, when a service was configured without an optional `name` field,
`svc.value.name` was nil and overwrote `entry.service_id` with nil.
This caused the `service_name` tag to be omitted entirely from emitted
DogStatsD metrics.

Check `svc.value.name` for truthiness before assigning, ensuring the tag
falls back to the service ID as intended.

Fixes apache#14000

Signed-off-by: bhuvan-somisetty <somisettybhuvan5@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: datadog plugin drops service_name tag when service has no name configured

1 participant