Skip to content

feat: add admin request logs page#184

Open
kiloconnect[bot] wants to merge 1 commit intomainfrom
feat/admin-request-logs
Open

feat: add admin request logs page#184
kiloconnect[bot] wants to merge 1 commit intomainfrom
feat/admin-request-logs

Conversation

@kiloconnect
Copy link
Contributor

@kiloconnect kiloconnect bot commented Feb 13, 2026

Summary

Adds a new admin page at /admin/requests for searching and viewing API request logs from the api_request_log table.

Features

  • Search & Filtering: Search by request ID (exact match), date range, full-text search across request data (provider, model, user, org, request JSON), and individual field filters (provider, model, status code, user ID, org ID)
  • Results Display: Clean table view with sortable columns, color-coded status badges, formatted timestamps, and pagination
  • Detail View: Dialog with toggle between structured "Formatted" view and "Raw JSON" view using @uiw/react-json-view
  • Admin Access Control: Enforced via existing admin layout auth guard and tRPC adminProcedure

Files Changed

  • src/routers/admin-router.ts — Added requestLogs.list tRPC procedure
  • src/app/admin/api/requests/hooks.ts — Created tRPC query hook
  • src/app/admin/components/RequestLogsTable.tsx — Created main table component with filters, sorting, pagination, and detail dialog
  • src/app/admin/requests/page.tsx — Created page component
  • src/app/admin/components/AppSidebar.tsx — Added "Request Logs" nav item

Built for Marius Wichtner by Kilo for Slack

const conditions = [];

if (requestId) {
conditions.push(eq(api_request_log.id, BigInt(requestId)));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

WARNING: requestId parsing can throw at runtime

BigInt(requestId) will throw if the UI sends a non-integer string (e.g. whitespace, non-numeric, or out-of-range formatting), which would turn a bad filter input into a 500. Consider validating/coercing at the Zod layer (e.g. require ^\d+$), or safely parsing and returning a BAD_REQUEST TRPC error.

}

if (input.fromDate) {
conditions.push(gte(api_request_log.created_at, input.fromDate));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

WARNING: Date filters accept arbitrary strings

fromDate/toDate are z.string().optional() but get passed into gte/lte against a timestamp column. If a client sends an invalid datetime string, Postgres can error. Consider using z.string().datetime() (or coercing to Date) so invalid inputs are rejected deterministically.

provider: api_request_log.provider,
model: api_request_log.model,
status_code: api_request_log.status_code,
request: api_request_log.request,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

WARNING: List endpoint returns full request/response payloads

Selecting request and response for every row can make the list query/network response very heavy (and may expose large/secret-bearing payloads to the UI unnecessarily). Consider returning only summary fields for the table, and add a getById endpoint (or includeBodies flag) for the detail dialog.


if (filters.requestId) params.requestId = filters.requestId;
if (debouncedSearch) params.search = debouncedSearch;
if (filters.fromDate) params.fromDate = new Date(filters.fromDate).toISOString();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

WARNING: toISOString() can throw for invalid date input

new Date(filters.fromDate).toISOString() throws a RangeError if the value is not a valid date. While datetime-local usually produces valid values, it can still be cleared/edited into an invalid string; consider guarding with isNaN(date.getTime()) before calling toISOString().

@kiloconnect
Copy link
Contributor Author

kiloconnect bot commented Feb 13, 2026

Code Review Summary

Status: 4 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 0
WARNING 4
SUGGESTION 0

Fix these issues in Kilo Cloud

Issue Details (click to expand)

WARNING

File Line Issue
src/routers/admin-router.ts 712 BigInt(requestId) can throw on invalid input; validate/coerce and return a BAD_REQUEST TRPC error instead of 500
src/routers/admin-router.ts 728 fromDate/toDate are arbitrary strings; invalid datetime strings can cause Postgres errors; validate with Zod datetime/coerce to Date
src/routers/admin-router.ts 776 List query returns full request/response bodies for every row (heavy and potentially sensitive); consider summaries + getById for details
src/app/admin/components/RequestLogsTable.tsx 303 toISOString() throws RangeError for invalid date strings; guard before calling
Other Observations (not in diff)

Issues found in unchanged code that cannot receive inline comments:

File Line Issue
Files Reviewed (5 files)
  • src/app/admin/api/requests/hooks.ts - 0 issues
  • src/app/admin/components/AppSidebar.tsx - 0 issues
  • src/app/admin/components/RequestLogsTable.tsx - 1 issue
  • src/app/admin/requests/page.tsx - 0 issues
  • src/routers/admin-router.ts - 3 issues

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.

0 participants