stack/packages
mantrakp04 b8215a8595 feat(analytics): public trackEvent/startSpan SDK + custom events/spans ingestion
Client SDK (browser):
- app.trackEvent(type, data?, {parentIds?}) and app.startSpan(type, {data?, parentIds?, startedAtMs?}) on StackClientApp
- Span handles: setData (merge + re-write), end (idempotent), trackEvent/startSpan (inherit full chain), ref() for cross-tier parenting
- setGlobalSpan/unsetGlobalSpan (ambient parents for spans AND events, auto-unset on end), app.flush()
- Per-item promises settle on batch ack; pre-caught (no unhandled rejections); nothing throws synchronously
- Spans are versioned upserts: written open on start, re-written on setData/end with per-handle monotonic updated_at_ms
- Batch-poisoning protection: full item validation at enqueue (name regex, 16KB data cap, uuid parents, depth<=10)
- clearBuffer rejects pending + inert-ifies live spans (sign-out privacy, pairs with segment-id rotation)

Server SDK:
- serverApp.trackEvent/startSpan with explicit {userId}; same-tick coalescing per userId (one POST per sync burst)
- sendAnalyticsEventBatchAsServer on HexclaveServerInterface (secret server key -> analytics base URL)

Backend:
- events batch route accepts custom event types, events[*].parent_span_ids, spans[], and server/admin auth with body user_id (verified in tenancy)
- buildCustomSpanRows: cs- prefixed ids, system ancestry (rti-/sri-/srsi-, same gating as events) prepended to client chain, version clamped to now+5min
- custom spans insert off the response path (waitUntil), quota debits events+spans
- stripLoneSurrogates moved to lib/clickhouse for reuse

Tests: 8 new spans.test.ts cases, 9 new event-tracker.test.ts cases, 17 new e2e cases (e2e not executed: dev stack down; 2 pre-existing snapshots updated for intentional schema-message changes)
2026-07-02 11:34:34 -07:00
..
cli chore: update package versions 2026-06-30 23:15:23 +00:00
dashboard-ui-components More consistent dashboard (#1613) 2026-07-01 09:24:08 -07:00
js chore: update package versions 2026-06-30 23:15:23 +00:00
next chore: update package versions 2026-06-30 23:15:23 +00:00
react chore: update package versions 2026-06-30 23:15:23 +00:00
sc chore: update package versions 2026-06-30 23:15:23 +00:00
shared feat(analytics): public trackEvent/startSpan SDK + custom events/spans ingestion 2026-07-02 11:34:34 -07:00
shared-backend chore: update package versions 2026-06-30 23:15:23 +00:00
tanstack-start chore: update package versions 2026-06-30 23:15:23 +00:00
template feat(analytics): public trackEvent/startSpan SDK + custom events/spans ingestion 2026-07-02 11:34:34 -07:00
ui More consistent dashboard (#1613) 2026-07-01 09:24:08 -07:00