Update Statsd tag serializer to allow falsy values

Open Beginner friendly
#326 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
68/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
ruby

Research direction

Start with lib/datadog/statsd/serialization/tag_serializer.rb around lines 58-66, then read PR 290 for the full context. Verify the serializer preserves explicit false tag values while retaining the intended nil handling, and confirm the relevant serializer behavior with the existing test suite.

Written by the indexing model from the issue text.

Description

Please, see https://github.com/DataDog/dogstatsd-ruby/pull/290 for all details.

PR description at the time of opening this issue:

Problem

If we provide a tag which has a boolean value, we are unable to properly track the false case, since the "true" string appears with the tag name, but the "false" string does not show up. This is because of this logic, which checks for tag value presence:

https://github.com/DataDog/dogstatsd-ruby/blob/517b830c9b9103ff37c4b642bcfa5eff7c47353a/lib/datadog/statsd/serialization/tag_serializer.rb#L58-L66

true is evaluated to present, so we would add that tag name and value; however, false is evaluated to not present, so we would only add that tag name (not the value).

Solution

First, check for nil explicitly then also check for nil after converting to a string.

This does result in other values being deemed "present" now which were not previously though, such as [] and {}. Is this a problem though?

Dominant language
Ruby
Stars
208
Forks
138
PR merge metrics
No merged PRs in 30d

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DataDog/dogstatsd-ruby

All issues in DataDog/dogstatsd-ruby

Similar issues

More Ruby issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.