Skip to content

Fix traces unmarshal error on fractional mem_delta - #21

Merged
quinnmil merged 3 commits into
mainfrom
19-traces-mem-delta
Sep 10, 2026
Merged

quinnmil merged 3 commits into
mainfrom
19-traces-mem-delta

Conversation

@quinnmil

@quinnmil quinnmil commented Sep 9, 2026

Copy link
Copy Markdown
Contributor

Closes #19

Summary

scout traces list and scout traces show failed for any app whose traces carry a memory delta:

Error: json: cannot unmarshal number 2.9296875 into Go struct field TraceEntry.traces.mem_delta of type int64

The API reports mem_delta as a float in megabytes (0.0, 2.9296875, null, …), matching the requests.mem_delta float column and the Scout UI's "N MB" rendering. The CLI declared it as int64 bytes, so decoding failed on the first fractional value and, when it didn't fail, FormatBytes would have shown "2 B" for a 2 MB increase.

Changes

  • TraceEntry.MemDelta and TraceDetail.MemDelta are now float64 (MB).
  • New output.FormatMB helper renders 2.9 MB, 12 MB, 1.5 GB; used by the traces table and the span-tree footer (Memory: +2.9 MB).
  • Adjacent unit fix (second commit): the traces table Duration column used FormatSeconds on total_call_time, but the API reports it in milliseconds (the UI renders it with an ms suffix; Request#total_call_time_in_seconds converts from ms). An 83-second request displayed as 83483.9s; it now shows 83.5s. The legacy-trace fallback in the span-tree header had the same *1000 error.
  • Regression tests with API-shaped payloads: float, 0.0, null, and integer mem_delta for both list and detail; FormatMB table test; span-tree footer and legacy header tests.
  • CHANGELOG ## Pending### Fixed entries.

Before / after (illustrative)

Before:

Error: json: cannot unmarshal number 2.9296875 into Go struct field TraceEntry.traces.mem_delta of type int64

After:

│ ID    │ Time   │ Duration │ Memory │ Endpoint               │ URI       │
│ 12345 │ 2d ago │ 83.5s    │ 2.9 MB │ Controller/users/index │ /users/42 │
│ 12346 │ 1d ago │ 61.7s    │ 0 MB   │ Controller/users/index │ /users/7  │
Trace #12345 — Controller/users/index — 83.5s
 Memory: +2.9 MB    Allocations: 15,467    Host: web-1    SHA: abc1234

Note for the reporter: the second error in the issue (invalid character 'N' looking for beginning of value when passing a raw endpoint name) was addressed in 0.4.0, which now surfaces the HTTP status and body instead. The Base64 endpoint id from the URL is the correct input.

Test plan

  • go test -race ./...
  • golangci-lint run ./...
  • Live: scout traces list --endpoint <id> --app <id> --from 6d (table, --json, --toon)
  • Live: scout traces show <trace-id> --app <id>

🤖 Generated with Claude Code

https://claude.ai/code/session_01BK3fzED9ksTWsvoPfsEwpS

quinnmil and others added 2 commits September 9, 2026 15:21
The Scout API reports a trace's mem_delta as a float in megabytes
(e.g. 0.0, 2.9296875), but TraceEntry and TraceDetail declared it as
int64, so `scout traces list` and `scout traces show` failed with:

  json: cannot unmarshal number 2.9296875 into Go struct field
  TraceEntry.traces.mem_delta of type int64

Decode mem_delta as float64 and format it as MB (matching the Scout UI)
via a new output.FormatMB helper, instead of treating it as a byte count.
Adds regression tests using live-shaped payloads (float, 0.0, null and
integer mem_delta values).

Closes #19

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BK3fzED9ksTWsvoPfsEwpS
The API reports total_call_time in milliseconds (the Scout UI renders it
with an "ms" suffix and Request#total_call_time_in_seconds converts from
ms). `scout traces list` formatted it as seconds, so an 83-second request
displayed as "83483.9s". Use FormatMs for the Duration column and drop
the extra *1000 in the legacy-trace fallback of the span tree header.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BK3fzED9ksTWsvoPfsEwpS
Replace trace ids, URIs and endpoint names copied from live output with
generic placeholders.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BK3fzED9ksTWsvoPfsEwpS
@quinnmil
quinnmil merged commit ff255ce into main Sep 10, 2026
2 checks passed
@quinnmil
quinnmil deleted the 19-traces-mem-delta branch September 10, 2026 21:02
This was referenced Sep 10, 2026
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.

Unmarshal error when trying to list traces

2 participants