Openstatus www.openstatus.dev
6
fork

Configure Feed

Select the types of activity you want to include in your feed.

๐Ÿ› rum (#788)

authored by

Thibault Le Ouay and committed by
GitHub
438383cd cc2985d4

+18 -21
+1 -2
apps/web/src/app/app/[workspaceSlug]/(dashboard)/rum/(overview)/_components/MetricCard.tsx
··· 10 10 const data = await api.rumRouter.GetEventMetricsForWorkspace.query({ 11 11 event: event, 12 12 }); 13 - console.log(data); 14 13 return ( 15 14 <Card> 16 15 <p className="text-tremor-default text-tremor-content dark:text-dark-tremor-content"> 17 16 {event} 18 17 </p> 19 18 <p className="text-tremor-content-strong dark:text-dark-tremor-content-strong text-3xl font-semibold"> 20 - {data.median} 19 + {data?.median || 0} 21 20 </p> 22 21 </Card> 23 22 );
+1 -5
packages/api/src/router/clerk/webhook.ts
··· 1 - import { customAlphabet } from "nanoid"; 2 - import { alphanumeric } from "nanoid-dictionary"; 3 1 import * as randomWordSlugs from "random-word-slugs"; 4 2 import * as z from "zod"; 5 3 ··· 53 51 slug = undefined; 54 52 } 55 53 } 56 - const lowercaseRandomString = customAlphabet(alphanumeric, 10); 57 54 58 - const dsn = `os_rum_${lowercaseRandomString}`; 59 55 const workspaceResult = await opts.ctx.db 60 56 .insert(workspace) 61 - .values({ slug, name: "", dsn }) 57 + .values({ slug, name: "" }) 62 58 .returning({ id: workspace.id }) 63 59 .get(); 64 60 await opts.ctx.db
+16 -14
packages/api/src/router/rum/index.ts
··· 14 14 .query(async (opts) => { 15 15 try { 16 16 const data = await opts.ctx.clickhouseClient.query({ 17 - query: `select 18 - event_name, 19 - quantile(0.5)(value) as median 20 - from 21 - cwv 22 - where 23 - dsn = '${opts.ctx.workspace.dsn}' 24 - and event_name = '${opts.input.event}' 25 - group by 26 - event_name 27 - `, 17 + query: ` 18 + select 19 + event_name, 20 + quantile(0.5)(value) as median 21 + from cwv 22 + where 23 + dsn = '${opts.ctx.workspace.dsn}' 24 + and event_name = '${opts.input.event}' 25 + group by event_name 26 + `, 28 27 format: "JSONEachRow", 29 28 }); 30 29 const result = await data.json(); 31 30 const schema = z.array( 32 31 z.object({ event_name: z.string(), median: z.number() }), 33 32 ); 34 - return schema.parse(result)[0]; 33 + if (!result) { 34 + return null; 35 + } 36 + const d = schema.parse(result); 37 + return d.length > 0 ? d[0] : null; 35 38 } catch (e) { 36 - console.error(e); 37 - throw e; 39 + return null; 38 40 } 39 41 }), 40 42 });