From 83dd38db498c6a1a550c1bb01a1b0e245c57f276 Mon Sep 17 00:00:00 2001 From: Carlos Monastyrski Date: Mon, 7 Jul 2025 08:36:15 -0300 Subject: [PATCH] feat(telemetry): reduce TELEMETRY_AGGREGATED_KEY_EXP to 10 mins and avoid sending org identitfy events for batch events on sendPostHogEvents --- .../src/services/telemetry/telemetry-service.ts | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/backend/src/services/telemetry/telemetry-service.ts b/backend/src/services/telemetry/telemetry-service.ts index eaab5bec6..6dbd12ff5 100644 --- a/backend/src/services/telemetry/telemetry-service.ts +++ b/backend/src/services/telemetry/telemetry-service.ts @@ -14,7 +14,7 @@ export const TELEMETRY_SECRET_PROCESSED_KEY = "telemetry-secret-processed"; export const TELEMETRY_SECRET_OPERATIONS_KEY = "telemetry-secret-operations"; export const POSTHOG_AGGREGATED_EVENTS = [PostHogEventTypes.SecretPulled]; -const TELEMETRY_AGGREGATED_KEY_EXP = 900; // 15mins +const TELEMETRY_AGGREGATED_KEY_EXP = 600; // 10mins // Bucket configuration const TELEMETRY_BUCKET_COUNT = 30; @@ -102,13 +102,6 @@ To opt into telemetry, you can set "TELEMETRY_ENABLED=true" within the environme const instanceType = licenseService.getInstanceType(); // capture posthog only when its cloud or signup event happens in self-hosted if (instanceType === InstanceType.Cloud || event.event === PostHogEventTypes.UserSignedUp) { - if (event.organizationId) { - try { - postHog.groupIdentify({ groupType: "organization", groupKey: event.organizationId }); - } catch (error) { - logger.error(error, "Failed to identify PostHog organization"); - } - } if (POSTHOG_AGGREGATED_EVENTS.includes(event.event)) { const eventKey = createTelemetryEventKey(event.event, event.distinctId); await keyStore.setItemWithExpiry( @@ -122,6 +115,13 @@ To opt into telemetry, you can set "TELEMETRY_ENABLED=true" within the environme }) ); } else { + if (event.organizationId) { + try { + postHog.groupIdentify({ groupType: "organization", groupKey: event.organizationId }); + } catch (error) { + logger.error(error, "Failed to identify PostHog organization"); + } + } postHog.capture({ event: event.event, distinctId: event.distinctId,