Data Architecture & Metrics Pipeline

How every AI-assisted action becomes a measurable metric — from git commit to executive dashboard

7 data sources feed into EventBridge, processed by Lambda, triple-written to DynamoDB (events + metadata) and CloudWatch (time-series). Dashboards read from CloudWatch (real-time) and DynamoDB (historical queries). 8 event types carry 6 AI-DORA metrics across every commit, PR, deploy, and eval gate.

End-to-End Data Flow

DATA SOURCES Git Hooks prepare-commit-msg, post-commit, post-merge GitHub Webhooks push, pull_request, deployment, check_run GitHub Actions CI ai-metrics, dora-weekly, agent-eval workflows Direct API POST /metrics — any system can push events AI Tool Detection CLAUDE_CODE / CLAUDE_SESSION_ID env → claude-code KIRO_SESSION env → kiro Q_DEVELOPER_SESSION env → q-developer Co-Authored-By / generated by → ai-generated Spec files in staged changes → Spec-Ref trailer No AI signals detected → human INGESTION API Gateway 50 req/s • 100K/month EventBridge prism-d1-metrics bus PROCESSING Lambda Normalize • Enrich • Triple-write STORAGE DynamoDB Events prism-d1-events • TTL 365d PK: team#repo • SK: timestamp DynamoDB Metadata prism-team-metadata Latest snapshot per team/repo CloudWatch PRISM/D1/Velocity namespace DASHBOARDS Team Velocity CloudWatch • Real-time Executive Readout QuickSight • Weekly API Queries GET /metrics/{team_id} Alarms 4 CloudWatch alarms 8 Event Types on EventBridge prism.d1.commit Every git commit with AI context prism.d1.pr PR open/merge with lead time & acceptance rate prism.d1.deploy Deployment frequency & change failure rate prism.d1.eval Bedrock eval gate pass/fail prism.d1.incident prism.d1.assessment prism.d1.agent prism.d1.agent.eval

Data Sources

1. Git Hooks (Local Machine)

Installed via bootstrapper/metric-hooks/install.sh. Fire automatically on every commit and merge.

HookTriggerData CapturedOutput
prepare-commit-msg Before commit message editor Detects AI tool via env vars, scans for Co-Authored-By, detects spec files in staged changes Adds trailers: AI-Origin, AI-Tool, AI-Model, Spec-Ref
post-commit After successful commit SHA, author, files changed, lines added/removed, all trailers from message JSON to .prism/metrics/ + async emit to EventBridge
post-merge After merge or git pull AI commits vs human commits on branch, lead time (first commit → merge), AI-to-merge ratio JSON to .prism/metrics/ + async emit to EventBridge

AI Tool Detection Logic: The prepare-commit-msg hook checks environment variables in this order: CLAUDE_CODE / CLAUDE_SESSION_ID → claude-code, KIRO_SESSION → kiro, Q_DEVELOPER_SESSION → q-developer. If none match, it scans the commit message for AI indicators. Default: AI-Origin: human.

2. GitHub Webhooks

The webhook handler at collector/github-webhook-handler/index.ts processes 5 event types with HMAC-SHA256 signature verification.

GitHub EventEvent Type EmittedKey Data Extracted
pushprism.d1.commitFiles changed per commit, AI trailers parsed from each commit message, aggregate AI ratio for the push
pull_request (merged)prism.d1.prLead time (created_at → merged_at), lines changed (additions + deletions), AI-to-merge ratio
deploymentprism.d1.deployDeployment frequency count (1 per event), deployment timestamp
deployment_statusprism.d1.deployChange failure rate: 1 if failure/error, 0 if success
check_run (eval-*)prism.d1.evalEval gate pass/fail (checks for names starting with eval- or prism-eval-), duration

3. GitHub Actions Workflows

Three workflows in bootstrapper/github-workflows/ emit structured events on specific triggers.

prism-ai-metrics.yml

Trigger: PR merged to main
Calculates: AI-to-merge ratio (counts AI vs human commits), lead time (PR created → merged), acceptance rate (approved reviews / total reviews)
Emits: prism.d1.pr + prism.d1.deploy

prism-dora-weekly.yml

Trigger: Monday 09:00 UTC (+ manual)
Calculates: 7-day DORA snapshot (deploy freq, avg lead time, CFR via revert/hotfix detection, MTTR). AI adoption rate, spec coverage, tool breakdown (Claude Code / Kiro / Q Dev)
Emits: prism.d1.assessment

prism-agent-eval.yml

Trigger: PR modifying agent paths
Calculates: Agent quality scores (task_completion, tool_efficiency, guardrail_compliance, reasoning_quality, error_recovery) via Bedrock evaluation rubric
Emits: prism.d1.agent.eval

Direct API Ingestion

Endpoint: POST /metrics
Auth: API key + usage plan
Rate: 50 req/s burst, 100K/month quota
Use case: Custom integrations, third-party CI, manual metric submission

4. CI Metadata Emitter

The shell script at collector/ci-metadata-emitter/emit-metrics.sh runs inside GitHub Actions to emit deploy/PR events. It parses the git log from base ref to HEAD, counts commits by AI origin, calculates AI-to-merge ratio, and emits to EventBridge.

# Environment variables the emitter reads
PRISM_EVENT_TYPE=deploy|pr     PRISM_TEAM_ID=team-alpha
PRISM_EVENT_BUS=prism-d1-metrics   PRISM_REPO=owner/repo
PRISM_BASE_REF=origin/main    PRISM_SHA=abc123
PRISM_PR_CREATED_AT=2026-04-20T10:00:00Z   # for lead time calc

Event Schema

Every event follows this structure on EventBridge:

{
  "source": "prism.d1.velocity",
  "detail-type": "prism.d1.commit | .pr | .deploy | .eval | .incident | .assessment | .agent | .agent.eval",
  "detail": {
    "team_id": "team-alpha",
    "repo": "owner/repo-name",
    "timestamp": "2026-04-22T14:30:00Z",
    "prism_level": 3,
    "metric": {
      "name": "commit.files_changed",     // primary metric name
      "value": 5,                          // numeric value
      "unit": "files"                      // count | percent | seconds | hours | files | lines
    },
    "ai_context": {
      "tool": "claude-code",               // claude-code | kiro | q-developer | none
      "model": "claude-sonnet-4",          // model identifier
      "session_id": "sess_abc123",         // optional session ID
      "origin": "ai-assisted"              // ai-assisted | ai-generated | human
    },
    "dora": {
      "deployment_frequency": 1,           // count per event
      "lead_time_seconds": 3600,           // PR created → merged
      "change_failure_rate": 0.0,          // 0 or 1 per event, averaged over time
      "mttr_seconds": null                 // incident → resolution
    },
    "ai_dora": {
      "ai_acceptance_rate": 0.85,          // approved reviews / total reviews
      "ai_to_merge_ratio": 0.70,           // AI commits / total commits
      "spec_to_code_hours": 1.8,           // spec approved → code ready
      "post_merge_defect_rate": 0.014,     // defects per AI-assisted merge
      "eval_gate_pass_rate": 1.0,          // 1 if pass, 0 if fail
      "ai_test_coverage_delta": 0.123      // coverage change from AI tests
    }
  }
}

Processing & Storage

The Lambda processor (infra/lib/lambda/metrics-processor.ts) does a triple-write for every event:

Write 1: DynamoDB Events Table

FieldValuePurpose
Tableprism-d1-eventsImmutable event log
Partition Key{team_id}#{repo}Team+repo scoping
Sort Key{timestamp} ISO 8601Time-ordered within partition
GSIby-detail-type (PK: detail_type, SK: timestamp)Query by event type across teams
TTL365 daysAuto-expire old events
DataFull event detail (JSON stringified)Complete audit trail

Write 2: DynamoDB Metadata Table

FieldValuePurpose
Tableprism-team-metadataLatest snapshot per team/repo
Keyteam_id + repoFast lookup for current state
UpdatedEvery event overwrites latest valuesAlways-current DORA + AI-DORA numbers
TTLNonePersists until team is removed

Write 3: CloudWatch Metrics

Published to namespace PRISM/D1/Velocity with dimensions:

DimensionSourceRequired
TeamIddetail.team_idYes
Repositorydetail.repoYes
AIOrigindetail.ai_context.originOptional — enables filtering by ai-generated / ai-assisted / human
AgentNamedetail.agent.nameOptional — for agent metrics only

Dimensionless publishing: Every metric is also published without dimensions, enabling aggregate queries across all teams and repos in a single dashboard widget.

CloudWatch Metrics Catalog

DORA Metrics

DeploymentFrequency
Count
LeadTimeForChanges
Seconds
ChangeFailureRate
Percent
MTTR
Seconds

AI-DORA Metrics

AIAcceptanceRate
Percent
AIToMergeRatio
Percent
EvalGatePassRate
Percent
SpecToCodeHours
Hours
PostMergeDefectRate
Percent
AITestCoverageDelta
Percent

Agent Metrics

AgentInvocationCount
Count
AgentStepCount
Count
AgentDurationMs
Milliseconds
AgentTokensUsed
Count
AgentToolInvocationCount
Count
AgentGuardrailTriggerCount
Count
AgentSuccessRate
Percent

What Dashboards Read From

DashboardData SourceRefreshAudience
CloudWatch Team VelocityCloudWatch metrics (PRISM/D1/Velocity)Real-timeEngineering teams, tech leads
CloudWatch Executive ReadoutCloudWatch metrics (PRISM/D1/Velocity)Real-timeCTOs, VPEs, directors
QuickSight AI-DORA AnalysisTimestream (fed from CloudWatch)Near real-timeEngineering leaders
QuickSight PRISM Level TrackerTimestream + DynamoDB metadataNear real-timeExecutive review
API: GET /metrics/{team_id}DynamoDB events tableOn-demandCustom integrations

Active Alarms

AlarmMetricThresholdPeriod
AI Acceptance Rate LowAIAcceptanceRate< 20%6 hours
Eval Gate Pass Rate LowEvalGatePassRate< 70%6 hours
Change Failure Rate HighChangeFailureRate> 20%6 hours
Agent Success Rate LowAgentSuccessRate< 80%1 hour

Current Gap: Token Usage & Cost Tracking

Claude Code, Kiro, and Q Developer token consumption is NOT tracked today. The pipeline captures which tool was used and what it produced (commits, PRs), but not how many tokens it consumed or what it cost. Agent token usage (AgentTokensUsed) is tracked for Strands agents, but not for interactive developer tool sessions.

What's tracked vs. what's missing

DimensionTodayMissing
Tool identityTracked via env var detection
Model usedTracked via AI-Model trailer
Code outputTracked lines/files per commit
Token consumptionNot trackedInput tokens, output tokens, total tokens per session/commit
Session durationNot trackedHow long each Claude Code / Kiro session lasted
Cost per sessionNot trackedDollar cost of each AI interaction
Cost per commitNot trackedCorrelation of token cost to code output
Cost per PR/featureNot trackedAggregate cost across a feature's lifecycle
Developer-level costNot trackedPer-developer AI consumption patterns
License spendNot trackedMonthly tool subscription costs

Why it's hard today

Proposed solution: Bedrock CloudTrail → Token Pipeline

See the Token & Cost Intelligence phase in the Community Roadmap for the full implementation plan.

Bedrock InvokeModel API calls
         |
         v
CloudTrail (logs every call with input_tokens, output_tokens, model_id)
         |
         v
EventBridge Rule (matches bedrock.amazonaws.com InvokeModel events)
         |
         v
Lambda: token-cost-processor
  - Extract: model_id, input_tokens, output_tokens, timestamp, IAM user/role
  - Look up cost: model pricing table (DynamoDB)
  - Correlate: timestamp proximity to commits (within 5-min window)
  - Correlate: IAM role → developer identity
  - Aggregate: per-session, per-commit, per-PR, per-feature
         |
         v
CloudWatch: PRISM/D1/Velocity namespace
  - BedrockTokensInput (by TeamId, Developer, Model)
  - BedrockTokensOutput (by TeamId, Developer, Model)
  - BedrockCostUSD (by TeamId, Developer, Model)
  - CostPerCommit (by TeamId, AITool)
  - CostPerPR (by TeamId)
         |
         v
Dashboards: Token usage trends, cost overlays, ROI calculation

Key Files Reference

ComponentLocationPurpose
Git hooksbootstrapper/metric-hooks/Local commit metadata capture + AI tool detection
GitHub webhook handlercollector/github-webhook-handler/index.tsProcess push, PR, deploy, check_run events
CI metric emittercollector/ci-metadata-emitter/emit-metrics.shShell script for GitHub Actions metric emission
Commit analyzercollector/git-hooks/prism-commit-analyzer.tsStandalone commit analysis tool
Metrics processor Lambdainfra/lib/lambda/metrics-processor.tsEventBridge → DynamoDB + CloudWatch triple-write
API handler Lambdainfra/lib/lambda/api-handler.tsREST API for ingestion + queries
Metrics pipeline stackinfra/lib/metrics-pipeline-stack.tsEventBridge bus + DynamoDB tables + Lambda
API stackinfra/lib/api-stack.tsAPI Gateway + Lambda + usage plans
Dashboard stackinfra/lib/dashboard-stack.tsCloudWatch dashboards + alarms
AI metrics workflowbootstrapper/github-workflows/prism-ai-metrics.ymlPR merge → AI-DORA event emission
DORA weekly workflowbootstrapper/github-workflows/prism-dora-weekly.ymlWeekly DORA + AI adoption assessment
Agent eval workflowbootstrapper/github-workflows/prism-agent-eval.ymlAgent quality gate on PRs
Workshop moduleworkshop/04-instrumenting-ai-metrics/Hands-on exercises for metric instrumentation