Debug and automate

Capture a curl trace

Record protocol bytes and timing details when verbose output does not explain a transfer failure.

10 minute lesson

~~~

Verbose mode shows headers and events. Sometimes that’s not enough: a transfer dies mid-body, a server misbehaves on specific bytes, or you need to hand a complete record to someone else. A curl trace contains more detail than verbose mode, including data exchanged by the transfer. It is useful for a small, controlled reproduction.

Record a trace

Capture an ASCII trace with timestamps:

curl --trace-ascii trace.txt --trace-time https://example.org/ -o /dev/null

Nothing extra appears on screen. The record lands in trace.txt:

17:20:31.234567 == Info: Connected to example.org (104.20.26.136) port 443
17:20:31.301234 => Send header, 76 bytes (0x4c)
0000: GET / HTTP/2
000e: Host: example.org
...
17:20:31.398765 <= Recv header, 13 bytes (0xd)
0000: HTTP/2 200
17:20:31.401122 <= Recv data, 1256 bytes (0x4e8)

Open the trace and follow connection setup, headers, and data. The direction markers do the navigation: => is data curl sent, <= is data received, == Info lines are curl’s own commentary. Every block shows its byte count, and --trace-time stamps each line so you can see exactly where time went.

That combination answers questions verbose mode can’t. A transfer that hangs shows a timestamp gap at the precise byte where it stalled. A response cut short shows fewer received bytes than the headers promised.

--trace-ascii keeps the output readable by replacing non-printable bytes. When the exact byte values matter, like debugging a compressed or binary response, use --trace trace.bin instead to get a full hex dump.

Make the trace worth keeping

A trace is a reproduction artifact, so preserve its context. Keep the file with the exact command and curl version:

curl --version > repro-notes.txt
echo 'curl --trace-ascii trace.txt --trace-time https://example.org/ -o /dev/null' >> repro-notes.txt

Whoever picks this up later, including future you, can rerun the same transfer and compare traces line by line.

One serious caution: a trace records everything, by design. Trace files can contain credentials, cookies, URLs, and bodies. Use disposable data and sanitize before sharing. A trace made with a real session cookie is a working credential sitting in a text file.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →