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: add PostHog telemetry events for honey tokens
Devin AI76f4dadae3a2
diff --git a/backend/src/ee/routes/v1/honey-token-router.ts b/backend/src/ee/routes/v1/honey-token-router.tsindex 9616a267e2..582110275a 100644--- a/backend/src/ee/routes/v1/honey-token-router.ts+++ b/backend/src/ee/routes/v1/honey-token-router.ts@@ -9,8 +9,10 @@ import {} from "@app/ee/services/honey-token/honey-token-provider-fns";import { readLimit, writeLimit } from "@app/server/config/rateLimiter";import { slugSchema } from "@app/server/lib/schemas";+import { getTelemetryDistinctId } from "@app/server/lib/telemetry";import { verifyAuth } from "@app/server/plugins/auth/verify-auth";import { AuthMode } from "@app/services/auth/auth-type";+import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";const HoneyTokenResponseSchema = HoneyTokensSchema.pick({id: true,@@ -137,6 +139,21 @@ export const registerHoneyTokenGenericRouter = async (server: FastifyZodProvider}});+ await server.services.telemetry+ .sendPostHogEvents({+ event: PostHogEventTypes.HoneyTokenCreated,+ distinctId: getTelemetryDistinctId(req),+ organizationId: req.permission.orgId,+ properties: {+ honeyTokenId: honeyToken.id,+ type: honeyToken.type,+ projectId: honeyToken.projectId,+ environment: req.body.environment,+ secretPath: req.body.secretPath+ }+ })+ .catch(() => {});+return { honeyToken, stackDeployment };}});@@ -216,6 +233,19 @@ export const registerHoneyTokenGenericRouter = async (server: FastifyZodProvider}});+ await server.services.telemetry+ .sendPostHogEvents({+ event: PostHogEventTypes.HoneyTokenUpdated,+ distinctId: getTelemetryDistinctId(req),+ organizationId: req.permission.orgId,+ properties: {+ honeyTokenId: honeyToken.id,+ type: honeyToken.type,+ projectId: honeyToken.projectId+ }+ })+ .catch(() => {});+return { honeyToken };}});@@ -242,6 +272,19 @@ export const registerHoneyTokenGenericRouter = async (server: FastifyZodProvider{ honeyTokenId: req.params.id },req.permission);+ await server.services.telemetry+ .sendPostHogEvents({+ event: PostHogEventTypes.HoneyTokenReset,+ distinctId: getTelemetryDistinctId(req),+ organizationId: req.permission.orgId,+ properties: {+ honeyTokenId: honeyToken.id,+ type: honeyToken.type,+ projectId: honeyToken.projectId+ }+ })+ .catch(() => {});+return {honeyToken: {id: honeyToken.id,@@ -290,6 +333,19 @@ export const registerHoneyTokenGenericRouter = async (server: FastifyZodProvider}});+ await server.services.telemetry+ .sendPostHogEvents({+ event: PostHogEventTypes.HoneyTokenRevoked,+ distinctId: getTelemetryDistinctId(req),+ organizationId: req.permission.orgId,+ properties: {+ honeyTokenId,+ type: honeyToken.type,+ projectId: honeyToken.projectId+ }+ })+ .catch(() => {});+return { honeyTokenId };}});diff --git a/backend/src/ee/services/honey-token/honey-token-service.ts b/backend/src/ee/services/honey-token/honey-token-service.tsindex 20d5aec137..3761480e75 100644--- a/backend/src/ee/services/honey-token/honey-token-service.ts+++ b/backend/src/ee/services/honey-token/honey-token-service.ts@@ -24,6 +24,8 @@ import { TResourceMetadataDALFactory } from "@app/services/resource-metadata/resimport { TSecretQueueFactory } from "@app/services/secret/secret-queue";import { TSecretFolderDALFactory } from "@app/services/secret-folder/secret-folder-dal";import { TSecretTagDALFactory } from "@app/services/secret-tag/secret-tag-dal";+import { TTelemetryServiceFactory } from "@app/services/telemetry/telemetry-service";+import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";import { TSecretV2BridgeDALFactory } from "@app/services/secret-v2-bridge/secret-v2-bridge-dal";import { fnSecretBulkDelete, fnSecretBulkInsert } from "@app/services/secret-v2-bridge/secret-v2-bridge-fns";import { TSecretVersionV2DALFactory } from "@app/services/secret-v2-bridge/secret-version-dal";@@ -106,6 +108,7 @@ export type THoneyTokenServiceFactoryDep = {resourceMetadataDAL: Pick<TResourceMetadataDALFactory, "insertMany">;snapshotService: Pick<TSecretSnapshotServiceFactory, "performSnapshot">;secretQueueService: Pick<TSecretQueueFactory, "syncSecrets" | "removeSecretReminder">;+ telemetryService: Pick<TTelemetryServiceFactory, "sendPostHogEvents">;};type TSendTriggerNotificationInput = {@@ -146,7 +149,8 @@ export const honeyTokenServiceFactory = ({folderCommitService,resourceMetadataDAL,snapshotService,- secretQueueService+ secretQueueService,+ telemetryService}: THoneyTokenServiceFactoryDep) => {const honeyTokenProviderHooksByType = getHoneyTokenServiceHooksByType({honeyTokenDAL,@@ -169,7 +173,8 @@ export const honeyTokenServiceFactory = ({folderCommitService,resourceMetadataDAL,snapshotService,- secretQueueService+ secretQueueService,+ telemetryService});const create = async (@@ -1021,6 +1026,18 @@ export const honeyTokenServiceFactory = ({);if (updatedToken) {void $sendTriggerNotification({ orgId: honeyTokenWithOrg.orgId, honeyToken, eventMetadata: parsed.data });+ void telemetryService+ .sendPostHogEvents({+ event: PostHogEventTypes.HoneyTokenTriggered,+ distinctId: `honey-token-${honeyToken.id}`,+ organizationId: honeyTokenWithOrg.orgId,+ properties: {+ honeyTokenId: honeyToken.id,+ type: honeyToken.type,+ projectId: honeyToken.projectId+ }+ })+ .catch(() => {});}}/* eslint-enable no-continue */diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.tsindex a39b55c7a3..18193ad83a 100644--- a/backend/src/server/routes/index.ts+++ b/backend/src/server/routes/index.ts@@ -2375,7 +2375,8 @@ export const registerRoutes = async (resourceMetadataDAL,snapshotService,secretQueueService,- appConnectionService+ appConnectionService,+ telemetryService});const webhookService = webhookServiceFactory({diff --git a/backend/src/services/telemetry/telemetry-types.ts b/backend/src/services/telemetry/telemetry-types.tsindex 07472116de..78ddf6ac98 100644--- a/backend/src/services/telemetry/telemetry-types.ts+++ b/backend/src/services/telemetry/telemetry-types.ts@@ -108,7 +108,13 @@ export enum PostHogEventTypes {PamRotationRuleDeleted = "PAM Rotation Rule Deleted",ResourceAuthMethodLogin = "Resource Auth Method Login",- ResourceAuthMethodUpdated = "Resource Auth Method Updated"+ ResourceAuthMethodUpdated = "Resource Auth Method Updated",++ HoneyTokenCreated = "Honey Token Created",+ HoneyTokenUpdated = "Honey Token Updated",+ HoneyTokenRevoked = "Honey Token Revoked",+ HoneyTokenReset = "Honey Token Reset",+ HoneyTokenTriggered = "Honey Token Triggered"}export type TSecretModifiedEvent = {@@ -836,6 +842,53 @@ export type TResourceAuthMethodEvent = {};};+export type THoneyTokenCreatedEvent = {+ event: PostHogEventTypes.HoneyTokenCreated;+ properties: {+ honeyTokenId: string;+ type: string;+ projectId: string;+ environment: string;+ secretPath: string;+ };+};++export type THoneyTokenUpdatedEvent = {+ event: PostHogEventTypes.HoneyTokenUpdated;+ properties: {+ honeyTokenId: string;+ type: string;+ projectId: string;+ };+};++export type THoneyTokenRevokedEvent = {+ event: PostHogEventTypes.HoneyTokenRevoked;+ properties: {+ honeyTokenId: string;+ type: string;+ projectId: string;+ };+};++export type THoneyTokenResetEvent = {+ event: PostHogEventTypes.HoneyTokenReset;+ properties: {+ honeyTokenId: string;+ type: string;+ projectId: string;+ };+};++export type THoneyTokenTriggeredEvent = {+ event: PostHogEventTypes.HoneyTokenTriggered;+ properties: {+ honeyTokenId: string;+ type: string;+ projectId: string;+ };+};+export type TPostHogEvent = { distinctId: string; organizationId?: string; organizationName?: string } & (| TSecretModifiedEvent| TAdminInitEvent@@ -907,4 +960,9 @@ export type TPostHogEvent = { distinctId: string; organizationId?: string; organ| TPamRotationRuleCreatedEvent| TPamRotationRuleDeletedEvent| TResourceAuthMethodEvent+ | THoneyTokenCreatedEvent+ | THoneyTokenUpdatedEvent+ | THoneyTokenRevokedEvent+ | THoneyTokenResetEvent+ | THoneyTokenTriggeredEvent);