Add GET /telemetry/events to read archived telemetry from S2#285
Draft
archandatta wants to merge 10 commits into
Draft
Add GET /telemetry/events to read archived telemetry from S2#285archandatta wants to merge 10 commits into
archandatta wants to merge 10 commits into
Conversation
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
… limit Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
bb9b965 to
0f44c61
Compare
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Reading telemetry emitted its own api_call event back into the stream, a feedback loop that prevents a paginated read from catching the tail. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a paginated read path for browser telemetry archived in S2, so events stay available after they age out of the live SSE ring buffer (
GET /telemetry/stream).GET /telemetry/events— reads archived telemetry envelopes for the browser in ascending sequence order. Returns a top-level JSON array of envelopes plusX-Has-More/X-Next-Offsetpagination headers (matching theoffset_paginationconvention used by the list endpoints). Empty result serializes as[], nevernull.offsetis an S2 sequence cursor (pass the previous response'sX-Next-Offset);since/untilbound the time window;categoryfilters;limitis the page size (default 100, max 1000).has_moreis derived from the S2 read's next-position vs the stream tail, so it is correct whether a page stops on the count, byte, or time bound.events.S2Reader— one-shot, bounded S2 reader injected intoApiService; always terminates (caps at the tail when unbounded).S2_BATCHER_LINGER/S2_BATCHER_MAX_RECORDSenv vars wire into the existingS2Config(defaults unchanged: 100ms / 50).TelemetryEventCategorypromoted to a named schema component so thecategoryquery param can reference it (behavior-preserving; generated type byte-identical).api_callevents. The per-requestapi_callmiddleware was firing forReadTelemetryEvents/StreamTelemetryEvents, appending to the very stream being read — a feedback loop that, at page size 1, prevented a paginated read from ever catching the tail. Reads are now side-effect-free.Envelope/event schemas are unchanged. The response is encoded directly from
events.Envelope(matching the SSE stream and publish endpoints), so all telemetry endpoints emit an identical envelope shape.Consumers paginate via
X-Next-Offset(an S2 stream position) — not the envelope'sseqfield; the param/header docs call this out.This endpoint is harmless until a consumer calls it, so it can ship independently. A follow-up on the control-plane API will mirror it and wire Stainless
offset_paginationso the SDK auto-paginates.Test plan
buildReadOptions(offset-over-since precedence,Countmapping),pageSizeclamping,filterByCategory.server/e2e, real S2 viaKI_E2E_BACKEND=docker): round-trip, category filter, empty-window[], multi-page cursor walk (ascending, no gaps/dupes), and a read-is-side-effect-free assertion. Auto-skips withoutS2_BASIN/S2_ACCESS_TOKEN/S2_STREAM.go build,go vet, package tests green;make oapi-generateoutput committed.Live runs
Ran against a real S2 stream (freshly built headless image,
KI_E2E_BACKEND=docker):Also exercised by hand over HTTP at scale — published ~1000 events and paged the full stream at
limit=50:And confirmed
limit=1terminates cleanly (the feedback-loop fix), which it would not have before.🤖 Generated with Claude Code