feat(telemetry): add wire-format module and export event reader#959
Open
EhabY wants to merge 3 commits into
Open
feat(telemetry): add wire-format module and export event reader#959EhabY wants to merge 3 commits into
EhabY wants to merge 3 commits into
Conversation
3c02990 to
350d662
Compare
6e2c3ad to
ca1bd07
Compare
917a7de to
03773cd
Compare
ca1bd07 to
c0e517d
Compare
…ugh types - Consolidate preset labels/details/filenames/durations into one PRESETS record so TELEMETRY_RANGE_PRESETS and createPresetDateRange stay in sync. - Derive TelemetryRangePresetId from PRESET_IDS; un-export parseUtcDate and utcDateString (used only internally). - Drop src/telemetry/export/types.ts; consumers import TelemetryEvent directly. JsonValue/JsonPrimitive are unused here and will be introduced by the OTLP writer branch where they're actually needed. - Flatten the nested ternary in errorMessage.
Extract `src/telemetry/wireFormat.ts` as the single source of truth for the on-disk JSONL shape. `SessionContext`, `TelemetryContext`, and `TelemetryEvent` are now `DeepReadonly<z.infer<...>>` derived from the schemas, removing the parallel hand-written interfaces and the satisfies drift checks. The sink and exporter both share `serializeTelemetryEvent` and `parseTelemetryEventLine`, so the format can't drift between writer and reader. Export-side cleanups in `files.ts` and `range.ts`: hide internal helpers, rename `segment`/`sessionSlug` to `part`/`session`, drop the next-day grace in `fileDateCanContainRangeEvent`, simplify presets, and replace the manual snake/camel mapping with a tiny generic rename. Tests for the parse boundary moved to `wireFormat.test.ts`; the remaining files tests focus on listing and streaming, now backed by memfs.
3788e9b to
d550ffd
Compare
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
src/telemetry/wireFormat.tsas the single source of truth for the on-disk JSONL telemetry shape.SessionContext,TelemetryContext, andTelemetryEventare nowDeepReadonly<z.infer<...>>derived from schemas, so the wire format and the TS types cannot drift.serializeTelemetryEventandparseTelemetryEventLineare shared by the sink (writer) and the exporter (reader); the sink's hand-rolled serializer is gone.listTelemetryFilesForRange(filename-date filtering, chronological order) andstreamTelemetryEvents(line-by-lineAsyncIterable<TelemetryEvent>withTelemetryFileParseErrorfor parse failures).range.tswithcreatePresetDateRange,createCustomDateRange,validateUtcDateInput,isTimestampInRange, andfileDateCanContainRangeEvent. Preset table is the source of truth forTelemetryRangePresetIdand the UI-facingTELEMETRY_RANGE_PRESETS.Refs #903.
Stack: 1 / 4. Next: #960.
Notable design choices
SessionContext/TelemetryContext/TelemetryEventcome fromz.infer<...>wrapped in a localDeepReadonly<T>so nested fields (includingcontext,properties,measurements,error) stay readonly all the way down.event.tsre-exports the types for back-compat.wireToCamelhelper that renames structural keys (top-level +context);propertiesandmeasurementspass through verbatim since they hold caller-supplied keys.TelemetryFileParseErrorso stream readers can distinguish parse errors from IO errors without sniffing message text.fileDateCanContainRangeEventis a coarse calendar-day filter so files outside the window are skipped without being opened.Tests
test/unit/telemetry/wireFormat.test.tscovers serializer behavior (snake_case top level and context, optional-field omission, arbitrary properties/measurements keys), round-trip serialize→parse,TelemetryFileParseErrortagging withsource:line, and rejection of invalid ISO timestamps and missing structural fields.test/unit/telemetry/export/files.test.ts(memfs-backed) covers date filtering, missing-directory handling, timestamp-range streaming, and parse-error surfacing with file:line context.test/unit/telemetry/export/range.test.tscovers preset and custom range construction, UTC validation, and the calendar-day pre-filter.test/unit/telemetry/sinks/localJsonlSink.test.tsmigrated to the sharedcreateTelemetryEventFactoryand no longer maintains its own event fixture.