@redthreadlabs/tracelog-schema
v0.7.0
Published
Shared contract for the tracelog suite: record kinds, S3 key layout, metadata sidecar, and the /logs wire format
Maintainers
Readme
@redthreadlabs/tracelog-schema
The shared contract for the tracelog suite — one dependency-free, isomorphic source of truth so the agent (writer), the client SDK, the server, and the viewer (reader) never drift.
It contains only the contract: types and pure functions, no I/O.
- Record kinds (
kinds.ts) — the top-level kinds of each NDJSON line (transaction,span,error,event,metricset). - S3 key layout (
keys.ts) —buildKey/parseKey(exact inverses) plusintervalSpan,overlapsRange,dedupeCurrents,normalizeHost. The layout{channel}/{interval}/{host}[_{seq}][_current].jsonl[.gz]is fixed. - Metadata sidecar (
sidecar.ts) — theSidecarMetashape written at<logkey>.meta.json, plus theMetaAccumulatorthat derives it from a file's bytes (uncompressed size, record count, and an hourly interval×kind histogram). - Wire format (
wire.ts) — thePOST /logsingest types: theRecordBatchenvelope, the records it carries (EventRecord,TransactionRecord,SpanRecord), their sharedRecordContext, and theRecordOriginametadatarecord carries.SCHEMA_VERSIONis the value a writer puts inorigin.schema. - Analytics context (
wire.ts,context.ts) — the typedRecordContextsub-objectsvisitor,visit,actor,page,campaign,geo,entity, andsanitizeContext, the one ingest filter for an untrusted context, withisVisitorKind/isVia. - Analytics events (
analytics.ts) —ANALYTICS_EVENT_TYPES,REQUIRED_CONTEXTper type,isAuditEventTypefor the openaudit.<action>family, andcheckAnalyticsEvent.
See docs/ANALYTICS_CONTEXT.md for the analytics fields, their words, and what the viewer reads.
Usage
import {
parseKey,
MetaAccumulator,
RECORD_KINDS,
sanitizeContext,
checkAnalyticsEvent,
type EventRecord,
type RecordBatch,
} from '@redthreadlabs/tracelog-schema';Build / test
Plain tsc to CommonJS dist/; tests run against the compiled output.
npm run build
npm test