Skip to content

feat(den): analytics event model + /v1/telemetry/analytics endpoint (Layer 1+2)#2148

Open
benjaminshafii wants to merge 1 commit into
devfrom
analytics/layer12-server
Open

feat(den): analytics event model + /v1/telemetry/analytics endpoint (Layer 1+2)#2148
benjaminshafii wants to merge 1 commit into
devfrom
analytics/layer12-server

Conversation

@benjaminshafii

Copy link
Copy Markdown
Member

What

First of three PRs implementing OpenWork Analytics Layers 1 (who is using AI) and 2 (how often).

Server-side foundation:

  • Event model (ee/packages/den-db/src/schema/telemetry.ts + migration 0021): adds source, session_id, duration_ms, success columns to telemetry_event, and expands the allowed event types to the PRD set: user.active, session.active, session.started/ended, task.started/completed/failed.
  • Ingest hardening (POST /v1/telemetry/ingest): unknown event types are silently dropped, disallowed source values are nulled, durationMs is clamped. Still fire-and-forget (always 204, errors swallowed). No content fields exist anywhere in the pipeline — only event names, timestamps, opaque session ids, durations, and success flags.
  • New GET /v1/telemetry/analytics: org-scoped Layer 1+2 aggregates — members, pending invites, active members (7d/30d), distinct sessions (7d/30d), tasks completed/failed (7d/30d), avg task duration (30d), and a 12-week trend of active members / sessions / tasks per week.

The existing /v1/telemetry/adoption endpoint is unchanged for compatibility.

Stack

  1. This PR — server event model + analytics endpoint
  2. #TBD — Den dashboard Analytics page (stacked on this)
  3. #TBD — desktop app emits task lifecycle events

Tests

Commands run:

  • pnpm --filter @openwork-ee/den-db db:generate — migration 0021_flaky_hex.sql generated cleanly
  • npx tsc --noEmit in ee/apps/den-api — passes
  • End-to-end against the local Den stack (dev:den:mysql + drizzle push + dev:den:api + seed:demo-org):
    • signed in as the seeded demo owner, POST /v1/telemetry/ingest with 6 events → 204
    • unknown event type (totally.unknown) not stored (5 rows in DB), disallowed source (evil-source) stored as NULL
    • GET /v1/telemetry/analytics returned correct aggregates: members: 17, activeMembers7d: 1, sessions7d: 2 (distinct session ids), tasksCompleted7d: 2, tasksFailed7d: 1, avgTaskDurationMs30d: 30000 = (42000+18000)/2 ✓

Raw verification output:

ingest: 204
{"members":17,"pendingInvites":3,"activeMembers7d":1,"activeMembers30d":1,
 "sessions7d":2,"sessions30d":2,"tasksCompleted7d":2,"tasksFailed7d":1,
 "tasksCompleted30d":2,"tasksFailed30d":1,"avgTaskDurationMs30d":30000,...}

event_type      source  session_id  duration_ms  success
session.active  app     ses_demo_1  NULL         NULL
task.started    app     ses_demo_1  NULL         NULL
task.completed  app     ses_demo_1  42000        1
task.failed     app     ses_demo_2  9000         0
task.completed  NULL    ses_demo_2  18000        1

No video for this server-only PR; the stacked dashboard PR includes UI screenshots of this data rendered.

Notes / decisions

  • GET /v1/telemetry/analytics follows the same auth posture as the existing /adoption endpoint (signed-in member of the org; aggregates only, no per-member breakdown), with the admin gate enforced in the dashboard UI route group.
  • Sessions are counted as COUNT(DISTINCT session_id), which naturally ignores legacy rows without a session id.

Layer 1+2 of OpenWork Analytics:
- extend telemetry_event with source, session_id, duration_ms, success
- expand allowed event types (session/task lifecycle) and drop unknown
  types and disallowed sources at ingest
- new GET /v1/telemetry/analytics: members, active members (7d/30d),
  distinct sessions, task completed/failed counts, avg task duration,
  and a 12-week trend of active members / sessions / tasks
@vercel

vercel Bot commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
openwork-app Ready Ready Preview, Comment Jun 10, 2026 3:09pm
openwork-den Ready Ready Preview, Comment Jun 10, 2026 3:09pm
openwork-den-worker-proxy Building Building Preview, Comment Jun 10, 2026 3:09pm
openwork-landing Ready Ready Preview, Comment, Open in v0 Jun 10, 2026 3:09pm

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant