0

Merge pull request #302 from mendableai/cjp/email-to-posthog-logging

Cjp/email to posthog logging
This commit is contained in:
Nicolas 2024-06-18 21:30:42 -04:00 committed by GitHub
commit c4252b6170
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 14 additions and 7 deletions

View File

@ -10,10 +10,12 @@ export async function validateIdempotencyKey(
// // not returning for missing idempotency key for now // // not returning for missing idempotency key for now
return true; return true;
} }
if (!isUuid(idempotencyKey)) { // Ensure idempotencyKey is treated as a string
console.error("Invalid idempotency key provided in the request headers."); const key = Array.isArray(idempotencyKey) ? idempotencyKey[0] : idempotencyKey;
return false; if (!isUuid(key)) {
} console.error("Invalid idempotency key provided in the request headers.");
return false;
}
const { data, error } = await supabase_service const { data, error } = await supabase_service
.from("idempotency_keys") .from("idempotency_keys")

View File

@ -32,8 +32,12 @@ export async function logJob(job: FirecrawlJob) {
]); ]);
if (process.env.POSTHOG_API_KEY) { if (process.env.POSTHOG_API_KEY) {
posthog.capture({
distinctId: job.team_id === "preview" ? null : job.team_id, let phLog = {
distinctId: "from-api", //* To identify this on the group level, setting distinctid to a static string per posthog docs: https://posthog.com/docs/product-analytics/group-analytics#advanced-server-side-only-capturing-group-events-without-a-user
...(job.team_id !== "preview" && {
groups: { team: job.team_id }
}), //* Identifying event on this team
event: "job-logged", event: "job-logged",
properties: { properties: {
success: job.success, success: job.success,
@ -49,7 +53,8 @@ export async function logJob(job: FirecrawlJob) {
extractor_options: job.extractor_options, extractor_options: job.extractor_options,
num_tokens: job.num_tokens num_tokens: job.num_tokens
}, },
}); }
posthog.capture(phLog);
} }
if (error) { if (error) {
console.error("Error logging job:\n", error); console.error("Error logging job:\n", error);