mirror of
https://github.com/mauricioabh/arbpulse.git
synced 2026-07-27 15:47:43 +00:00
Add Sentry dev probe and observability smoke test.
GET /api/debug/sentry, load .env.local for DSN, Playwright observability spec. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -347,7 +347,7 @@ Eso no indica que el bot “no funcione”: indica que el filtro económico es e
|
||||
|
||||
- **Pre-commit:** Husky runs lint-staged (`eslint --fix`, `prettier --write`) on staged `*.ts` / `*.tsx` in `src/` and `web/src/`.
|
||||
- **API contracts:** Zod schemas per REST endpoint → OpenAPI via `@asteasolutions/zod-to-openapi` → Scalar UI at `/api-docs`. Request bodies validated with Zod in route handlers.
|
||||
- **Observability:** `@sentry/node` captures REST, WebSocket feed, and SSE errors; `pino` JSON logs with `correlationId` (from `x-request-id` or per book tick); OpenTelemetry spans (`ws.message` → `orderbook.process` → `arbitrage.evaluate` → `sse.broadcast`) export to Sentry via `@sentry/opentelemetry` when `SENTRY_DSN` is set.
|
||||
- **Observability:** `@sentry/node` captures REST, WebSocket feed, and SSE errors; `pino` JSON logs with `correlationId` (from `x-request-id` or per book tick); OpenTelemetry spans (`ws.message` → `orderbook.process` → `arbitrage.evaluate` → `sse.broadcast`) export to Sentry via `@sentry/opentelemetry` when `SENTRY_DSN` is set. Dev probe: `GET /api/debug/sentry`; verify with `npm run test:observability`.
|
||||
- **Rate limiting & cache:** Upstash sliding-window limits per IP on read/write/SSE routes (`429` + `Retry-After`). Latest `StateSnapshot` cached in Redis (~1s TTL) for `GET /api/state` and refreshed on SSE broadcast. Set `UPSTASH_REDIS_REST_URL` and `UPSTASH_REDIS_REST_TOKEN`.
|
||||
- **CI:** GitHub Actions quality pipeline (typecheck, unit tests, build); Playwright smoke on PRs — dashboard loads and SSE connects (`npm run test:e2e`, workflow `e2e.yml`, `DEMO_MODE=true` in CI).
|
||||
- **Security scanning:** CodeQL (`.github/workflows/codeql.yml`); Dependabot for npm (root + `web/`) and GitHub Actions.
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
import { test, expect } from "@playwright/test";
|
||||
|
||||
/** Asserts the dev Sentry probe responds; does not verify ingest in sentry.io (see README). */
|
||||
test("sentry dev probe returns ok", async ({ request }) => {
|
||||
const res = await request.get("/api/debug/sentry");
|
||||
expect(res.ok()).toBeTruthy();
|
||||
await expect(res.json()).resolves.toMatchObject({ ok: true });
|
||||
});
|
||||
@@ -14,6 +14,7 @@
|
||||
"typecheck": "tsc --noEmit && npm --prefix web run typecheck",
|
||||
"test": "node scripts/run-tests.mjs",
|
||||
"test:e2e": "playwright test",
|
||||
"test:observability": "playwright test observability.spec.ts",
|
||||
"lint": "eslint .",
|
||||
"prepare": "husky"
|
||||
},
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import "./load-env.js";
|
||||
import { initInstrumentation } from "./instrumentation/index.js";
|
||||
|
||||
initInstrumentation();
|
||||
|
||||
@@ -4,6 +4,7 @@ import {
|
||||
type Request,
|
||||
type Response,
|
||||
} from "express";
|
||||
import { Sentry } from "../../instrumentation/sentry.js";
|
||||
import type { ApplicationService } from "../../composition/application-service.js";
|
||||
import {
|
||||
bindRequestCorrelation,
|
||||
@@ -39,6 +40,15 @@ export function createRouter(app: ApplicationService, sse: SseHub): Router {
|
||||
res.json({ success: true, data: { status: "ok", ts: Date.now() } });
|
||||
});
|
||||
|
||||
router.get("/debug/sentry", (_req: Request, res: Response) => {
|
||||
if (process.env.NODE_ENV === "production") {
|
||||
res.status(404).json({ error: "Not found" });
|
||||
return;
|
||||
}
|
||||
Sentry.captureException(new Error("Arb Pulse Sentry test error"));
|
||||
res.json({ ok: true, message: "Test error sent to Sentry" });
|
||||
});
|
||||
|
||||
router.get("/state", async (_req: Request, res: Response) => {
|
||||
const cached =
|
||||
await getCachedSnapshot<ReturnType<ApplicationService["getSnapshot"]>>();
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import { existsSync } from "node:fs";
|
||||
import { loadEnvFile } from "node:process";
|
||||
|
||||
for (const file of [".env.local", ".env"]) {
|
||||
if (existsSync(file)) {
|
||||
loadEnvFile(file);
|
||||
break;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user