From 5a91d8425f40828ab908a185fb8a0459bd7a56cd Mon Sep 17 00:00:00 2001 From: Caleb Peffer <44934913+calebpeffer@users.noreply.github.com> Date: Tue, 18 Jun 2024 17:07:38 -0700 Subject: [PATCH 1/2] Caleb: solve for typechecking on idempotencyKey on my machine --- apps/api/src/services/idempotency/validate.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/apps/api/src/services/idempotency/validate.ts b/apps/api/src/services/idempotency/validate.ts index ad6f2c4..1ca348b 100644 --- a/apps/api/src/services/idempotency/validate.ts +++ b/apps/api/src/services/idempotency/validate.ts @@ -10,10 +10,12 @@ export async function validateIdempotencyKey( // // not returning for missing idempotency key for now return true; } - if (!isUuid(idempotencyKey)) { - console.error("Invalid idempotency key provided in the request headers."); - return false; - } + // Ensure idempotencyKey is treated as a string + const key = Array.isArray(idempotencyKey) ? idempotencyKey[0] : idempotencyKey; + if (!isUuid(key)) { + console.error("Invalid idempotency key provided in the request headers."); + return false; + } const { data, error } = await supabase_service .from("idempotency_keys") From e59ba758f57f811a45aa258b7277d71f7b1263b7 Mon Sep 17 00:00:00 2001 From: Caleb Peffer <44934913+calebpeffer@users.noreply.github.com> Date: Tue, 18 Jun 2024 17:42:21 -0700 Subject: [PATCH 2/2] Caleb: changed posthog logging so that It associates jobs with a group. No --- apps/api/src/services/logging/log_job.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/api/src/services/logging/log_job.ts b/apps/api/src/services/logging/log_job.ts index 83e0bf3..6cb6ec3 100644 --- a/apps/api/src/services/logging/log_job.ts +++ b/apps/api/src/services/logging/log_job.ts @@ -32,8 +32,12 @@ export async function logJob(job: FirecrawlJob) { ]); 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", properties: { success: job.success, @@ -49,7 +53,8 @@ export async function logJob(job: FirecrawlJob) { extractor_options: job.extractor_options, num_tokens: job.num_tokens }, - }); + } + posthog.capture(phLog); } if (error) { console.error("Error logging job:\n", error);