Skip to content

fix(telemetry): report lost records once on stderr when the run drains - #439

Merged
priyasingh2111 merged 4 commits into
mainfrom
feature/telemetry-drain-loss-warning
Nov 13, 2026
Merged

priyasingh2111 merged 4 commits into
mainfrom
feature/telemetry-drain-loss-warning

Conversation

@priyasingh2111

@priyasingh2111 priyasingh2111 commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Human readable section

Problem: When Box could not deliver telemetry to a configured target, it lost the records and said nothing. That happened both during the run and at exit. A workload could use this to hide its own last actions: fill the disk under the file target, or make an OTLP target hang, then act and exit. The records were gone, and the run still exited 0. The design decision on telemetry delivery already says the collector prints to stderr when delivery fails, but the code did not.

Solution: When the run ends, Box prints one warning on stderr if an export to a configured target failed, or if the final export did not finish in time. The warning says which of these happened. The exit code does not change.

Trade-off: The warning comes once, at the end of the run, not at each failure. A workload cannot flood stderr that way, but the operator learns of the loss only when the run ends. The warning does not prove that nothing was lost when it is absent: records the telemetry queue refuses, agent payloads Box refuses, and relays in flight at shutdown are still not counted.

Description

Example line:

strands-box: warning: telemetry records were lost: 2 exports to the configured targets failed

Decisions this depends on

  • One line at the drain, not in deliver. This is the scope maintainers accepted in triage: one stderr line at the drain, no retry, no gap-marker record, and no non-zero exit. A non-zero exit would let a workload fail the run by breaking an audit sink it can reach.
  • The receiver gets its own counter. It shared dropped with the exporters, so a refused agent payload (the one-permit relay bound, or the fan-out bound) counted as a lost record. The workload could then raise the warning at will. Now dropped counts only batches an exporter failed to deliver.
  • An unfinished drain is its own cause. It no longer increments dropped, and the line names it ("the final export did not finish in time") instead of calling it a failed export. A final export that fails at once (a closed port, a full disk) makes the SDK return an error, not a timeout, so shut_down_bounded returns a typed outcome, and only a drain that got no answer, or a lane whose own shutdown did not finish, reads as "did not finish". A lane's shutdown did not finish when the SDK cut its final export at the deadline, or when the shutdown failed without a counted export failure from that shutdown (for example, a full queue refused the shutdown message, so nothing was exported). Each lane sets the flag itself, because the SDK joins every lane's error into one, so a lane that fails fast cannot hide a lane that did not finish.
  • No interface change. Collector::drained keeps its signature, the crate facade does not change, and the line carries a count and fixed text only, with no destination or secret.

Docs in this PR: docs/user/telemetry.md (errors section), docs/design/telemetry.md (limits), and the telemetry crate's AGENTS.md. decisions.md#delivery-is-best-effort already says the collector prints to stderr, and is now closer to true. A wording update there to "prints one line at the drain" is optional and left out.

Checks CI cannot perform: a live Strands SDK agent run was not done.

Related Issues

None.

Type of Change

Bug fix

Testing

  • an_unreachable_target_reports_the_lost_records_once (box_telemetry): an OTLP target on a closed port gives exactly one loss line, and the run still succeeds. It fails when the eprintln! is removed.

  • a_declared_file_target_is_where_the_records_go now also asserts that a healthy target prints no loss line.

  • a_lossy_drain_reports_the_loss_once, a_complete_drain_reports_no_loss and an_unfinished_drain_alone_is_a_loss pin the text and each cause.

  • a_counted_export_failure_is_not_reported_as_a_timeout and a_fast_failing_final_export_is_not_a_timeout pin that a final export that fails at once is reported as a failed export and not as "did not finish in time". The box test also asserts this. All three fail with the first version's mapping. a_cut_lane_is_reported_beside_a_failing_lane pins a cut lane (a file target on a full pipe) beside a lane that fails fast (OTLP on a closed port), and fails without the per-lane flag. a_shutdown_the_worker_never_receives_is_not_finished pins a shutdown that a full queue refuses (4000 records behind a listener that never accepts), and fails when only a timeout sets the flag.

  • a_refused_agent_payload_is_not_a_lost_record pins that a payload the receiver refuses raises the receiver's own count and leaves dropped at 0.

  • At 9aa7838, rebased onto main: cargo test --workspace --all-features: 5207 passed, 0 failed, 19 ignored. cargo test -p strands-box-telemetry --all-features: 92 passed. cargo test -p strands-box --all-features --test box_telemetry: 26 passed, 1 ignored. site_manifest: 27 passed. fmt is clean, clippy reports no owned warnings, and Cargo.lock still holds one reqwest.

  • feature-critic ran on the diff. Its findings (the shared counter, the missing print pin, the doc-comment placement, and the wording) are fixed in this commit. It ran again on the per-lane fix: no blocker, and its three minor findings (a timing-dependent pipe fill, a comment, and an uncounted cut during an ordinary export now listed in the docs) are fixed. A third run, on the shutdown fix, found no blocker, and its three minor findings (an export in flight could answer for the shutdown, two stale doc comments, and a test that depends on the SDK queue defaults) are fixed.

  • Linux (Ubuntu, kernel 7.3, arm64, in a Lima VM), at the first commit (0135c52 before the rebase onto main, now 975ef51): the workspace build passes. cargo test -p strands-box-telemetry --all-features: 87 passed. cargo test -p strands-box --all-features --test box_telemetry: 26 passed, 1 ignored, including an_unreachable_target_reports_the_lost_records_once. just clippy passes, and fmt is clean.

  • I ran the relevant suites (just check, or cargo test --workspace --all-features): cargo test --workspace --all-features passed, 5207 passed, 0 failed, 19 ignored

  • If I touched Rust, I ran cargo fmt --all and cargo clippy --workspace --all-targets --all-features -- -D warnings: fmt is clean. The plain -D warnings form stops on 9 lints that already exist in the vendored crates/shell, which this PR does not touch. The just clippy recipe passes the whole workspace.

Checklist

  • I have read the CONTRIBUTING document
  • I have reviewed and understand every line of code in this PR, including any generated by AI tools, and I can explain why it works
  • My change is focused and reasonably small; I have split unrelated work into separate PRs
  • I have added any necessary tests that prove my fix is effective or my feature works
  • I have updated the documentation accordingly
  • My changes generate no new warnings

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@github-actions github-actions Bot added bug Something isn't working Area - Telemetry The telemetry collector, receiver, and record targets labels Nov 12, 2026
@priyasingh2111
priyasingh2111 marked this pull request as ready for review November 12, 2026 23:57
Comment thread crates/telemetry/src/collector.rs Resolved
Comment thread crates/telemetry/src/collector.rs Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Request Changes

The single drain-time line, with no change to the exit code, fits the agreed triage scope. But the way the drain sorts its causes reports any failed final export as a timeout. That includes the PR's own unreachable-target scenario, and the tests do not catch it (see inline).

Checks that held
  • When the run ends, each loss cause produces exactly one stderr line, and the exit code stays the same.
  • The line carries a count and fixed text only, with no destination or secret.
  • Refusals by the receiver (relay bound, fan-out bound) no longer feed dropped. Failed agent relays to a target still count, which is correct, because those records were lost.
  • drained is reached on every run exit path (command/run.rs). The shut guard keeps the line from printing twice.
  • No frozen surface in the root AGENTS.md list changes, and Collector::drained and the facade are untouched.
  • The user, design and telemetry AGENTS.md docs describe the limits that remain (queue-full drops, relays in flight).

Splitting the counter and stating plainly what the line does not prove are both good calls.

Comment thread crates/telemetry/src/collector.rs Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Comment

b7bfee2 fixes both earlier findings. One narrower gap remains: deciding whether the drain finished from the provider-wide counter misses a cut in one lane when another lane is also failing (inline on drain_finished). It needs two targets, one of them stalled, so it isn't blocking, but the fix per lane is small.

Checks that held
  • A single target whose final export fails fast (closed-port OTLP, full disk) prints only the failed-export cause. The unit test and the box test both pin this.
  • A single lane cut at EXPORT_DEADLINE, and a worker that never answers, both still report "did not finish in time". I checked the first with a stalled FIFO.
  • Refusals by the receiver are counted separately (refused()) and leave dropped at 0.
  • The earlier checks still hold: one stderr line, exit code unchanged, no destination or secret in the line, no change to a frozen surface.

## Problem

When a telemetry target failed, the collector counted the failed batch and printed nothing. When
the exit flush did not finish in time, the collector also counted it and printed nothing. So a
workload that filled the disk under a file target, or made an OTLP target hang, removed the records
of its own last actions with no signal, and the run still exited 0. The decision "Delivery is best
effort" (docs/design/decisions.md#delivery-is-best-effort) says that the collector prints to stderr
when delivery fails, but the code did not.

The receiver shared the same counter. So a refused agent payload (the one-permit relay bound, or the
fan-out bound) counted as a lost record, and the workload could raise any loss signal at will.

## Solution

`Collector::drained` now prints one stderr line when an export to a configured target failed, or
when the final export did not finish in time. The line names its cause:

    strands-box: warning: telemetry records were lost: 2 exports to the configured targets failed

The line is printed once, at the drain, and not in `deliver`, so a workload that makes every batch
fail cannot fill stderr. It carries a count and fixed text only, and no destination or secret. The
exit code does not change, because a failed audit sink that the workload can break must not also
let the workload fail the run. Maintainers accepted this scope in triage: one stderr line at the
drain, no retry, no gap-marker record, and no non-zero exit.

The receiver now has its own counter, so `dropped` counts only batches an exporter failed to
deliver. An unfinished drain no longer increments `dropped`, because no export failed; the line
states that cause separately. `drained` keeps its signature, so the crate facade does not change.

The user page (docs/user/telemetry.md), the design page (docs/design/telemetry.md) and the crate
AGENTS.md now state the line and what it does not count: a record the SDK queue refuses, an agent
payload the receiver refuses, and a relay in flight at shutdown.

## Tests

- `box_telemetry.rs::an_unreachable_target_reports_the_lost_records_once`: an OTLP target on a
  closed port gives exactly one loss line, and the run still succeeds. With the `eprintln!` removed,
  this test fails.
- `box_telemetry.rs::a_declared_file_target_is_where_the_records_go` now also asserts that a target
  that took every record prints no loss line.
- `collector.rs::a_lossy_drain_reports_the_loss_once`, `a_complete_drain_reports_no_loss` and
  `an_unfinished_drain_alone_is_a_loss` pin the text and each cause.
- `cargo test -p strands-box-telemetry --all-features`: 87 passed. `cargo test -p strands-box
  --all-features --test box_telemetry`: 26 passed, 1 ignored. `site_manifest`: 27 passed. fmt is
  clean, clippy reports no owned warnings, and `Cargo.lock` holds one `reqwest`.

Not run: a Linux build (no cross-compiler on the macOS host), and a live Strands SDK agent run.
@priyasingh2111
priyasingh2111 force-pushed the feature/telemetry-drain-loss-warning branch from b7bfee2 to c28824a Compare November 13, 2026 02:46
Comment thread crates/telemetry/src/collector.rs Resolved
@github-actions

Copy link
Copy Markdown

Assessment: Comment

c28824a fixes the mixed-lane case from my last comment: a stalled lane next to a fast-failing lane now reports both causes, and a_cut_lane_is_reported_beside_a_failing_lane pins it. One problem is left (inline at line 166): limiting the per-lane flag to Timeout lets a shutdown that never reached the worker count as finished. That reporting worked at b7bfee2.

Checks that held
  • In SDK 0.33, OTelSdkError::Timeout comes only from export_with_timeout's deadline. deliver returns InternalFailure only, so a counted export is never taken for a cut.
  • A blackholed OTLP target is cut by REQUEST_DEADLINE (4s), before EXPORT_DEADLINE (5s), so it is counted as failed and not marked as cut.
  • Two stalled lanes take 5s + 5s, which reaches DRAIN_DEADLINE, so the result is Unanswered and the drain is reported unfinished.
  • The relay race from my last comment is gone, because cut no longer depends on dropped.
  • The user and design docs now list mid-run SDK cuts as uncounted. All 31 collector:: tests pass locally.

@github-actions

Copy link
Copy Markdown

Assessment: Approve (from the telemetry-drain side)

9aa7838 fixes the regression in my last comment, and I found nothing new in this commit. Each lane now decides "did not finish" for itself, before the SDK joins the lane errors. An error counts as a finished, failed export only when it is a failed export that the lane's own exporter started inside this shutdown.

Checks that held
  • A shutdown refused because the queue is full or the worker is gone, with nothing counted, is reported unfinished. The new test pins it and is stable over repeated runs.
  • A final export on a closed port is reported only as a failed export, not as a timeout.
  • A failure from an export that started before the shutdown does not mark the final export as failed, because of the shutdown count in LaneFailures.
  • A final export the SDK cuts at EXPORT_DEADLINE is still reported unfinished through the Timeout arm. That holds next to a lane that fails fast too.
  • The SDK's timeout is still the only source of Timeout, and deliver counts every error it returns.
  • The test skips itself when OTEL_BLRP_* would make the queue larger. All 32 collector:: tests pass locally.

@priyasingh2111
priyasingh2111 merged commit 70eb3af into main Nov 13, 2026
21 checks passed
@priyasingh2111
priyasingh2111 deleted the feature/telemetry-drain-loss-warning branch November 13, 2026 04:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area - Telemetry The telemetry collector, receiver, and record targets bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants