Openstatus www.openstatus.dev
6
fork

Configure Feed

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

chore: op improvements (#1137)

* fix: add user agent and location

* fix: api middleware event track

* chore: trpc metadata

authored by

Maximilian Kaske and committed by
GitHub
21049b27 fa07287a

+36 -101
+3 -1
apps/server/src/v1/middleware.ts
··· 55 55 await next(); 56 56 57 57 // REMINDER: only track the event if the request was successful 58 - if (!c.error) { 58 + const isValid = c.res.status.toString().startsWith("2") && !c.error; 59 + 60 + if (isValid) { 59 61 // We have checked the request to be valid already 60 62 let json: unknown; 61 63 if (c.req.raw.bodyUsed) {
-1
apps/web/src/components/forms/monitor/form.tsx
··· 111 111 112 112 const handleDataUpdateOrInsertion = async (props: InsertMonitor) => { 113 113 if (defaultValues) { 114 - console.log(props); 115 114 await api.monitor.update.mutate(props); 116 115 } else { 117 116 await api.monitor.create.mutate(props);
+3 -1
apps/web/src/content/posts/event-analytics-implementation.mdx
··· 148 148 export function trackMiddleware(event: EventProps) { 149 149 return async (c: Context<{ Variables: { user?: User } }, "/*">, next: Next) => { 150 150 await next(); 151 + 152 + const isValid = c.res.status.toString().startsWith("2") && !c.error; 151 153 152 - if (!c.error) { 154 + if (isValid) { 153 155 setTimeout(async () => { 154 156 const analytics = await setupAnalytics({ 155 157 profileId: c.get("user")?.id,
+1 -2
packages/analytics/package.json
··· 4 4 "description": "", 5 5 "main": "src/index.ts", 6 6 "dependencies": { 7 - "@jitsu/js": "1.9.2", 8 - "@openpanel/sdk": "^1.0.0", 7 + "@openpanel/sdk": "1.0.0", 9 8 "@t3-oss/env-core": "0.7.0", 10 9 "zod": "3.23.8" 11 10 },
+11
packages/analytics/src/server.ts
··· 18 18 email?: string; 19 19 workspaceId?: string; 20 20 plan?: string; 21 + // headers from the request 22 + location?: string; 23 + userAgent?: string; 21 24 }; 22 25 23 26 export async function setupAnalytics(props: IdentifyProps) { 24 27 if (process.env.NODE_ENV !== "production") { 25 28 return noop(); 29 + } 30 + 31 + if (props.location) { 32 + op.api.addHeader("x-client-ip", props.location); 33 + } 34 + 35 + if (props.userAgent) { 36 + op.api.addHeader("user-agent", props.userAgent); 26 37 } 27 38 28 39 if (props.userId) {
+17 -2
packages/api/src/trpc.ts
··· 32 32 workspace?: Workspace | null; 33 33 user?: User | null; 34 34 req?: NextRequest; 35 + metadata?: { 36 + userAgent?: string; 37 + location?: string; 38 + }; 35 39 }; 36 40 37 41 type Meta = { ··· 73 77 workspace, 74 78 user, 75 79 req: opts.req, 80 + metadata: { 81 + userAgent: opts.req.headers.get("user-agent") ?? undefined, 82 + location: 83 + opts.req.headers.get("x-forwarded-for") ?? 84 + process.env.VERCEL_REGION ?? 85 + undefined, 86 + }, 76 87 }); 77 88 }; 78 89 ··· 202 213 // REMINDER: We only track the event if the request was successful 203 214 // REMINDER: We are not blocking the request 204 215 after(async () => { 205 - const { meta, getRawInput } = opts; 216 + const { ctx, meta, getRawInput } = opts; 217 + 206 218 if (meta?.track) { 207 - let identify: IdentifyProps = {}; 219 + let identify: IdentifyProps = { 220 + userAgent: ctx.metadata?.userAgent, 221 + location: ctx.metadata?.location, 222 + }; 208 223 209 224 if (user && workspace) { 210 225 identify = {
+1 -94
pnpm-lock.yaml
··· 499 499 500 500 packages/analytics: 501 501 dependencies: 502 - '@jitsu/js': 503 - specifier: 1.9.2 504 - version: 1.9.2(@types/dlv@1.1.5) 505 502 '@openpanel/sdk': 506 - specifier: ^1.0.0 503 + specifier: 1.0.0 507 504 version: 1.0.0 508 505 '@t3-oss/env-core': 509 506 specifier: 0.7.0 ··· 1134 1131 resolution: {integrity: sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw==} 1135 1132 engines: {node: '>=6.0.0'} 1136 1133 1137 - '@analytics/cookie-utils@0.2.12': 1138 - resolution: {integrity: sha512-2h/yuIu3kmu+ZJlKmlT6GoRvUEY2k1BbQBezEv5kGhnn9KpmzPz715Y3GmM2i+m7Y0QmBdVUoA260dQZkofs2A==} 1139 - 1140 - '@analytics/core@0.12.7': 1141 - resolution: {integrity: sha512-etmIPCoxWLoUZ/o1o2zvIk4cdVHa8I1xUQtTuLA+YXQ4SsFbm75ZoMXJBqWrNSENpqCJgoL6hizl5uTbkNN+1Q==} 1142 - 1143 - '@analytics/global-storage-utils@0.1.7': 1144 - resolution: {integrity: sha512-V+spzGLZYm4biZT4uefaylm80SrLXf8WOTv9hCgA46cLcyxx3LD4GCpssp1lj+RcWLl/uXJQBRO4Mnn/o1x6Gw==} 1145 - 1146 - '@analytics/localstorage-utils@0.1.10': 1147 - resolution: {integrity: sha512-uJS+Jp1yLG5VFCgA5T82ZODYBS0xuDQx0NtAZrgbqt9j51BX3TcgmOez5LVkrUNu/lpbxjCLq35I4TKj78VmOQ==} 1148 - 1149 - '@analytics/session-storage-utils@0.0.7': 1150 - resolution: {integrity: sha512-PSv40UxG96HVcjY15e3zOqU2n8IqXnH8XvTkg1X43uXNTKVSebiI2kUjA3Q7ESFbw5DPwcLbJhV7GforpuBLDw==} 1151 - 1152 - '@analytics/storage-utils@0.4.2': 1153 - resolution: {integrity: sha512-AXObwyVQw9h2uJh1t2hUgabtVxzYpW+7uKVbdHQK80vr3Td5rrmCxrCxarh7HUuAgSDZ0bZWqmYxVgmwKceaLg==} 1154 - 1155 - '@analytics/type-utils@0.6.2': 1156 - resolution: {integrity: sha512-TD+xbmsBLyYy/IxFimW/YL/9L2IEnM7/EoV9Aeh56U64Ify8o27HJcKjo38XY9Tcn0uOq1AX3thkKgvtWvwFQg==} 1157 - 1158 1134 '@antfu/install-pkg@0.4.1': 1159 1135 resolution: {integrity: sha512-T7yB5QNG29afhWVkVq7XeIMBa5U/vs9mX69YqayXypPRmYzUmzwnYltplHmPtZ4HPCn+sQKeXW8I47wCbuBOjw==} 1160 1136 ··· 2761 2737 '@jest/schemas@29.6.3': 2762 2738 resolution: {integrity: sha512-mo5j5X+jIZmJQveBKeS/clAueipV7KgiX1vMgCxam1RNYiqE1w62n0/tJJnHtjW8ZHcQco5gY85jA3mi0L+nSA==} 2763 2739 engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0} 2764 - 2765 - '@jitsu/js@1.9.2': 2766 - resolution: {integrity: sha512-IFwVJczP/c9Lp5BFQZP5ebHgepbr5N1A+bE5m/CG1Sjekcr/oHuVtw1hjZFHJBa3eK6Gbn0Ax8Ih0LSPZkxiUg==} 2767 2740 2768 2741 '@jridgewell/gen-mapping@0.3.5': 2769 2742 resolution: {integrity: sha512-IzL8ZoEDIBRWEzlCcRhOaCupYyN5gdIK+Q6fbFdPDg6HqX6jpkItn7DFIpW9LQzXG6Df9sA7+OKnq0qlz/GaQg==} ··· 4980 4953 '@types/debug@4.1.10': 4981 4954 resolution: {integrity: sha512-tOSCru6s732pofZ+sMv9o4o3Zc+Sa8l3bxd/tweTQudFn06vAzb13ZX46Zi6m6EJ+RUbRTHvgQJ1gBtSgkaUYA==} 4982 4955 4983 - '@types/dlv@1.1.5': 4984 - resolution: {integrity: sha512-JHOWNfiWepAhfwlSw17kiWrWrk6od2dEQgHltJw9AS0JPFoLZJBge5+Dnil2NfdjAvJ/+vGSX60/BRW20PpUXw==} 4985 - 4986 4956 '@types/eslint-scope@3.7.7': 4987 4957 resolution: {integrity: sha512-MzMFlSLBqNF2gcHWO0G1vP/YQyfvrxZ0bF+u7mzUdZ1/xK4A4sru+nraZz5i3iEIk1l1uyicaDVTB4QbbEkAYg==} 4988 4958 ··· 5421 5391 5422 5392 ajv@8.17.1: 5423 5393 resolution: {integrity: sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==} 5424 - 5425 - analytics-utils@1.0.12: 5426 - resolution: {integrity: sha512-WvV2YWgsnXLxaY0QYux0crpBAg/0JA763NmbMVz22jKhMPo7dpTBet8G2IlF7ixTjLDzGlkHk1ZaKqqQmjJ+4w==} 5427 - peerDependencies: 5428 - '@types/dlv': ^1.0.0 5429 - 5430 - analytics@0.8.9: 5431 - resolution: {integrity: sha512-oTbUzQpncMTslakqfK70GgB6bopk5hY+uuekwnadMkDyqNLgcD02KRzteTnO7q5Ko6wDECVtT8xi/6OuAMZykA==} 5432 5394 5433 5395 ansi-align@3.0.1: 5434 5396 resolution: {integrity: sha512-IOfwwBF5iczOjp/WeY4YxyjqAFMQoZufdQWDd19SEExbVLNXqvpzSJ/M7Za4/sCPmQ0+GRquoA7bGcINcxew6w==} ··· 10344 10306 '@jridgewell/gen-mapping': 0.3.5 10345 10307 '@jridgewell/trace-mapping': 0.3.25 10346 10308 10347 - '@analytics/cookie-utils@0.2.12': 10348 - dependencies: 10349 - '@analytics/global-storage-utils': 0.1.7 10350 - 10351 - '@analytics/core@0.12.7(@types/dlv@1.1.5)': 10352 - dependencies: 10353 - '@analytics/global-storage-utils': 0.1.7 10354 - '@analytics/type-utils': 0.6.2 10355 - analytics-utils: 1.0.12(@types/dlv@1.1.5) 10356 - transitivePeerDependencies: 10357 - - '@types/dlv' 10358 - 10359 - '@analytics/global-storage-utils@0.1.7': 10360 - dependencies: 10361 - '@analytics/type-utils': 0.6.2 10362 - 10363 - '@analytics/localstorage-utils@0.1.10': 10364 - dependencies: 10365 - '@analytics/global-storage-utils': 0.1.7 10366 - 10367 - '@analytics/session-storage-utils@0.0.7': 10368 - dependencies: 10369 - '@analytics/global-storage-utils': 0.1.7 10370 - 10371 - '@analytics/storage-utils@0.4.2': 10372 - dependencies: 10373 - '@analytics/cookie-utils': 0.2.12 10374 - '@analytics/global-storage-utils': 0.1.7 10375 - '@analytics/localstorage-utils': 0.1.10 10376 - '@analytics/session-storage-utils': 0.0.7 10377 - '@analytics/type-utils': 0.6.2 10378 - 10379 - '@analytics/type-utils@0.6.2': {} 10380 - 10381 10309 '@antfu/install-pkg@0.4.1': 10382 10310 dependencies: 10383 10311 package-manager-detector: 0.2.4 ··· 12196 12124 '@jest/schemas@29.6.3': 12197 12125 dependencies: 12198 12126 '@sinclair/typebox': 0.27.8 12199 - 12200 - '@jitsu/js@1.9.2(@types/dlv@1.1.5)': 12201 - dependencies: 12202 - analytics: 0.8.9(@types/dlv@1.1.5) 12203 - transitivePeerDependencies: 12204 - - '@types/dlv' 12205 12127 12206 12128 '@jridgewell/gen-mapping@0.3.5': 12207 12129 dependencies: ··· 14863 14785 dependencies: 14864 14786 '@types/ms': 0.7.33 14865 14787 14866 - '@types/dlv@1.1.5': {} 14867 - 14868 14788 '@types/eslint-scope@3.7.7': 14869 14789 dependencies: 14870 14790 '@types/eslint': 9.6.1 ··· 15458 15378 fast-uri: 3.0.3 15459 15379 json-schema-traverse: 1.0.0 15460 15380 require-from-string: 2.0.2 15461 - 15462 - analytics-utils@1.0.12(@types/dlv@1.1.5): 15463 - dependencies: 15464 - '@analytics/type-utils': 0.6.2 15465 - '@types/dlv': 1.1.5 15466 - dlv: 1.1.3 15467 - 15468 - analytics@0.8.9(@types/dlv@1.1.5): 15469 - dependencies: 15470 - '@analytics/core': 0.12.7(@types/dlv@1.1.5) 15471 - '@analytics/storage-utils': 0.4.2 15472 - transitivePeerDependencies: 15473 - - '@types/dlv' 15474 15381 15475 15382 ansi-align@3.0.1: 15476 15383 dependencies: