|
1 | | -Telemetry Receiver Prototype |
2 | | - |
3 | | -Purpose: |
4 | | - |
5 | | -This receiver is a development prototype for collecting telemetry events emitted by the Director and related runtime components. It is intended for local testing and experimentation only — not for production use. Use it to: |
6 | | - |
7 | | -- Capture and inspect `director_decision` events emitted by the Director during playtests. |
8 | | -- Exercise telemetry payload shapes and validate downstream processing or analysis scripts. |
9 | | -- Provide a simple, disposable storage backend (newline-delimited JSON) for quick local debugging. |
10 | | - |
11 | | -Do not rely on this receiver for production telemetry: it has no authentication, no retention/rotation, and minimal error handling. |
12 | | - |
13 | | -Run locally: |
14 | | - |
15 | | -- Node (>= 14) is required |
16 | | -- Start the receiver: |
17 | | - |
18 | | - PORT=4005 node server/telemetry/receiver.js |
19 | | - |
20 | | -It listens on `/` for HTTP POST JSON payloads. |
21 | | - |
22 | | -Accepted events: |
23 | | - |
24 | | -Only events with `type: "director_decision"` (or `event_type` or nested `event.type`) are accepted and persisted to `server/telemetry/events.ndjson`. |
25 | | - |
26 | | -Expected payload shape (example): |
27 | | - |
28 | | - { |
29 | | - "type": "director_decision", |
30 | | - "decision": "accept", |
31 | | - "reason": "low_risk", |
32 | | - "meta": { "user": "test" } |
33 | | - } |
34 | | - |
35 | | -Example curl test: |
36 | | - |
37 | | - curl -v -X POST \ |
38 | | - -H "Content-Type: application/json" \ |
39 | | - -d '{"type":"director_decision","decision":"accept","meta":{"user":"test"}}' \ |
40 | | - http://localhost:4005/ |
41 | | - |
42 | | -Expected responses: |
43 | | -- 200 {"ok":true} for valid director_decision events |
44 | | -- 400 {"error":"Invalid or unsupported event type"} for invalid event types |
45 | | -- 400 {"error":"Invalid JSON"} for malformed JSON |
46 | | -- 404 for non-POST or other paths |
47 | | - |
48 | | -Storage: |
49 | | -- Events are appended to `server/telemetry/events.ndjson` as newline-delimited JSON lines with a `received_at` timestamp. |
50 | | - |
51 | | -Notes / next steps: |
52 | | -- This is intentionally minimal. For follow-up work consider adding SQLite persistence, simple schema validation, or basic authentication before using in shared environments. |
| 1 | +Telemetry receiver (dev prototype) |
| 2 | + |
| 3 | +Purpose |
| 4 | +------- |
| 5 | +Lightweight development receiver that accepts POSTed JSON events and persists director decision telemetry for local analysis. |
| 6 | + |
| 7 | +What it does |
| 8 | +------------ |
| 9 | +- Accepts POST requests to `/` with a JSON body. |
| 10 | +- Validates that the event represents a `director_decision` (accepts payloads with `type: "director_decision"` or same under `event_type` or `event.type`). |
| 11 | +- Appends accepted events as NDJSON lines to `server/telemetry/events.ndjson` (dev ingestion store). |
| 12 | + |
| 13 | +Run locally |
| 14 | +----------- |
| 15 | +```bash |
| 16 | +# starts the receiver on port 4005 by default |
| 17 | +node server/telemetry/receiver.js |
| 18 | + |
| 19 | +# to choose a different port (useful in tests): |
| 20 | +PORT=0 node server/telemetry/receiver.js |
| 21 | +``` |
| 22 | + |
| 23 | +The process prints the listening URL to stdout when ready, e.g. `Telemetry receiver listening on http://localhost:4005/`. |
| 24 | + |
| 25 | +API (single endpoint) |
| 26 | +--------------------- |
| 27 | +- POST / |
| 28 | + - Content-Type: application/json |
| 29 | + - Body: arbitrary JSON representing an event |
| 30 | + - Success (200): when the payload identifies as a `director_decision` and was persisted |
| 31 | + - Client error (400): when payload is invalid JSON or not a supported event type |
| 32 | + - Server error (500): when writing to storage failed |
| 33 | + |
| 34 | +Example payload (director_decision) |
| 35 | +---------------------------------- |
| 36 | +```json |
| 37 | +{ |
| 38 | + "type": "director_decision", |
| 39 | + "proposal_id": "p1", |
| 40 | + "decision": "approve", |
| 41 | + "riskScore": 0.12, |
| 42 | + "reason": "low_risk", |
| 43 | + "metrics": { "latencyMs": 120 } |
| 44 | +} |
| 45 | +``` |
| 46 | + |
| 47 | +Curl example |
| 48 | +------------ |
| 49 | +```bash |
| 50 | +curl -X POST http://localhost:4005/ \ |
| 51 | + -H 'Content-Type: application/json' \ |
| 52 | + -d '{"type":"director_decision","proposal_id":"p1","decision":"approve","riskScore":0.12}' |
| 53 | +``` |
| 54 | + |
| 55 | +Inspecting persisted events |
| 56 | +--------------------------- |
| 57 | +Events are appended to `server/telemetry/events.ndjson` as one JSON object per line. To inspect recent events: |
| 58 | + |
| 59 | +```bash |
| 60 | +tail -n 50 server/telemetry/events.ndjson | jq . |
| 61 | +``` |
| 62 | + |
| 63 | +Development notes |
| 64 | +----------------- |
| 65 | +- This receiver is intentionally small and intended for dev/testing only. Production work (SQLite storage, schema validation, auth/token protection, log rotation) is tracked in `ge-apq.1` and should be implemented before using this in production. |
| 66 | +- The receiver uses `server/telemetry/backend-ndjson.js` as the storage backend; swap or extend backends as needed. |
0 commit comments