Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.
TypeScript acmeagentsai-agentscertificate-managementdevsecopsenvironment-variableskubernetesopen-sourcepampkipostgresprivate-caprivileged-access-managementsecret-managementsecret-managersecretssecrets-managementsecuritysecurity-toolsvault
feat: enable full PostHog telemetry for all instance types and pass organizationId on signup
Devin AI71189ba88baa
diff --git a/backend/src/lib/config/env.ts b/backend/src/lib/config/env.tsindex 8351beb41c..3562976bd6 100644--- a/backend/src/lib/config/env.ts+++ b/backend/src/lib/config/env.ts@@ -292,6 +292,9 @@ const envSchema = z.enum(["true", "false"]).transform((val) => val === "true" || IS_PACKAGED).optional(),+ // WARNING: Infisical-managed only. Do not set on self-hosted deployments.+ // When true, enables full PostHog telemetry including user PII (emails, usernames)+ // sent to Infisical's cloud PostHog project. Used for Cloud and dedicated cloud instances.INFISICAL_CLOUD: zodStrBool.default("false"),MAINTENANCE_MODE: zodStrBool.default("false"),CAPTCHA_SECRET: zpStr(z.string().optional()),diff --git a/backend/src/server/routes/v3/signup-router.ts b/backend/src/server/routes/v3/signup-router.tsindex ab3431ae6a..efa31814da 100644--- a/backend/src/server/routes/v3/signup-router.ts+++ b/backend/src/server/routes/v3/signup-router.ts@@ -157,6 +157,7 @@ export const registerSignupRouter = async (server: FastifyZodProvider) => {void server.services.telemetry.sendPostHogEvents({event: PostHogEventTypes.UserSignedUp,distinctId: user.username ?? "",+ ...(organizationId ? { organizationId } : {}),properties: {username: user.username,email: user.email ?? "",diff --git a/backend/src/services/telemetry/telemetry-service.ts b/backend/src/services/telemetry/telemetry-service.tsindex 0eac5be1b4..2f67922882 100644--- a/backend/src/services/telemetry/telemetry-service.ts+++ b/backend/src/services/telemetry/telemetry-service.ts@@ -185,61 +185,11 @@ To opt into telemetry, you can set "TELEMETRY_ENABLED=true" within the environme};const sendPostHogEvents = async (event: TPostHogEvent) => {- if (postHog) {- const instanceType = licenseService.getInstanceType();-- // Resolve org name: prefer explicit value, fall back to request context- const resolvedOrgName = event.organizationName ?? requestContext.get("orgName");-- // capture posthog only when its cloud or signup event happens in self-hosted- if (instanceType === InstanceType.Cloud || event.event === PostHogEventTypes.UserSignedUp) {- if (POSTHOG_AGGREGATED_EVENTS.includes(event.event)) {- const eventKey = createTelemetryEventKey(event.event, event.distinctId);- await keyStore.setItemWithExpiry(- eventKey,- TELEMETRY_AGGREGATED_KEY_EXP,- JSON.stringify({- distinctId: event.distinctId,- event: event.event,- properties: event.properties,- organizationId: event.organizationId,- ...(resolvedOrgName ? { organizationName: resolvedOrgName } : {})- })- );- } else {- if (event.organizationId) {- const orgId = event.organizationId;- // Dedup groupIdentify: only fire once per org per hour to avoid redundant DB/API calls- const groupIdentifyCacheKey = KeyStorePrefixes.TelemetryGroupIdentify(orgId);- void keyStore- .setItemWithExpiryNX(groupIdentifyCacheKey, GROUP_IDENTIFY_CACHE_TTL, "1")- .then((wasSet) => {- if (wasSet) {- return getOrgGroupProperties(orgId, resolvedOrgName).then((groupProperties) => {- postHog.groupIdentify({- groupType: "organization",- groupKey: orgId,- properties: groupProperties,- distinctId: event.distinctId- });- });- }- return undefined;- })- .catch((error) => {- logger.error(error, "Failed to identify PostHog organization");- });- }- postHog.capture({- event: event.event,- distinctId: event.distinctId,- properties: event.properties,- ...(event.organizationId ? { groups: { organization: event.organizationId } } : {})- });- }- return;- }-+ // Track secret operation counters in Redis for TelemetryInstanceStats (non-cloud only).+ // Only increment when a PostHog client is available, since the TelemetryInstanceStats+ // cleanup job that reads and deletes these counters is only scheduled when postHog+ // is defined. Without this gate, counters would accumulate indefinitely in Redis.+ if (!appCfg.INFISICAL_CLOUD && postHog) {if ([PostHogEventTypes.SecretPulled,@@ -255,6 +205,56 @@ To opt into telemetry, you can set "TELEMETRY_ENABLED=true" within the environmeawait keyStore.incrementBy(TELEMETRY_SECRET_OPERATIONS_KEY, 1);}}++ if (!postHog) return;++ // Resolve org name: prefer explicit value, fall back to request context+ const resolvedOrgName = event.organizationName ?? requestContext.get("orgName");++ if (POSTHOG_AGGREGATED_EVENTS.includes(event.event)) {+ const eventKey = createTelemetryEventKey(event.event, event.distinctId);+ await keyStore.setItemWithExpiry(+ eventKey,+ TELEMETRY_AGGREGATED_KEY_EXP,+ JSON.stringify({+ distinctId: event.distinctId,+ event: event.event,+ properties: event.properties,+ organizationId: event.organizationId,+ ...(resolvedOrgName ? { organizationName: resolvedOrgName } : {})+ })+ );+ } else {+ if (event.organizationId) {+ const orgId = event.organizationId;+ // Dedup groupIdentify: only fire once per org per hour to avoid redundant DB/API calls+ const groupIdentifyCacheKey = KeyStorePrefixes.TelemetryGroupIdentify(orgId);+ void keyStore+ .setItemWithExpiryNX(groupIdentifyCacheKey, GROUP_IDENTIFY_CACHE_TTL, "1")+ .then((wasSet) => {+ if (wasSet) {+ return getOrgGroupProperties(orgId, resolvedOrgName).then((groupProperties) => {+ postHog.groupIdentify({+ groupType: "organization",+ groupKey: orgId,+ properties: groupProperties,+ distinctId: event.distinctId+ });+ });+ }+ return undefined;+ })+ .catch((error) => {+ logger.error(error, "Failed to identify PostHog organization");+ });+ }+ postHog.capture({+ event: event.event,+ distinctId: event.distinctId,+ properties: event.properties,+ ...(event.organizationId ? { groups: { organization: event.organizationId } } : {})+ });+ }};const aggregateGroupProperties = (events: SingleEventData[]): AggregatedEventData => {@@ -456,32 +456,26 @@ To opt into telemetry, you can set "TELEMETRY_ENABLED=true" within the environme{ skipDedup }: { skipDedup?: boolean } = {}) => {if (postHog && distinctId) {- const instanceType = licenseService.getInstanceType();- if (instanceType === InstanceType.Cloud) {- if (!skipDedup) {- try {- const cacheKey = `${TELEMETRY_IDENTIFY_CACHE_KEY_PREFIX}:${distinctId}`;- // Atomic SET NX + EX: only the first caller within the TTL window proceeds- const wasSet = await keyStore.setItemWithExpiryNX(cacheKey, TELEMETRY_IDENTIFY_CACHE_TTL, "1");- if (!wasSet) return;- } catch (error) {- logger.error(error, `Failed to check PostHog identify dedup cache for distinctId=${distinctId}`);- // In-memory fallback to limit blast radius during Redis outage- if (inMemoryIdentifyDedup.has(distinctId)) return;- inMemoryIdentifyDedup.add(distinctId);- const timer = setTimeout(- () => inMemoryIdentifyDedup.delete(distinctId),- IN_MEMORY_IDENTIFY_FALLBACK_TTL_MS- );- timer.unref();- }- }+ if (!skipDedup) {try {- postHog.identify({ distinctId, properties });- } catch (err) {- logger.error(err, `Failed to call postHog.identify for distinctId=${distinctId}`);+ const cacheKey = `${TELEMETRY_IDENTIFY_CACHE_KEY_PREFIX}:${distinctId}`;+ // Atomic SET NX + EX: only the first caller within the TTL window proceeds+ const wasSet = await keyStore.setItemWithExpiryNX(cacheKey, TELEMETRY_IDENTIFY_CACHE_TTL, "1");+ if (!wasSet) return;+ } catch (error) {+ logger.error(error, `Failed to check PostHog identify dedup cache for distinctId=${distinctId}`);+ // In-memory fallback to limit blast radius during Redis outage+ if (inMemoryIdentifyDedup.has(distinctId)) return;+ inMemoryIdentifyDedup.add(distinctId);+ const timer = setTimeout(() => inMemoryIdentifyDedup.delete(distinctId), IN_MEMORY_IDENTIFY_FALLBACK_TTL_MS);+ timer.unref();}}+ try {+ postHog.identify({ distinctId, properties });+ } catch (err) {+ logger.error(err, `Failed to call postHog.identify for distinctId=${distinctId}`);+ }}};@@ -496,39 +490,36 @@ To opt into telemetry, you can set "TELEMETRY_ENABLED=true" within the environme}) => {if (postHog && identityId) {- const instanceType = licenseService.getInstanceType();- if (instanceType === InstanceType.Cloud) {- const dedupKey = `${identityId}-${properties.authMethod ?? ""}`;- try {- const cacheKey = KeyStorePrefixes.TelemetryIdentifyIdentity(dedupKey);- // Atomic SET NX + EX: only the first caller within the TTL window proceeds- const wasSet = await keyStore.setItemWithExpiryNX(- cacheKey,- KeyStoreTtls.TelemetryIdentifyIdentityInSeconds,- "1"- );- if (!wasSet) return;- } catch (error) {- logger.error(error, `Failed to check PostHog identity dedup cache [identityId=${identityId}]`);- // In-memory fallback to limit blast radius during Redis outage- if (inMemoryIdentityDedup.has(dedupKey)) return;- inMemoryIdentityDedup.add(dedupKey);- const timer = setTimeout(() => inMemoryIdentityDedup.delete(dedupKey), IN_MEMORY_IDENTIFY_FALLBACK_TTL_MS);- timer.unref();- // falls through intentionally: first caller during Redis outage still identifies- }+ const dedupKey = `${identityId}-${properties.authMethod ?? ""}`;+ try {+ const cacheKey = KeyStorePrefixes.TelemetryIdentifyIdentity(dedupKey);+ // Atomic SET NX + EX: only the first caller within the TTL window proceeds+ const wasSet = await keyStore.setItemWithExpiryNX(+ cacheKey,+ KeyStoreTtls.TelemetryIdentifyIdentityInSeconds,+ "1"+ );+ if (!wasSet) return;+ } catch (error) {+ logger.error(error, `Failed to check PostHog identity dedup cache [identityId=${identityId}]`);+ // In-memory fallback to limit blast radius during Redis outage+ if (inMemoryIdentityDedup.has(dedupKey)) return;+ inMemoryIdentityDedup.add(dedupKey);+ const timer = setTimeout(() => inMemoryIdentityDedup.delete(dedupKey), IN_MEMORY_IDENTIFY_FALLBACK_TTL_MS);+ timer.unref();+ // falls through intentionally: first caller during Redis outage still identifies+ }- const distinctId = `identity-${identityId}`;- const enrichedProperties = {- ...properties,- actorType: ActorType.IDENTITY,- ...(properties.name ? { name: `[Machine Identity] ${properties.name}` } : {})- };- try {- postHog.identify({ distinctId, properties: enrichedProperties });- } catch (err) {- logger.error(err, `Failed to call postHog.identify for machine identity [identityId=${identityId}]`);- }+ const distinctId = `identity-${identityId}`;+ const enrichedProperties = {+ ...properties,+ actorType: ActorType.IDENTITY,+ ...(properties.name ? { name: `[Machine Identity] ${properties.name}` } : {})+ };+ try {+ postHog.identify({ distinctId, properties: enrichedProperties });+ } catch (err) {+ logger.error(err, `Failed to call postHog.identify for machine identity [identityId=${identityId}]`);}}};