Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

feat(telemetry): enrich self-hosted instance stats with enterprise signals and instanceId linkage

Devin AI3070d15e68ed
diff --git a/backend/src/services/telemetry/telemetry-dal.ts b/backend/src/services/telemetry/telemetry-dal.ts
index 40f2853eb9..02b838f9bd 100644
--- a/backend/src/services/telemetry/telemetry-dal.ts
+++ b/backend/src/services/telemetry/telemetry-dal.ts
@@ -5,21 +5,21 @@ import { DatabaseError } from "@app/lib/errors";
export type TTelemetryDALFactory = ReturnType<typeof telemetryDALFactory>;
-const IDENTITY_AUTH_TABLES: readonly string[] = [
- TableName.IdentityUniversalAuth,
- TableName.IdentityTokenAuth,
- TableName.IdentityKubernetesAuth,
- TableName.IdentityGcpAuth,
- TableName.IdentityAwsAuth,
- TableName.IdentityAzureAuth,
- TableName.IdentityOciAuth,
- TableName.IdentityOidcAuth,
- TableName.IdentityJwtAuth,
- TableName.IdentityLdapAuth,
- TableName.IdentityAliCloudAuth,
- TableName.IdentityTlsCertAuth,
- TableName.IdentitySpiffeAuth
-];
+const IDENTITY_AUTH_TABLE_MAP: Record<string, string> = {
+ "universal-auth": TableName.IdentityUniversalAuth,
+ "token-auth": TableName.IdentityTokenAuth,
+ "kubernetes-auth": TableName.IdentityKubernetesAuth,
+ "gcp-auth": TableName.IdentityGcpAuth,
+ "aws-auth": TableName.IdentityAwsAuth,
+ "azure-auth": TableName.IdentityAzureAuth,
+ "oci-auth": TableName.IdentityOciAuth,
+ "oidc-auth": TableName.IdentityOidcAuth,
+ "jwt-auth": TableName.IdentityJwtAuth,
+ "ldap-auth": TableName.IdentityLdapAuth,
+ "alicloud-auth": TableName.IdentityAliCloudAuth,
+ "tls-cert-auth": TableName.IdentityTlsCertAuth,
+ "spiffe-auth": TableName.IdentitySpiffeAuth
+};
const countTable = async (db: TDbClient, table: TableName) => {
const result = (await db(table).count().first())?.count as string;
@@ -43,7 +43,25 @@ export const telemetryDALFactory = (db: TDbClient) => {
certificates,
dynamicSecrets,
groups,
- secretApprovalPolicies
+ secretApprovalPolicies,
+ // new counts
+ samlConfigs,
+ oidcConfigs,
+ ldapConfigs,
+ scimTokens,
+ auditLogStreams,
+ secretRotations,
+ webhooks,
+ customProjectRoles,
+ customOrgRoles,
+ kmipClients,
+ sshHosts,
+ sshCertificateAuthorities,
+ sshCertificates,
+ pamResources,
+ pamAccounts,
+ accessApprovalPolicies,
+ honeyTokens
] = await Promise.all([
(async () => {
const result = (await db(TableName.Users).where({ isGhost: false }).count().first())?.count as string;
@@ -64,20 +82,43 @@ export const telemetryDALFactory = (db: TDbClient) => {
countTable(db, TableName.Certificate),
countTable(db, TableName.DynamicSecret),
countTable(db, TableName.Groups),
- countTable(db, TableName.SecretApprovalPolicy)
+ countTable(db, TableName.SecretApprovalPolicy),
+ // new counts
+ countTable(db, TableName.SamlConfig),
+ countTable(db, TableName.OidcConfig),
+ countTable(db, TableName.LdapConfig),
+ countTable(db, TableName.ScimToken),
+ countTable(db, TableName.AuditLogStream),
+ countTable(db, TableName.SecretRotationV2),
+ countTable(db, TableName.Webhook),
+ countTable(db, TableName.ProjectRoles),
+ countTable(db, TableName.OrgRoles),
+ countTable(db, TableName.KmipClient),
+ countTable(db, TableName.SshHost),
+ countTable(db, TableName.SshCertificateAuthority),
+ countTable(db, TableName.SshCertificate),
+ countTable(db, TableName.PamResource),
+ countTable(db, TableName.PamAccount),
+ countTable(db, TableName.AccessApprovalPolicy),
+ countTable(db, TableName.HoneyToken)
]);
+ // Per-type identity auth method breakdown
+ const identityAuthMethodEntries = Object.entries(IDENTITY_AUTH_TABLE_MAP);
const identityAuthMethodsResult = await db.raw<{ rows: { count: string }[] }>(
- IDENTITY_AUTH_TABLES.map((table) => `SELECT COUNT(*)::text AS count FROM ${table}`).join(" UNION ALL ")
- );
- const identityAuthMethods = identityAuthMethodsResult.rows.reduce(
- (sum: number, row: { count: string }) => sum + parseInt(row.count || "0", 10),
- 0
+ identityAuthMethodEntries.map(([, table]) => `SELECT COUNT(*)::text AS count FROM ${table}`).join(" UNION ALL ")
);
+ const identityAuthMethodBreakdown: Record<string, number> = {};
+ let identityAuthMethods = 0;
+ identityAuthMethodsResult.rows.forEach((row: { count: string }, idx: number) => {
+ const count = parseInt(row.count || "0", 10);
+ identityAuthMethods += count;
+ if (count > 0) {
+ identityAuthMethodBreakdown[identityAuthMethodEntries[idx][0]] = count;
+ }
+ });
// Count active gateways from both legacy (Gateway) and V2 (GatewayV2) tables.
- // Legacy gateways heartbeat every ~3 minutes; use a 5-minute window to avoid undercounting.
- // V2 gateways report their own heartbeatTTL; use the same expression as gateway-v2-dal.ts.
const legacyActiveResult = (
await db(TableName.Gateway)
.whereNotNull("heartbeat")
@@ -98,12 +139,56 @@ export const telemetryDALFactory = (db: TDbClient) => {
const activeGateways = parseInt(legacyActiveResult || "0", 10) + parseInt(v2ActiveResult || "0", 10);
- // Merge legacy `secrets` and `secrets_v2` counts. secrets_v2 is the active table;
- // legacy `secrets` only retains rows for projects that haven't been migrated.
const secrets = legacySecrets + v2Secrets;
- const organizationNames = await db(TableName.Organization).select("name");
- const organizations = organizationNames.length;
+ // Integration type breakdown
+ const integrationTypeResult = await db.raw<{ rows: { integration: string; count: string }[] }>(
+ `SELECT integration, COUNT(*)::text AS count FROM ${TableName.Integration} GROUP BY integration`
+ );
+ const integrationBreakdown: Record<string, number> = {};
+ for (const row of integrationTypeResult.rows) {
+ integrationBreakdown[row.integration] = parseInt(row.count, 10);
+ }
+
+ // Project type breakdown
+ const projectTypeResult = await db.raw<{ rows: { type: string; count: string }[] }>(
+ `SELECT type, COUNT(*)::text AS count FROM ${TableName.Project} GROUP BY type`
+ );
+ const projectTypeBreakdown: Record<string, number> = {};
+ for (const row of projectTypeResult.rows) {
+ projectTypeBreakdown[row.type] = parseInt(row.count, 10);
+ }
+
+ // Secret sync destination breakdown
+ const syncDestinationResult = await db.raw<{ rows: { destination: string; count: string }[] }>(
+ `SELECT destination, COUNT(*)::text AS count FROM ${TableName.SecretSync} GROUP BY destination`
+ );
+ const secretSyncBreakdown: Record<string, number> = {};
+ for (const row of syncDestinationResult.rows) {
+ secretSyncBreakdown[row.destination] = parseInt(row.count, 10);
+ }
+
+ // Per-org breakdown: orgId, name, user count, project count
+ const organizationRows = await db(TableName.Organization).select("id", "name");
+ const organizations = organizationRows.length;
+ const organizationNames = organizationRows.map(({ name }) => name);
+
+ const orgUserResult = await db.raw<{ rows: { orgId: string; count: string }[] }>(
+ `SELECT "orgId", COUNT(*)::text AS count FROM ${TableName.OrgMembership} GROUP BY "orgId"`
+ );
+ const orgUserMap = new Map(orgUserResult.rows.map((r) => [r.orgId, parseInt(r.count, 10)]));
+
+ const orgProjectResult = await db.raw<{ rows: { orgId: string; count: string }[] }>(
+ `SELECT "orgId", COUNT(*)::text AS count FROM ${TableName.Project} GROUP BY "orgId"`
+ );
+ const orgProjectMap = new Map(orgProjectResult.rows.map((r) => [r.orgId, parseInt(r.count, 10)]));
+
+ const organizationBreakdown = organizationRows.map((org) => ({
+ orgId: org.id,
+ name: org.name,
+ users: orgUserMap.get(org.id) ?? 0,
+ projects: orgProjectMap.get(org.id) ?? 0
+ }));
return {
users,
@@ -111,7 +196,7 @@ export const telemetryDALFactory = (db: TDbClient) => {
projects,
secrets,
organizations,
- organizationNames: organizationNames.map(({ name }) => name),
+ organizationNames,
environments,
secretSyncs,
appConnections,
@@ -120,9 +205,31 @@ export const telemetryDALFactory = (db: TDbClient) => {
certificates,
dynamicSecrets,
identityAuthMethods,
+ identityAuthMethodBreakdown,
groups,
secretApprovalPolicies,
- activeGateways
+ activeGateways,
+ samlConfigs,
+ oidcConfigs,
+ ldapConfigs,
+ scimTokens,
+ auditLogStreams,
+ secretRotations,
+ webhooks,
+ customProjectRoles,
+ customOrgRoles,
+ kmipClients,
+ sshHosts,
+ sshCertificateAuthorities,
+ sshCertificates,
+ pamResources,
+ pamAccounts,
+ accessApprovalPolicies,
+ honeyTokens,
+ integrationBreakdown,
+ projectTypeBreakdown,
+ secretSyncBreakdown,
+ organizationBreakdown
};
} catch (error) {
throw new DatabaseError({ error, name: "TelemetryInstanceStats" });
diff --git a/backend/src/services/telemetry/telemetry-queue.ts b/backend/src/services/telemetry/telemetry-queue.ts
index eb9b2a0a11..a61d5d40b8 100644
--- a/backend/src/services/telemetry/telemetry-queue.ts
+++ b/backend/src/services/telemetry/telemetry-queue.ts
@@ -52,7 +52,12 @@ export const telemetryQueueServiceFactory = ({
10
);
const numberOfSecretProcessed = parseInt((await keyStore.getItem(TELEMETRY_SECRET_PROCESSED_KEY)) || "0", 10);
- const stats = { ...telemetryStats, numberOfSecretProcessed, numberOfSecretOperationsMade };
+ const stats = {
+ ...telemetryStats,
+ numberOfSecretProcessed,
+ numberOfSecretOperationsMade,
+ ...(appCfg.INFISICAL_PLATFORM_VERSION ? { infisicalVersion: appCfg.INFISICAL_PLATFORM_VERSION } : {})
+ };
postHog.capture({
event: PostHogEventTypes.TelemetryInstanceStats,
diff --git a/backend/src/services/telemetry/telemetry-service.ts b/backend/src/services/telemetry/telemetry-service.ts
index f013211033..9468a8b3e4 100644
--- a/backend/src/services/telemetry/telemetry-service.ts
+++ b/backend/src/services/telemetry/telemetry-service.ts
@@ -13,6 +13,7 @@ import { RequestContextKey } from "@app/lib/request-context/request-context-keys
import { requestMemoize } from "@app/lib/request-context/request-memoizer";
import { ActorType } from "@app/services/auth/auth-type";
import { TOrgDALFactory } from "@app/services/org/org-dal";
+import { getServerCfg } from "@app/services/super-admin/super-admin-service";
import { HubSpotSignupMethod, PostHogEventTypes, TPostHogEvent, TSecretModifiedEvent } from "./telemetry-types";
@@ -110,6 +111,19 @@ const getDeploymentType = (
export const telemetryServiceFactory = ({ keyStore, licenseService, orgDAL }: TTelemetryServiceFactoryDep) => {
const appCfg = getConfig();
+ let cachedInstanceId: string | undefined;
+ const getInstanceId = async (): Promise<string | undefined> => {
+ if (appCfg.INFISICAL_CLOUD) return undefined;
+ if (cachedInstanceId) return cachedInstanceId;
+ try {
+ const { instanceId } = await getServerCfg();
+ cachedInstanceId = instanceId;
+ return instanceId;
+ } catch {
+ return undefined;
+ }
+ };
+
if (appCfg.isProductionMode && !appCfg.TELEMETRY_ENABLED) {
// eslint-disable-next-line
console.log(`
@@ -328,7 +342,11 @@ To opt into telemetry, you can set "TELEMETRY_ENABLED=true" within the environme
// `anonymous-<shareId>` keys used by unauthenticated public secret
// shares) from inflating the person count while preserving event
// counts, funnels, and breakdowns.
- const properties = event.anonymous ? { ...event.properties, $process_person_profile: false } : event.properties;
+ const instanceId = await getInstanceId();
+ const baseProperties = event.anonymous
+ ? { ...event.properties, $process_person_profile: false }
+ : event.properties;
+ const properties = instanceId ? { ...baseProperties, instanceId } : baseProperties;
postHog.capture({
event: event.event,
@@ -502,6 +520,12 @@ To opt into telemetry, you can set "TELEMETRY_ENABLED=true" within the environme
properties.orgId = key.org;
}
+ // eslint-disable-next-line no-await-in-loop
+ const instanceId = await getInstanceId();
+ if (instanceId) {
+ properties.instanceId = instanceId;
+ }
+
postHog.capture({
event: `${eventType} aggregated`,
distinctId: key.id,
diff --git a/backend/src/services/telemetry/telemetry-types.ts b/backend/src/services/telemetry/telemetry-types.ts
index 7402bf4be5..a06b0a2011 100644
--- a/backend/src/services/telemetry/telemetry-types.ts
+++ b/backend/src/services/telemetry/telemetry-types.ts
@@ -494,9 +494,32 @@ export type TTelemetryInstanceStatsEvent = {
certificates: number;
dynamicSecrets: number;
identityAuthMethods: number;
+ identityAuthMethodBreakdown: Record<string, number>;
groups: number;
secretApprovalPolicies: number;
activeGateways: number;
+ samlConfigs: number;
+ oidcConfigs: number;
+ ldapConfigs: number;
+ scimTokens: number;
+ auditLogStreams: number;
+ secretRotations: number;
+ webhooks: number;
+ customProjectRoles: number;
+ customOrgRoles: number;
+ kmipClients: number;
+ sshHosts: number;
+ sshCertificateAuthorities: number;
+ sshCertificates: number;
+ pamResources: number;
+ pamAccounts: number;
+ accessApprovalPolicies: number;
+ honeyTokens: number;
+ integrationBreakdown: Record<string, number>;
+ projectTypeBreakdown: Record<string, number>;
+ secretSyncBreakdown: Record<string, number>;
+ organizationBreakdown: { orgId: string; name: string; users: number; projects: number }[];
+ infisicalVersion?: string;
};
};