Skip to content

Open-source status page, incident response and uptime monitoring

claude: fix oom (#1729)

Thibault Le Ouayd62a189e7057
diff --git a/apps/server/src/libs/middlewares/track.ts b/apps/server/src/libs/middlewares/track.ts
index a777e1a39..38672af48 100644
--- a/apps/server/src/libs/middlewares/track.ts
+++ b/apps/server/src/libs/middlewares/track.ts
@@ -1,4 +1,5 @@
import type { Variables } from "@/types";
+import { getLogger } from "@logtape/logtape";
import {
type EventProps,
parseInputToProps,
@@ -6,6 +7,8 @@ import {
} from "@openstatus/analytics";
import type { Context, Next } from "hono";
+const logger = getLogger("api-server");
+
export function trackMiddleware(event: EventProps, eventProps?: string[]) {
return async (c: Context<{ Variables: Variables }, "/*">, next: Next) => {
await next();
@@ -26,17 +29,20 @@ export function trackMiddleware(event: EventProps, eventProps?: string[]) {
const additionalProps = parseInputToProps(json, eventProps);
const workspace = c.get("workspace");
- // REMINDER: use setTimeout to avoid blocking the response
- setTimeout(async () => {
- const analytics = await setupAnalytics({
- userId: `api_${workspace.id}`,
- workspaceId: `${workspace.id}`,
- plan: workspace.plan,
- location: c.req.raw.headers.get("x-forwarded-for") ?? undefined,
- userAgent: c.req.raw.headers.get("user-agent") ?? undefined,
+ setupAnalytics({
+ userId: `api_${workspace.id}`,
+ workspaceId: `${workspace.id}`,
+ plan: workspace.plan,
+ location: c.req.raw.headers.get("x-forwarded-for") ?? undefined,
+ userAgent: c.req.raw.headers.get("user-agent") ?? undefined,
+ })
+ .then((analytics) => analytics.track({ ...event, additionalProps }))
+ .catch(() => {
+ logger.warn(
+ "Failed to send analytics event {event} for workspace {workspaceId}",
+ { event: event.name, workspaceId: workspace.id },
+ );
});
- await analytics.track({ ...event, additionalProps });
- }, 0);
}
};
}