diff --git a/README.md b/README.md index 14d70a5..0aa9980 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/e2e/observability.spec.ts b/e2e/observability.spec.ts new file mode 100644 index 0000000..5fb3b67 --- /dev/null +++ b/e2e/observability.spec.ts @@ -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 }); +}); diff --git a/package.json b/package.json index 5cc4021..70194da 100644 --- a/package.json +++ b/package.json @@ -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" }, diff --git a/src/index.ts b/src/index.ts index 926a3fc..978a1bc 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,3 +1,4 @@ +import "./load-env.js"; import { initInstrumentation } from "./instrumentation/index.js"; initInstrumentation(); diff --git a/src/interfaces/http/routes.ts b/src/interfaces/http/routes.ts index 8f035f1..ceabeb3 100644 --- a/src/interfaces/http/routes.ts +++ b/src/interfaces/http/routes.ts @@ -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>(); diff --git a/src/load-env.ts b/src/load-env.ts new file mode 100644 index 0000000..48351c9 --- /dev/null +++ b/src/load-env.ts @@ -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; + } +}