Skip to content

Implement automated database index analysis and slow query logging interceptor #102

Description

@Cjay-Cyber-2

Description — what to implement and the why/impact.

As the Astroid financial operating system processes high volumes of agent transactions and wallet audit logs, database performance is critical. Currently, slow or unoptimized queries are not systematically tracked or measured in production. This issue implements a NestJS interceptor or Prisma middleware that logs query execution duration and flags queries exceeding a configurable threshold for database performance tuning.

Context & Requirements — background, constraints, design references, edge cases;

  • Located in src/database or src/common/interceptors.
  • Utilize Prisma query events or middleware to measure execution time per query.
  • Log structured warnings with query parameters (sanitized) when duration exceeds the threshold (e.g., > 250ms).
  • Integrate with NestJS Logger service.

Acceptance Criteria — a checklist ("- [ ] ...") of specific, testable conditions that define "done".

  • Implement Prisma middleware or event listener to track query runtimes.
  • Configure threshold environment variable via NestJS ConfigModule.
  • Emit structured warning logs containing query execution duration and model operation.
  • Add unit tests verifying slow query detection and logging behavior.

Implementation Guidance — likely files/modules to touch and a suggested approach

  • Likely touch src/database/database.service.ts or create a new Prisma extension file under src/database/.
  • Ensure sensitive parameters in query args are masked or omitted in logs.

Testing & Validation — how the contributor should prove it works

  • Run npm test to verify no regressions.
  • Add unit tests mocking Prisma query execution with high latency.

Submission Guidelines — must open a PR that includes "Closes #"; assignment is required before starting; follow the repo's existing style and conventions.


Wave complexity: Medium

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions