feat: add telemetry event payload
This commit is contained in:
parent
503321d43b
commit
dc77c4f85a
@ -14,7 +14,6 @@
|
||||
"build:openapi": "ts-node scripts/build-openapi-schema.ts",
|
||||
"postinstall": "pnpm db:generate",
|
||||
"check:type": "tsc --noEmit --skipLibCheck --module esnext",
|
||||
"db:push": "prisma db push",
|
||||
"db:generate": "prisma generate",
|
||||
"db:migrate:dev": "prisma migrate dev",
|
||||
"db:migrate:apply": "prisma migrate deploy",
|
||||
|
@ -0,0 +1,2 @@
|
||||
-- AlterTable
|
||||
ALTER TABLE "TelemetryEvent" ADD COLUMN "payload" JSON;
|
@ -205,6 +205,7 @@ model TelemetryEvent {
|
||||
eventName String? @db.VarChar(100)
|
||||
urlOrigin String @db.VarChar(500)
|
||||
urlPath String @db.VarChar(500)
|
||||
payload Json? @db.Json // Other payload info get from query params, should be a object
|
||||
createdAt DateTime @default(now()) @db.Timestamptz(6)
|
||||
|
||||
session TelemetrySession @relation(fields: [sessionId], references: [id], onUpdate: Cascade, onDelete: Cascade)
|
||||
|
@ -5,11 +5,12 @@ import { getRequestInfo } from '../utils/detect';
|
||||
import { prisma } from './_client';
|
||||
|
||||
export async function recordTelemetryEvent(req: Request) {
|
||||
const url = req.query.url ?? req.headers.referer;
|
||||
const { url = req.headers.referer, name, ...others } = req.query;
|
||||
|
||||
if (!(url && typeof url === 'string')) {
|
||||
return;
|
||||
}
|
||||
const eventName = req.query.name ? String(req.query.name) : undefined;
|
||||
const eventName = name ? String(name) : undefined;
|
||||
|
||||
const session = await findSession(req, url);
|
||||
if (!session) {
|
||||
@ -22,6 +23,7 @@ export async function recordTelemetryEvent(req: Request) {
|
||||
}
|
||||
|
||||
const { origin, pathname } = new URL(url);
|
||||
const payload = Object.keys(others).length > 0 ? others : undefined;
|
||||
|
||||
await prisma.telemetryEvent.create({
|
||||
data: {
|
||||
@ -30,6 +32,7 @@ export async function recordTelemetryEvent(req: Request) {
|
||||
eventName,
|
||||
urlOrigin: origin,
|
||||
urlPath: pathname,
|
||||
payload,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user