Skip to content

[wip] adding more mo telemetry events#247

Open
Sayan- wants to merge 3 commits into
mainfrom
sayan/kernel-1301-add-more-events
Open

[wip] adding more mo telemetry events#247
Sayan- wants to merge 3 commits into
mainfrom
sayan/kernel-1301-add-more-events

Conversation

@Sayan-
Copy link
Copy Markdown
Contributor

@Sayan- Sayan- commented May 21, 2026

Note

Medium Risk
Adds new request/WS middleware and expands telemetry configuration/schema, which can affect API routing performance and emitted event volume/shape. Behavior is gated behind config, but incorrect toggling could lead to missing or unexpected telemetry.

Overview
Adds an api telemetry category and wires it through PUT/PATCH /telemetry so enabling/disabling that category dynamically turns API-call event emission on/off.

Introduces TelemetryHTTPMiddleware + TelemetryStrictMiddleware to emit api_call events for documented OpenAPI operations (operationId, status, duration, request_id), and updates main.go to install RequestID plus these middleware.

Extends the DevTools WebSocket proxy to optionally publish cdp_connect/cdp_disconnect system events (including disconnect reason, duration, and relayed message count), updates call sites/tests, and updates the OpenAPI spec/generated oapi types to include the new events and api category.

Reviewed by Cursor Bugbot for commit 0e22845. Bugbot is set up for automated code reviews on this repo. Configure here.

@firetiger-agent
Copy link
Copy Markdown

Firetiger deploy monitoring skipped

This PR didn't match the auto-monitor filter configured on your GitHub connection:

Any PR that changes the kernel API. Monitor changes to API endpoints (packages/api/cmd/api/) and Temporal workflows (packages/api/lib/temporal) in the kernel repo

Reason: PR title and empty body suggest telemetry event additions rather than kernel API or Temporal workflow changes; please confirm if this affects packages/api/cmd/api/ or packages/api/lib/temporal to opt into deploy monitoring.

To monitor this PR anyway, reply with @firetiger monitor this.

Comment thread server/openapi.yaml
Schemas:
- New event types: api_call (HTTP middleware), cdp_connect / cdp_disconnect
  (CDP proxy), live_view_connect / live_view_disconnect (Neko, producer
  in a follow-up).
- captcha_solve_result enum trimmed to the producer-normalized vendor set
  (hcaptcha, recaptcha_v2, recaptcha_v3, turnstile, geetest, other).
- New `api` user-toggleable category for api_call events.

Producers:
- chi middleware emits api_call with operationId / status / request_id /
  duration_ms. Disabled by default; the telemetry handler flips the
  package-level toggle on/off when the api category is enabled.
- WebSocketProxyHandler emits cdp_connect on accept and cdp_disconnect on
  teardown with message_count and reason (client_close / upstream_changed
  / upstream_error / context_cancelled).

Co-authored-by: Cursor <cursoragent@cursor.com>
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 2 potential issues.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 0e22845. Configure here.

"operation_id": tc.operationID,
"status": ww.Status(),
"duration_ms": float64(time.Since(start).Microseconds()) / 1000.0,
})
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ad-hoc map literals instead of generated oapi types

Medium Severity

Event data payloads in TelemetryHTTPMiddleware and publishCdpDisconnect are constructed using map[string]any literals instead of the generated oapi.BrowserApiCallEventData and oapi.BrowserCdpDisconnectEventData types. The existing cdpmonitor producers already use generated types (e.g., oapi.BrowserConsoleLogEventData). Using ad-hoc maps bypasses compile-time checking and risks drift between the documented API contract and actual event shapes — for instance, the generated DurationMs field is float32 but the map uses float64, and MessageCount is int in the schema but int64 in the map.

Additional Locations (1)
Fix in Cursor Fix in Web

Triggered by learned rule: Producer repo must own typed event schemas in OpenAPI and use generated oapi types

Reviewed by Cursor Bugbot for commit 0e22845. Configure here.

cdpReasonUpstreamChanged = "upstream_changed"
cdpReasonUpstreamError = "upstream_error"
cdpReasonContextCanceled = "context_cancelled"
)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CDP disconnect reasons use raw strings not generated enum

Low Severity

The CDP disconnect reason constants (cdpReasonClientClose, cdpReasonUpstreamChanged, etc.) are declared as plain string values. The generated code already provides oapi.BrowserCdpDisconnectEventDataReason as a typed enum with constants like oapi.ClientClose, oapi.UpstreamChanged, etc. The hand-rolled string constants duplicate the generated ones and bypass the type system, allowing silent drift if the OpenAPI enum values ever change.

Fix in Cursor Fix in Web

Triggered by learned rule: Producer repo must own typed event schemas in OpenAPI and use generated oapi types

Reviewed by Cursor Bugbot for commit 0e22845. Configure here.

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