Skip to content

Modernize SDK to v1.1.0 (reliability, client API, transport, tooling) - #29

Merged
melekr merged 39 commits into
masterfrom
improvements/sdk-modernization
Nov 26, 2026
Merged

melekr merged 39 commits into
masterfrom
improvements/sdk-modernization

Conversation

@melekr

@melekr melekr commented Aug 4, 2026 •

Copy link
Copy Markdown
Contributor

Modernize backtrace-go (v1.1.0)

This brings the SDK up to a production-ready state. It fixes long-standing reliability bugs, adds the features expected from a modern error-reporting SDK and rebuilds the tooling around it.

Fixes

  • Contains Improvements/prod hardening #30

  • Submissions had no HTTP timeout : an unreachable endpoint hung the sender and eventually blocked every Report() call.
    There's now a real transport (30s timeout, status/429 handling) behind a bounded queue that drops and counts instead of blocking.

  • About half of all panic reports were lost to a channel race. Panics are now flushed deterministically before re-panicking, and retry a full queue instead of being dropped.

  • FinishSendingReports killed the sender permanently and deadlocked on a second call. Replaced by Flush(timeout)/Close, kept as an alias.

  • Data races on the global Options/attributes map, report UUIDs, Windows stack paths split at the drive letter, parser panics on unusual frames, and a CI matrix that couldn't build (Go 1.18 vs go.mod 1.22).

New

  • Instance API: bt.NewClient(Config). The legacy global API still works unchanged, same wire format.
  • BeforeSend hook (fails closed: a panicking hook drops the report rather than sending it half-scrubbed), sampling, error-chain capture, and a bthttp middleware for net/http panic capture.
  • File attachments (multipart, 10 MiB/file cap) and breadcrumbs, delivered both as an annotation and as the bt-breadcrumbs-0 attachment the Backtrace UI reads.
  • Source context is now limited to lines around each frame instead of uploading whole files (ContextLineCount was dead code before).
  • Richer default attributes: build/VCS info, runtime stats, module list, env vars with secrets redacted.

updates : (review follow-up)

  • Values are normalised into a detached, bounded model on the caller's goroutine (freeze.go). BeforeSend has a written contract: model types, its own copy, removals stick.
  • Redirects are refused for reports and snapshots; the SDK's client owns its connection pool; attached files come before the inline breadcrumb part.
  • bthttp: the response writer keeps Flusher/Hijacker behind Unwrap and tracks http.ResponseController calls.
  • Tracer: callback and upload-client panics become ErrTracerCallback; Recover keeps the application's panic and PanicOnKillFailure.
  • SourceRoots confined with os.Root; limits have ceilings; EnvVars allowlist.

updates: (23-11-2026)

  • CI: lint on linux, darwin, windows and freebsd; test Go 1.27.
  • Reports: attribute values converted to what the backend stores, long error.message capped, oversized reports trimmed, ReportData.Error for BeforeSend.
  • Capture: regular files only (no FIFO hangs), secret query values redacted, heap and GC stats from runtime/metrics.
  • Client: request scopes, ReportContext, ReportPanic, ReportAndRecoverPanic, SetDefaultClient. ReportPanicValueAndFlush now takes a context (breaking, see MIGRATION.md).
  • Delivery: gzip, retries with backoff, panic reports first, ReportsPerMinute, pause after repeated network failures.
  • MonitorCrashes: reports crashes recover can't catch.
  • bthttp: per-request scopes, ReportStatus, SetRoute, NewTransport.
  • btslog: log/slog handler.
  • bcd: signal traces named by signal and uploaded before the resend; tracer stub outside Linux and FreeBSD.
  • Docs: MIGRATION.md, README sections, MIT LICENSE.

ref: BT-7421, BT-8145, BT-8154

@melekr melekr self-assigned this Aug 4, 2026
melekr added 5 commits August 4, 2026 11:48
…p, bt-breadcrumbs

- A panicking BeforeSend hook now drops the report instead of sending it half scrubbed. The drop is counted in DroppedReports
- Attachment 10 MiB cap enforced at read time.
- Breadcrumbs also sent as the bt-breadcrumbs-0 attachment the Backtrace UI reads: scrubbing the annotation in BeforeSend suppresses it
- Token redacted in 2-segment submit.backtrace.io paths and in transport errors (*url.Error embeds the full URL)
- Tests: multipart test server, panic-report queue-full retry, Flush retry after full queue, attachment collision cases
Trailing-slash endpoints no longer produce "//post" : an endpoint carrying a query string together with Token is rejected at NewClient (previously produced a malformed submission URL and silently dropped every report).
wmic is removed from Windows 11 24H2 / Server 2025. Shared reg-output parser for the GUID and CPU probes, with unit tests.
@melekr

melekr commented Aug 4, 2026

Copy link
Copy Markdown
Contributor Author
  • Add a LICENSE file [ ]

- Trace() fails gracefully when a stub tracer (macOS) returns no command instead of crashing the process in the exec goroutine
- Env-var redaction broadened (PASS/KEY/DSN/COOKIE/SESSION/SIGNATURE/ BEARER/CONN) plus value shape detection of URL-embedded credentials
- Retry-After capped at 5 minutes; token redaction extended to aliased submit-shaped URLs and NewClient error messages
- All Client methods are safe no-ops on a nil receiver, as documented
melekr and others added 6 commits August 7, 2026 17:15
panic containment, bounded lifecycle, privacy budgets
An error-reporting SDK must never become the incident. 

After this change the SDK cannot crash, hang, or leak from the host
application: every path that executes application code is
panic-contained (including re-entrant loggers and typed-nil errors),
every wait is bounded and cancellable, every payload component has a
byte budget, and no credential can reach a log, error string, or report
annotation.
@melekr
melekr requested a review from KishanPRao August 17, 2026 16:28
melekr and others added 13 commits August 17, 2026 13:02
## Summary
Upgrades all actions in `tests.yml` to their latest releases and pins
each to a full commit SHA. All three now run on Node 24, which removes
the Node 20 deprecation warnings.

| Action | Before | After |
|---|---|---|
| `actions/checkout` | `v4` | `v7.0.1` (`3d3c42e`) |
| `actions/setup-go` | `v5` | `v7.0.0` (`b7ad1da`) |
| `golangci/golangci-lint-action` | `v8` | `v9.3.0` (`ba0d7d2`) |

## Notes
- Pinning to SHAs protects against a tag being moved to different code.
The `# vX.Y.Z` comments keep versions readable and work with
Dependabot/Renovate.
Add the value normaliser that the following commits wire into the client. It turns whatever the application passes as an attribute or breadcrumb value into a detached graph of nil, bool, string, int64, uint64, float64, []interface{} and map[string]interface{}, on the caller’s goroutine.

Conversion follows encoding/json: time.Time, json.Marshaler,encoding.TextMarshaler, error values and structs keep a useful form.Every user method runs behind panic containment.
Depth, value count and bytes are enforced while walking: an oversizedslice, map or byte slice stops being visited and ends in one marker.
copyModel gives a report its own copy of shared values.
Unit tests, and FuzzFreezeValue added to the CI fuzz list.
…nline parts

- Never follow a redirect: a 307/308 would replay the report to another
  host. A caller-supplied http.Client is copied, not mutated, and its
  idle connections are never closed.
- The SDK's own client uses a clone of http.DefaultTransport, so closing
  its idle connections at shutdown leaves the application's alone.
- Attached files are admitted before the inline breadcrumb part, which
  shares the attachment budgets and keeps its name when a file has the
  same one.
- Diagnostics name attachments by file name, and error text from a
  caller-supplied client is formatted behind panic containment.
…ounting

- Values passed to Report, SetAttribute(s), AddBreadcrumb and
  Config.Attributes are normalised when the call returns, so a queued
  report never shares a map or slice with the caller. The package-level
  SetAttribute(s) normalise at store time.
- BeforeSend: the hook sees value-model types, edits its own copy of the
  report, and its removals stick. Only the report id is restored; what
  the submission format requires is repaired.
- Config: explicit limits have ceilings, a negative MaxErrorDepth still
  disables chain capture, and the hosted endpoint forms are validated.
- Environment capture: EnvVars allowlist, MaxEnvVars and MaxEnvBytes.
- A forced shutdown skips queued work (new Shutdown drop reason), and a
  report on a closed client is rejected before any capture.
- macOS: ioreg by absolute path with capped output.
- A panic in a Tracer method, or in the HTTP client used for snapshot
  uploads (Trace, Put, PutDir), becomes an error wrapping the new
  ErrTracerCallback. A nil or typed-nil tracer is rejected with an
  ordinary error.
- Recover never lets a tracer failure replace the application's panic.
  PanicOnKillFailure is still honoured by Trace, and by Recover when it
  does not re-panic.
- The trace lock is released before any logging.
- Snapshot uploads never follow a redirect; diagnostics name snapshots
  by file name.
- Source files are opened through os.Root handles, so a symbolic link or
  ".." that leaves a configured root is refused at open time. Roots that
  cannot be opened fail closed.
- A root and a stack frame may name the same directory through different
  symbolic links (/tmp and /private/tmp); both forms are matched.
- The writer handed to handlers offers Flusher and Hijacker when the
  wrapped writer, or one behind its Unwrap, supports them, and Pusher and
  ReaderFrom when the wrapped writer has them itself. CloseNotifier is
  never offered.
- Flushes and hijacks are tracked, including those made through
  http.ResponseController: a swallowed panic never appends a 500 to a
  started response or writes to a hijacked connection.
@melekr
melekr marked this pull request as ready for review November 26, 2026 19:00
@melekr
melekr merged commit c5b7620 into master Nov 26, 2026
21 checks passed
@melekr
melekr deleted the improvements/sdk-modernization branch November 26, 2026 19:01
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.

3 participants