Skip to content

A value that is not a number is sent as-is, or loses the whole event #37

Closed

Description

@dmccoystephenson

TraceClient.report(name, value, tags) documents value as "an optional numeric value", and the README's wire-format section says value is omitted only when not given or when it is NaN or infinite. _json in trace_client/trace_client.py does not check the type of value, though, so anything that is not a plain int/float goes straight to json.dumps:

value passed What is sent / happens
"3" (e.g. read from a settings file) {"...","value":"3"} -- a JSON string where the server expects a number
True {"...","value":true}
decimal.Decimal("1"), a numpy int64 json.dumps raises TypeError; report() catches it and logs could not queue, so the whole event is lost, not just the value

Reproduced with:

from trace_client.trace_client import _json
_json("a", "n", "3", None)   # b'{"application":"a","name":"n","value":"3"}'
_json("a", "n", True, None)  # b'{"application":"a","name":"n","value":true}'
from decimal import Decimal
_json("a", "n", Decimal("1"), None)  # TypeError

trace-client-java cannot send any of these, because its value is typed Double. So on these inputs the Python client sends something the Java client never would.

Suggested fix: treat value the way NaN and infinity are already treated. Send any real number (numbers.Real, excluding bool) as a JSON number, convert it with float() when it is not a plain int/float, and leave every other value out of the event while still sending the event itself. Update the report docstring and the README wire-format sentence to match.

This issue was drafted during a Gardener session (https://github.com/Stephenson-Software/gardener).


drafted by Claude on behalf of Daniel Stephenson

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions