Skip to content

Leave out a value that is not a number, rather than sending it or losing the event - #38

Merged
dmccoystephenson merged 3 commits into
mainfrom
trace/non-numeric-value
Nov 11, 2026
Merged

dmccoystephenson merged 3 commits into
mainfrom
trace/non-numeric-value

Conversation

@dmccoystephenson

Copy link
Copy Markdown
Member

Summary

  • _json now runs value through a new private _number helper. A real number (numbers.Real or decimal.Decimal, excluding bool) is sent as a JSON number, converted with float() when it is not a plain int/float. NaN, infinity, anything float() overflows or refuses, and everything else (strings such as "3", bools, bytes, lists) is left out of the event, and the event itself is still sent.
  • Previously "3" was sent as "value":"3" and True as "value":true. A Decimal or numpy integer made json.dumps raise, so the whole event was lost with only a DEBUG could not queue line.
  • The report docstring and the README "The wire format" paragraph are updated to describe what happens to such values.

Closes #37

Test plan

  • python3 -m unittest on Python 3.8.10 locally: Ran 76 tests, OK
  • Stash-and-run: with the trace_client/trace_client.py change stashed, the three new tests fail (test_json_leaves_out_a_value_that_is_not_a_real_number_but_keeps_the_event, test_json_sends_other_real_numbers_as_floats, test_report_with_a_decimal_value_still_delivers_the_event). With the change restored, all 76 tests pass.
  • CI test (3.8), test (3.10), test (3.12) green

Java parity

No Java-visible behavior changed. trace-client-java types value as Double, so it cannot send a string, a boolean or a non-float number. This change makes the Python client's output on those inputs match what the Java client would send. Endpoint, headers and JSON field names are unchanged.

Skipped issues

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

🤖 Generated with Claude Code


drafted by Claude on behalf of Daniel Stephenson

dmccoystephenson and others added 3 commits November 10, 2026 19:55
…ing the event (#37)

A string or bool value went to the server as a JSON string or boolean, and a
Decimal or numpy integer made json.dumps raise, which dropped the whole event.
Real numbers are now sent as floats; anything else is left out like NaN, and
the event still goes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…other imports

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@dmccoystephenson

Copy link
Copy Markdown
Member Author

Self-review rubric (scored against the diff and command output, assuming FAIL until shown otherwise):

  • Scope: PASS. Three files changed (trace_client/trace_client.py, tests/test_trace_client.py, README.md), each needed for A value that is not a number is sent as-is, or loses the whole event #37. 58 insertions and 7 deletions, of which about 25 lines are non-test code.
  • Tests-new: PASS. The new private helper _number is covered by test_json_leaves_out_a_value_that_is_not_a_real_number_but_keeps_the_event and test_json_sends_other_real_numbers_as_floats, and the end-to-end path by test_report_with_a_decimal_value_still_delivers_the_event. No public name was added.
  • Tests-fix: PASS. Stash-and-run was performed on Python 3.8.10. With the trace_client/trace_client.py change stashed: 2 failures and 1 error, exactly the three new tests. Restored: Ran 76 tests, OK.
  • Sibling structure / Sibling renames: PASS. No new files and no renames.
  • Docs: PASS. The README "The wire format" paragraph and the report docstring now describe the new omission rule. The class docstring and the README promises table make no claim about value types.
  • Issue resolution: PASS. All three cases listed in A value that is not a number is sent as-is, or loses the whole event #37 (string, bool, Decimal) are handled and asserted.
  • CI: PASS. test (3.8), test (3.10) and test (3.12) are green on the head commit.
  • Stdlib-only: PASS. The new imports are decimal, numbers and fractions (tests only). pyproject.toml is untouched.
  • Py3.8 floor: PASS. test (3.8) is green, and the local run was on 3.8.10.
  • Never-raises / never-blocks: PASS. _number catches OverflowError and ValueError from float() (covered by Fraction(10**400) and Decimal("sNaN")). It runs inside report()'s existing try, and no blocking call was added.
  • Log level: PASS. No _LOG calls were added.
  • Version agreement: PASS. 0.4.2 appears in all five places, and the version was not bumped.
  • Exports: PASS (N/A). _number is private.
  • Java parity noted: PASS. The PR body explains that trace-client-java's Double-typed value cannot produce these inputs.

Judgment call that was flagged:

  • trace_client/trace_client.py _json: the do-not-auto-merge list covers wire-format changes in _json (endpoint, headers, JSON fields). This diff leaves the endpoint, headers and field names unchanged. It only stops values outside the documented format, such as a JSON string or boolean value, from going out, which brings the Python client's output into line with what trace-client-java can send. On that basis it is assessed as not matching the hold.
  • Two cleanups were found during review and fixed with mechanical commits: the README now names only types the tests exercise (Decimal, Fraction, not numpy) and is rewrapped to the file's width, and the test imports of decimal/fractions were moved to the top of the module.

Summary: a small fix with regression evidence, CI green on the full matrix, and the docs aligned.

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


drafted by Claude on behalf of Daniel Stephenson

@dmccoystephenson
dmccoystephenson merged commit 256171b into main Nov 11, 2026
3 checks passed
@dmccoystephenson
dmccoystephenson deleted the trace/non-numeric-value branch November 11, 2026 02:59
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.

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

1 participant