Skip to content

Add Kafka analytics event ingestion endpoint#10

Draft
IamJasonBian wants to merge 6 commits into
mainfrom
claude/practical-bohr-x4jIC
Draft

Add Kafka analytics event ingestion endpoint#10
IamJasonBian wants to merge 6 commits into
mainfrom
claude/practical-bohr-x4jIC

Conversation

@IamJasonBian

Copy link
Copy Markdown
Owner

$(cat <<'EOF'

Summary

  • Adds POST /api/analytics Netlify Function that accepts single or batched event payloads
  • Enriches events with server-side timestamps and source IP before producing to Kafka
  • Uses Upstash Kafka REST API (HTTP-based, no persistent TCP — required for serverless)
  • Routes /api/analytics/.netlify/functions/analytics in netlify.toml

Configuration

Set these Netlify env vars before deploying:

Var Description
UPSTASH_KAFKA_REST_URL e.g. https://<id>.upstash.io
UPSTASH_KAFKA_REST_USERNAME Upstash REST credential
UPSTASH_KAFKA_REST_PASSWORD Upstash REST credential
KAFKA_TOPIC Topic name, defaults to analytics

Usage

# Single event
curl -X POST https://route-runtime-service.netlify.app/api/analytics \
  -H "Content-Type: application/json" \
  -d '{"event": "page_view", "properties": {"url": "/dashboard"}}'

# Batch
curl -X POST https://route-runtime-service.netlify.app/api/analytics \
  -H "Content-Type: application/json" \
  -d '[{"event":"order_placed","properties":{"symbol":"AAPL"}},{"event":"page_view"}]'

Test plan

  • POST single event returns {"ok":true,"published":1}
  • POST batch array returns correct published count
  • Missing event field returns 400
  • Missing Kafka env vars returns 502 with descriptive message
  • OPTIONS returns 204 (CORS preflight)

https://claude.ai/code/session_01CXxC65zr3ZHxDuqTkxm4vH
EOF
)


Generated by Claude Code

Adds POST /api/analytics that accepts single or batched event payloads,
enriches them with server-side timestamps and source IP, and produces
them to an Upstash Kafka topic via the Upstash REST API.

Requires UPSTASH_KAFKA_REST_URL, UPSTASH_KAFKA_REST_USERNAME,
UPSTASH_KAFKA_REST_PASSWORD env vars; KAFKA_TOPIC defaults to "analytics".

https://claude.ai/code/session_01CXxC65zr3ZHxDuqTkxm4vH
@netlify

netlify Bot commented Jun 4, 2026

Copy link
Copy Markdown

Deploy Preview for route-runtime-service ready!

Name Link
🔨 Latest commit f1e0b72
🔍 Latest deploy log https://app.netlify.com/projects/route-runtime-service/deploys/6a21d232e867a20008434d63
😎 Deploy Preview https://deploy-preview-10--route-runtime-service.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

claude added 5 commits June 4, 2026 19:11
ANALYTICS_BACKEND env var selects "blob" (default), "kafka", or "both".
Blob backend uses Netlify Blobs with key layout {event}/{date}/{unix_ms}
enabling prefix filtering by event type and date partition. New GET
/api/analytics endpoint supports ?event, ?since, ?date, ?limit queries
against the blob store. Kafka backend unchanged (Upstash REST).

https://claude.ai/code/session_01CXxC65zr3ZHxDuqTkxm4vH
- Add unique suffix to blob keys so same-named events in a batch (or same
  millisecond) no longer silently overwrite each other; published count
  now matches blobs written.
- Validate event names against [A-Za-z0-9._-]{1,128}; reject slashes which
  corrupted the {event}/{date}/{ts} key layout and made events unqueryable.
- Update query timestamp parsing/sort for the new {ts}-{uniq} segment.

https://claude.ai/code/session_01CXxC65zr3ZHxDuqTkxm4vH
Replace UPSTASH_KAFKA_REST_{URL,USERNAME,PASSWORD} with generic
KAFKA_REST_{URL,USERNAME,PASSWORD} so any REST-capable broker
(Upstash, Confluent, Redpanda, etc.) works without code changes.

https://claude.ai/code/session_01CXxC65zr3ZHxDuqTkxm4vH
- Add global security: [] (public by default) + BearerAuth securityScheme,
  fixing all 11 security-defined errors across every operation
- Add security: [{BearerAuth: []}] on PUT /mcp-context (the only authenticated op)
- Add license + url to info block (info-license-strict warning)
- Add 405 responses to GET /health and GET /snapshots (operation-4xx-response warnings)
- Document POST/GET /api/analytics with request/response schemas

https://claude.ai/code/session_01CXxC65zr3ZHxDuqTkxm4vH
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.

2 participants