MCPcopy Create free account
hub / github.com/hashintel/hash / setupTelemetryHandler

Function setupTelemetryHandler

apps/hash-api/src/telemetry/telemetry-endpoint.ts:85–112  ·  view source on GitHub ↗
(app: Express)

Source from the content-addressed store, hash-verified

83 * never trusted.
84 */
85export const setupTelemetryHandler = (app: Express) => {
86 app.post("/api/telemetry", telemetryRateLimiter, (req: Request, res) => {
87 const body = req.body as Partial<TelemetryRequest> | undefined;
88
89 if (!body || !Array.isArray(body.events)) {
90 res.status(400).json({ error: "Request body must be { events: [...] }" });
91 return;
92 }
93
94 if (body.events.length > MAX_EVENTS_PER_BATCH) {
95 res
96 .status(400)
97 .json({ error: `Too many events (max ${MAX_EVENTS_PER_BATCH})` });
98 return;
99 }
100
101 const events = body.events
102 .map(parseTelemetryEvent)
103 .filter((event): event is FrontendTelemetryEvent => event !== null);
104
105 const anonymousId =
106 typeof body.anonymousId === "string" ? body.anonymousId : undefined;
107
108 telemetry.trackFromClient(req, { anonymousId, events });
109
110 res.status(204).end();
111 });
112};

Callers 1

mainFunction · 0.90

Calls 5

jsonMethod · 0.80
trackFromClientMethod · 0.80
filterMethod · 0.45
mapMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected