Skip to content

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

feat(telemetry): report PKI certificate issuance from profile-based flows (#7514)

Saif Ur Rahman8b1ee83ac893
diff --git a/backend/src/server/routes/index.ts b/backend/src/server/routes/index.ts
index 228b8feae3..2232523933 100644
--- a/backend/src/server/routes/index.ts
+++ b/backend/src/server/routes/index.ts
@@ -3239,7 +3239,8 @@ export const registerRoutes = async (
usageMeteringService,
hsmConnectorService,
certificateAuthoritySecretDAL,
- licenseService
+ licenseService,
+ telemetryService
});
const certificateEstService = certificateEstServiceFactory({
@@ -3363,7 +3364,8 @@ export const registerRoutes = async (
pkiApplicationProfileDAL,
apiEnrollmentConfigDAL,
gatewayV2Service,
- gatewayPoolService
+ gatewayPoolService,
+ telemetryService
});
const certificateApprovalService = certificateApprovalServiceFactory({
@@ -3436,7 +3438,8 @@ export const registerRoutes = async (
pkiAlertV2Queue,
pkiApplicationProfileDAL,
apiEnrollmentConfigDAL,
- licenseService
+ licenseService,
+ telemetryService
});
const certificateV3Queue = certificateV3QueueServiceFactory({
@@ -3454,7 +3457,9 @@ export const registerRoutes = async (
appConnectionDAL,
kmsService,
resourceMetadataDAL,
- digicertFns: digicertCaFns
+ digicertFns: digicertCaFns,
+ projectDAL,
+ telemetryService
});
const digicertRevocationSyncQueue = digicertRevocationSyncQueueFactory({
@@ -3475,7 +3480,9 @@ export const registerRoutes = async (
appConnectionDAL,
kmsService,
resourceMetadataDAL,
- godaddyFns: godaddyCaFns
+ godaddyFns: godaddyCaFns,
+ projectDAL,
+ telemetryService
});
const certificateEstV3Service = certificateEstV3ServiceFactory({
diff --git a/backend/src/server/routes/v1/pki-application-router.ts b/backend/src/server/routes/v1/pki-application-router.ts
index 974eb1b208..8300fa0e73 100644
--- a/backend/src/server/routes/v1/pki-application-router.ts
+++ b/backend/src/server/routes/v1/pki-application-router.ts
@@ -76,7 +76,8 @@ export const registerPkiApplicationRouter = async (server: FastifyZodProvider) =
distinctId: getTelemetryDistinctId(req),
organizationId: req.permission.orgId,
properties: {
- orgId: req.permission.orgId
+ orgId: req.permission.orgId,
+ applicationId: application.id
}
});
@@ -303,6 +304,16 @@ export const registerPkiApplicationRouter = async (server: FastifyZodProvider) =
}
});
+ await server.services.telemetry.sendPostHogEvents({
+ event: PostHogEventTypes.PkiApplicationUpdated,
+ distinctId: getTelemetryDistinctId(req),
+ organizationId: req.permission.orgId,
+ properties: {
+ orgId: req.permission.orgId,
+ applicationId: application.id
+ }
+ });
+
return { application };
}
});
@@ -344,7 +355,8 @@ export const registerPkiApplicationRouter = async (server: FastifyZodProvider) =
distinctId: getTelemetryDistinctId(req),
organizationId: req.permission.orgId,
properties: {
- orgId: req.permission.orgId
+ orgId: req.permission.orgId,
+ applicationId: application.id
}
});
diff --git a/backend/src/services/certificate-authority/certificate-authority-service.ts b/backend/src/services/certificate-authority/certificate-authority-service.ts
index f09c947169..577b91383d 100644
--- a/backend/src/services/certificate-authority/certificate-authority-service.ts
+++ b/backend/src/services/certificate-authority/certificate-authority-service.ts
@@ -37,6 +37,7 @@ import { TPkiSyncDALFactory } from "../pki-sync/pki-sync-dal";
import { TPkiSyncQueueFactory } from "../pki-sync/pki-sync-queue";
import { TProjectDALFactory } from "../project/project-dal";
import { TResourceMetadataDALFactory } from "../resource-metadata/resource-metadata-dal";
+import { TTelemetryServiceFactory } from "../telemetry/telemetry-service";
import {
AcmeCertificateAuthorityFns,
castDbEntryToAcmeCertificateAuthority
@@ -135,6 +136,7 @@ type TCertificateAuthorityServiceFactoryDep = {
externalCertificateAuthorityDAL: Pick<TExternalCertificateAuthorityDALFactory, "create" | "update" | "findOne">;
internalCertificateAuthorityService: TInternalCertificateAuthorityServiceFactory;
projectDAL: Pick<TProjectDALFactory, "findProjectBySlug" | "findOne" | "updateById" | "findById" | "transaction">;
+ telemetryService: Pick<TTelemetryServiceFactory, "sendPostHogEvents">;
permissionService: Pick<TPermissionServiceFactory, "getProjectPermission">;
certificateDAL: Pick<TCertificateDALFactory, "create" | "findById" | "findOne" | "transaction" | "updateById">;
certificateBodyDAL: Pick<TCertificateBodyDALFactory, "create">;
@@ -165,6 +167,7 @@ export type TCertificateAuthorityServiceFactory = ReturnType<typeof certificateA
export const certificateAuthorityServiceFactory = ({
certificateAuthorityDAL,
projectDAL,
+ telemetryService,
permissionService,
internalCertificateAuthorityService,
appConnectionDAL,
@@ -1420,7 +1423,9 @@ export const certificateAuthorityServiceFactory = ({
certificateRequestDAL,
certificateRequestService,
resourceMetadataDAL,
- godaddyFns
+ godaddyFns,
+ projectDAL,
+ telemetryService
},
certificateRequest
)
@@ -1432,7 +1437,9 @@ export const certificateAuthorityServiceFactory = ({
certificateRequestDAL,
certificateRequestService,
resourceMetadataDAL,
- digicertFns
+ digicertFns,
+ projectDAL,
+ telemetryService
},
certificateRequest
);
diff --git a/backend/src/services/certificate-authority/certificate-issuance-queue.ts b/backend/src/services/certificate-authority/certificate-issuance-queue.ts
index 18befcf97e..4d9206f72d 100644
--- a/backend/src/services/certificate-authority/certificate-issuance-queue.ts
+++ b/backend/src/services/certificate-authority/certificate-issuance-queue.ts
@@ -14,20 +14,23 @@ import {
CertSubjectAlternativeNameType
} from "@app/services/certificate/certificate-types";
import { TCertificateProfileDALFactory } from "@app/services/certificate-profile/certificate-profile-dal";
+import { EnrollmentType } from "@app/services/certificate-profile/certificate-profile-types";
import { TKmsServiceFactory } from "@app/services/kms/kms-service";
import { TProjectDALFactory } from "@app/services/project/project-dal";
import { getProjectKmsCertificateKeyId } from "@app/services/project/project-fns";
+import { TTelemetryServiceFactory } from "@app/services/telemetry/telemetry-service";
import { TAppConnectionDALFactory } from "../app-connection/app-connection-dal";
import { TAppConnectionServiceFactory } from "../app-connection/app-connection-service";
import { TCertificateBodyDALFactory } from "../certificate/certificate-body-dal";
import { TCertificateSecretDALFactory } from "../certificate/certificate-secret-dal";
-import { CertKeyAlgorithm } from "../certificate-common/certificate-constants";
+import { CertificateIssuanceOperation, CertKeyAlgorithm } from "../certificate-common/certificate-constants";
import {
calculateFinalRenewBeforeDays,
resolveEffectiveApiConfig
} from "../certificate-common/certificate-issuance-utils";
import { CertificateRequestCancelledError } from "../certificate-common/certificate-request-errors";
+import { reportCertificateIssued } from "../certificate-common/certificate-telemetry-fns";
import {
DigiCertExternalMetadataSchema,
GoDaddyExternalMetadataSchema
@@ -176,6 +179,7 @@ type TCertificateIssuanceQueueFactoryDep = {
apiEnrollmentConfigDAL?: Pick<TApiEnrollmentConfigDALFactory, "findById">;
gatewayV2Service: Pick<TGatewayV2ServiceFactory, "getPlatformConnectionDetailsByGatewayId">;
gatewayPoolService: Pick<TGatewayPoolServiceFactory, "resolveEffectiveGatewayId">;
+ telemetryService: Pick<TTelemetryServiceFactory, "sendPostHogEvents">;
};
export type TCertificateIssuanceQueueFactory = ReturnType<typeof certificateIssuanceQueueFactory>;
@@ -203,7 +207,8 @@ export const certificateIssuanceQueueFactory = ({
pkiApplicationProfileDAL,
apiEnrollmentConfigDAL,
gatewayV2Service,
- gatewayPoolService
+ gatewayPoolService,
+ telemetryService
}: TCertificateIssuanceQueueFactoryDep) => {
const acmeFns = AcmeCertificateAuthorityFns({
appConnectionDAL,
@@ -436,6 +441,10 @@ export const certificateIssuanceQueueFactory = ({
);
};
+ // DigiCert and GoDaddy attach the certificate later in their processors, so a pending order
+ // must not be reported as issued. Tracked here rather than re-read: the replica lags the write.
+ let certificateExistsAfterThisJob = true;
+
try {
logger.info(`Processing certificate issuance job for [certificateId=${certificateId}] [caId=${caId}]`);
@@ -950,12 +959,14 @@ export const certificateIssuanceQueueFactory = ({
`DigiCert order issued immediately (pre-validated domains), attached certificate [certificateRequestId=${certificateRequestId}] [certificateId=${attachedCertificateId}]`
);
} catch (finaliseError) {
+ certificateExistsAfterThisJob = false;
logger.error(
finaliseError,
`DigiCert immediate finalisation failed, will be retried by polling queue [certificateRequestId=${certificateRequestId}]`
);
}
} else {
+ certificateExistsAfterThisJob = false;
await setPending(`DigiCert is processing the request — order #${digicertResult.metadata.digicert.orderId}`);
logger.info(
`DigiCert order placed, awaiting validation [certificateRequestId=${certificateRequestId}] [orderId=${digicertResult.metadata.digicert.orderId}]`
@@ -1038,6 +1049,7 @@ export const certificateIssuanceQueueFactory = ({
return;
}
+ certificateExistsAfterThisJob = false;
await setPending(
`GoDaddy is processing the request — certificate ${godaddyResult.metadata.godaddy.certificateId}`
);
@@ -1201,6 +1213,20 @@ export const certificateIssuanceQueueFactory = ({
} catch {
logger.debug("Failed to queue PKI alert event for async certificate issuance");
}
+
+ if (certificateExistsAfterThisJob) {
+ const telemetryProfile = profileId ? await certificateProfileDAL?.findById(profileId) : undefined;
+
+ await reportCertificateIssued({
+ telemetryService,
+ projectDAL,
+ projectId: ca.projectId,
+ profileId,
+ applicationId: scopedApplicationId,
+ enrollmentType: telemetryProfile?.enrollmentType ?? EnrollmentType.API,
+ operation: isRenewal ? CertificateIssuanceOperation.RENEW : CertificateIssuanceOperation.ORDER
+ });
+ }
} catch (error: unknown) {
if (error instanceof CertificateRequestCancelledError) {
logger.info(
diff --git a/backend/src/services/certificate-authority/digicert/digicert-certificate-authority-processor.ts b/backend/src/services/certificate-authority/digicert/digicert-certificate-authority-processor.ts
index ea75b65cc3..6f8e0e4dab 100644
--- a/backend/src/services/certificate-authority/digicert/digicert-certificate-authority-processor.ts
+++ b/backend/src/services/certificate-authority/digicert/digicert-certificate-authority-processor.ts
@@ -5,9 +5,13 @@ import { AppConnection } from "@app/services/app-connection/app-connection-enums
import { decryptAppConnectionCredentials } from "@app/services/app-connection/app-connection-fns";
import { getDigiCertApiBaseUrl } from "@app/services/app-connection/digicert/digicert-connection-fns";
import { TDigiCertConnection } from "@app/services/app-connection/digicert/digicert-connection-types";
+import { EnrollmentType } from "@app/services/certificate-profile/certificate-profile-types";
import { TKmsServiceFactory } from "@app/services/kms/kms-service";
+import { TProjectDALFactory } from "@app/services/project/project-dal";
+import { TTelemetryServiceFactory } from "@app/services/telemetry/telemetry-service";
-import { CertificateRequestStatus } from "../../certificate-common/certificate-constants";
+import { CertificateIssuanceOperation, CertificateRequestStatus } from "../../certificate-common/certificate-constants";
+import { reportCertificateIssued } from "../../certificate-common/certificate-telemetry-fns";
import { TCertificateRequestDALFactory } from "../../certificate-request/certificate-request-dal";
import {
TAttachCertificateToRequestDTO,
@@ -57,6 +61,8 @@ export type TProcessDigiCertRequestDeps = {
certificateRequestService: TDigiCertCertificateRequestServiceDep;
resourceMetadataDAL: Pick<TResourceMetadataDALFactory, "find" | "insertMany">;
digicertFns: Pick<TDigiCertCertificateAuthorityFns, "fetchAndAttachIssuedCertificate">;
+ projectDAL: Pick<TProjectDALFactory, "findById">;
+ telemetryService: Pick<TTelemetryServiceFactory, "sendPostHogEvents">;
};
export type TProcessDigiCertRequestResult =
@@ -181,6 +187,17 @@ export const processDigiCertPendingValidationRequest = async (
logger.info(
`DigiCert order issued, attached certificate [certificateRequestId=${request.id}] [certificateId=${certificateId}]`
);
+
+ await reportCertificateIssued({
+ telemetryService: deps.telemetryService,
+ projectDAL: deps.projectDAL,
+ projectId: request.projectId,
+ profileId: request.profileId,
+ applicationId: request.applicationId,
+ enrollmentType: EnrollmentType.API,
+ operation: parsed.digicert.isRenewal ? CertificateIssuanceOperation.RENEW : CertificateIssuanceOperation.ORDER
+ });
+
return { status: CertificateRequestStatus.ISSUED, certificateId, orderStatus };
}
diff --git a/backend/src/services/certificate-authority/godaddy/godaddy-certificate-authority-processor.ts b/backend/src/services/certificate-authority/godaddy/godaddy-certificate-authority-processor.ts
index 00143d2971..6c27eb83a6 100644
--- a/backend/src/services/certificate-authority/godaddy/godaddy-certificate-authority-processor.ts
+++ b/backend/src/services/certificate-authority/godaddy/godaddy-certificate-authority-processor.ts
@@ -6,9 +6,13 @@ import { decryptAppConnectionCredentials } from "@app/services/app-connection/ap
import { buildGoDaddySsoKeyHeader } from "@app/services/app-connection/godaddy/godaddy-connection-constants";
import { getGoDaddyApiBaseUrl } from "@app/services/app-connection/godaddy/godaddy-connection-fns";
import { TGoDaddyConnection } from "@app/services/app-connection/godaddy/godaddy-connection-types";
+import { EnrollmentType } from "@app/services/certificate-profile/certificate-profile-types";
import { TKmsServiceFactory } from "@app/services/kms/kms-service";
+import { TProjectDALFactory } from "@app/services/project/project-dal";
+import { TTelemetryServiceFactory } from "@app/services/telemetry/telemetry-service";
-import { CertificateRequestStatus } from "../../certificate-common/certificate-constants";
+import { CertificateIssuanceOperation, CertificateRequestStatus } from "../../certificate-common/certificate-constants";
+import { reportCertificateIssued } from "../../certificate-common/certificate-telemetry-fns";
import { TCertificateRequestDALFactory } from "../../certificate-request/certificate-request-dal";
import {
TAttachCertificateToRequestDTO,
@@ -57,6 +61,8 @@ export type TProcessGoDaddyRequestDeps = {
certificateRequestService: TGoDaddyCertificateRequestServiceDep;
resourceMetadataDAL: Pick<TResourceMetadataDALFactory, "find" | "insertMany">;
godaddyFns: Pick<TGoDaddyCertificateAuthorityFns, "fetchAndAttachIssuedCertificate">;
+ projectDAL: Pick<TProjectDALFactory, "findById">;
+ telemetryService: Pick<TTelemetryServiceFactory, "sendPostHogEvents">;
};
export type TProcessGoDaddyRequestResult =
@@ -175,6 +181,17 @@ export const processGoDaddyPendingValidationRequest = async (
logger.info(
`GoDaddy certificate issued, attached certificate [certificateRequestId=${request.id}] [certificateId=${certificateId}]`
);
+
+ await reportCertificateIssued({
+ telemetryService: deps.telemetryService,
+ projectDAL: deps.projectDAL,
+ projectId: request.projectId,
+ profileId: request.profileId,
+ applicationId: request.applicationId,
+ enrollmentType: EnrollmentType.API,
+ operation: parsed.godaddy.isRenewal ? CertificateIssuanceOperation.RENEW : CertificateIssuanceOperation.ORDER
+ });
+
return { status: CertificateRequestStatus.ISSUED, certificateId, orderStatus };
} catch (error) {
// A renewal can report ISSUED/CURRENT while GoDaddy is still serving the previous certificate
diff --git a/backend/src/services/certificate-common/certificate-constants.ts b/backend/src/services/certificate-common/certificate-constants.ts
index 5c57beae97..e98eeb794b 100644
--- a/backend/src/services/certificate-common/certificate-constants.ts
+++ b/backend/src/services/certificate-common/certificate-constants.ts
@@ -53,6 +53,13 @@ export enum CertificateRequestStatus {
REJECTED = "rejected"
}
+export enum CertificateIssuanceOperation {
+ ISSUE = "issue",
+ SIGN = "sign",
+ ORDER = "order",
+ RENEW = "renew"
+}
+
export enum CertSubjectAlternativeNameType {
DNS_NAME = "dns_name",
IP_ADDRESS = "ip_address",
diff --git a/backend/src/services/certificate-common/certificate-telemetry-fns.ts b/backend/src/services/certificate-common/certificate-telemetry-fns.ts
new file mode 100644
index 0000000000..396cd628fb
--- /dev/null
+++ b/backend/src/services/certificate-common/certificate-telemetry-fns.ts
@@ -0,0 +1,56 @@
+import { logger } from "@app/lib/logger";
+import { CertificateIssuanceOperation } from "@app/services/certificate-common/certificate-constants";
+import { TProjectDALFactory } from "@app/services/project/project-dal";
+import { TTelemetryServiceFactory } from "@app/services/telemetry/telemetry-service";
+import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";
+
+export type TReportCertificateIssuedDTO = {
+ telemetryService: Pick<TTelemetryServiceFactory, "sendPostHogEvents">;
+ projectId: string;
+ enrollmentType: string;
+ operation: CertificateIssuanceOperation;
+ profileId?: string | null;
+ applicationId?: string | null;
+ orgId?: string;
+ distinctId?: string;
+ /** Only needed when `orgId` is not supplied. */
+ projectDAL?: Pick<TProjectDALFactory, "findById">;
+};
+
+// Call only once the certificate exists — an order still pending validation is not an issuance.
+export const reportCertificateIssued = async ({
+ telemetryService,
+ projectId,
+ enrollmentType,
+ operation,
+ profileId,
+ applicationId,
+ orgId,
+ distinctId,
+ projectDAL
+}: TReportCertificateIssuedDTO) => {
+ try {
+ const resolvedOrgId = orgId || (projectDAL ? (await projectDAL.findById(projectId))?.orgId : undefined);
+ // orgId is non-nullable on a project, so this only happens if the project was deleted mid-issuance.
+ if (!resolvedOrgId) {
+ logger.warn(`Skipping certificate issuance telemetry, project not found [projectId=${projectId}]`);
+ return;
+ }
+
+ await telemetryService.sendPostHogEvents({
+ event: PostHogEventTypes.IssueCert,
+ distinctId: distinctId || `platform/${projectId}`,
+ organizationId: resolvedOrgId,
+ properties: {
+ orgId: resolvedOrgId,
+ projectId,
+ profileId: profileId ?? undefined,
+ applicationId: applicationId ?? undefined,
+ enrollmentType,
+ operation
+ }
+ });
+ } catch (error) {
+ logger.debug({ error }, "Failed to report certificate issuance telemetry");
+ }
+};
diff --git a/backend/src/services/certificate-v3/certificate-v3-service.test.ts b/backend/src/services/certificate-v3/certificate-v3-service.test.ts
index 0a5f7645bc..08d661cd21 100644
--- a/backend/src/services/certificate-v3/certificate-v3-service.test.ts
+++ b/backend/src/services/certificate-v3/certificate-v3-service.test.ts
@@ -17,6 +17,7 @@ import { CaStatus } from "@app/services/certificate-authority/certificate-author
import { TInternalCertificateAuthorityServiceFactory } from "@app/services/certificate-authority/internal/internal-certificate-authority-service";
import {
CertExtendedKeyUsageType,
+ CertificateIssuanceOperation,
CertIncludeType,
CertKeyUsageType,
CertSubjectAlternativeNameType,
@@ -25,6 +26,7 @@ import {
import { TCertificatePolicyServiceFactory } from "@app/services/certificate-policy/certificate-policy-service";
import { TCertificateProfileDALFactory } from "@app/services/certificate-profile/certificate-profile-dal";
import { EnrollmentType, IssuerType } from "@app/services/certificate-profile/certificate-profile-types";
+import { PostHogEventTypes } from "@app/services/telemetry/telemetry-types";
import { ActorType, AuthMethod } from "../auth/auth-type";
import {
@@ -56,6 +58,10 @@ vi.mock("../certificate-authority/certificate-authority-fns", () => ({
describe("CertificateV3Service", () => {
let service: TCertificateV3ServiceFactory;
+ const mockTelemetryService = {
+ sendPostHogEvents: vi.fn().mockResolvedValue(undefined)
+ };
+
const mockCertificateDAL: Pick<
TCertificateDALFactory,
"findOne" | "findById" | "updateById" | "transaction" | "create" | "find" | "getRequestEnrollmentTypeByCertId"
@@ -279,7 +285,8 @@ describe("CertificateV3Service", () => {
},
licenseService: {
getPlan: vi.fn().mockResolvedValue({ pkiPqc: true })
- }
+ },
+ telemetryService: mockTelemetryService
});
});
@@ -455,6 +462,18 @@ describe("CertificateV3Service", () => {
expect(result).toHaveProperty("privateKey");
expect(result).toHaveProperty("serialNumber", "123456");
expect(result).toHaveProperty("certificateId", "cert-123");
+
+ expect(mockTelemetryService.sendPostHogEvents).toHaveBeenCalledWith(
+ expect.objectContaining({
+ event: PostHogEventTypes.IssueCert,
+ properties: expect.objectContaining({
+ profileId,
+ projectId: "project-123",
+ enrollmentType: EnrollmentType.API,
+ operation: CertificateIssuanceOperation.ISSUE
+ })
+ })
+ );
});
it("should correctly map camelCase key usages to snake_case before validation", async () => {
@@ -910,6 +929,16 @@ describe("CertificateV3Service", () => {
expect(result).toHaveProperty("serialNumber", "789012");
expect(result).toHaveProperty("certificateId", "cert-456");
expect(result).not.toHaveProperty("privateKey");
+
+ expect(mockTelemetryService.sendPostHogEvents).toHaveBeenCalledWith(
+ expect.objectContaining({
+ event: PostHogEventTypes.IssueCert,
+ properties: expect.objectContaining({
+ enrollmentType: EnrollmentType.API,
+ operation: CertificateIssuanceOperation.SIGN
+ })
+ })
+ );
});
it("should throw ForbiddenRequestError when profile is not configured for API enrollment", async () => {
diff --git a/backend/src/services/certificate-v3/certificate-v3-service.ts b/backend/src/services/certificate-v3/certificate-v3-service.ts
index fe320cbfd3..2572bd26c4 100644
--- a/backend/src/services/certificate-v3/certificate-v3-service.ts
+++ b/backend/src/services/certificate-v3/certificate-v3-service.ts
@@ -59,10 +59,12 @@ import { TPkiAlertV2QueueServiceFactory } from "@app/services/pki-alert-v2/pki-a
import { PkiAlertEventType } from "@app/services/pki-alert-v2/pki-alert-v2-types";
import { TProjectDALFactory } from "@app/services/project/project-dal";
import { getProjectKmsCertificateKeyId } from "@app/services/project/project-fns";
+import { TTelemetryServiceFactory } from "@app/services/telemetry/telemetry-service";
import { TUserDALFactory } from "@app/services/user/user-dal";
import {
CertExtendedKeyUsageType,
+ CertificateIssuanceOperation,
CertKeyUsageType,
CertPolicyState,
mapExtendedKeyUsageToLegacy,
@@ -86,6 +88,7 @@ import {
validateAlgorithmCompatibility,
validateCaSupport
} from "../certificate-common/certificate-issuance-utils";
+import { reportCertificateIssued } from "../certificate-common/certificate-telemetry-fns";
import {
bufferToString,
buildCertificateSubjectFromTemplate,
@@ -174,6 +177,7 @@ type TCertificateV3ServiceFactoryDep = {
>;
apiEnrollmentConfigDAL: Pick<TApiEnrollmentConfigDALFactory, "findById">;
licenseService: Pick<TLicenseServiceFactory, "getPlan">;
+ telemetryService: Pick<TTelemetryServiceFactory, "sendPostHogEvents">;
};
export type TCertificateV3ServiceFactory = ReturnType<typeof certificateV3ServiceFactory>;
@@ -702,8 +706,53 @@ export const certificateV3ServiceFactory = ({
pkiAlertV2Queue,
pkiApplicationProfileDAL,
apiEnrollmentConfigDAL,
- licenseService
+ licenseService,
+ telemetryService
}: TCertificateV3ServiceFactoryDep) => {
+ const $reportCertificateIssued = async ({
+ orgId,
+ projectId,
+ profileId,
+ applicationId,
+ enrollmentType,
+ operation,
+ actor,
+ actorId
+ }: {
+ orgId?: string;
+ projectId: string;
+ profileId?: string | null;
+ applicationId?: string | null;
+ enrollmentType: EnrollmentType;
+ operation: CertificateIssuanceOperation;
+ actor?: ActorType;
+ actorId?: string;
+ }) => {
+ let distinctId: string | undefined;
+ try {
+ if (actor === ActorType.USER && actorId) {
+ const user = await requestMemoize(requestMemoKeys.userFindById(actorId), () => userDAL.findById(actorId));
+ distinctId = user?.username ?? user?.email;
+ } else if (actor === ActorType.IDENTITY && actorId) {
+ distinctId = `identity-${actorId}`;
+ }
+ } catch (error) {
+ logger.debug({ error }, "Failed to resolve distinctId for certificate issuance telemetry");
+ }
+
+ await reportCertificateIssued({
+ telemetryService,
+ projectDAL,
+ orgId,
+ projectId,
+ profileId,
+ applicationId,
+ enrollmentType,
+ operation,
+ distinctId
+ });
+ };
+
const $resolveApplicationIdForProfile = async (
profile: {
id: string;
@@ -1268,6 +1317,17 @@ export const certificateV3ServiceFactory = ({
logger.debug("Failed to queue PKI issuance alert event");
}
+ await $reportCertificateIssued({
+ orgId: profile.project?.orgId ?? actorOrgId,
+ projectId: profile.projectId,
+ profileId,
+ applicationId,
+ enrollmentType: EnrollmentType.API,
+ operation: CertificateIssuanceOperation.ISSUE,
+ actor,
+ actorId
+ });
+
return {
status: CertificateRequestStatus.ISSUED,
certificate: selfSignedResult.certificate.toString("utf8"),
@@ -1491,6 +1551,17 @@ export const certificateV3ServiceFactory = ({
logger.debug("Failed to queue PKI issuance alert event");
}
+ await $reportCertificateIssued({
+ orgId: profile.project?.orgId ?? actorOrgId,
+ projectId: profile.projectId,
+ profileId,
+ applicationId,
+ enrollmentType: EnrollmentType.API,
+ operation: CertificateIssuanceOperation.ISSUE,
+ actor,
+ actorId
+ });
+
return {
status: CertificateRequestStatus.ISSUED,
certificate: bufferToString(certificate),
@@ -1940,6 +2011,17 @@ export const certificateV3ServiceFactory = ({
logger.debug("Failed to queue PKI issuance alert event");
}
+ await $reportCertificateIssued({
+ orgId: profile.project?.orgId ?? actorOrgId,
+ projectId: profile.projectId,
+ profileId,
+ applicationId,
+ enrollmentType,
+ operation: CertificateIssuanceOperation.SIGN,
+ actor,
+ actorId
+ });
+
return {
status: CertificateRequestStatus.ISSUED,
certificate: certificateString,
@@ -2922,6 +3004,17 @@ export const certificateV3ServiceFactory = ({
logger.debug("Failed to queue PKI renewal alert event");
}
+ await $reportCertificateIssued({
+ orgId: renewalResult.profile?.project?.orgId ?? actorOrgId,
+ projectId: renewalResult.originalCert.projectId,
+ profileId: renewalResult.originalCert.profileId ?? undefined,
+ applicationId: renewalResult.originalCert.applicationId ?? undefined,
+ enrollmentType: EnrollmentType.API,
+ operation: CertificateIssuanceOperation.RENEW,
+ actor,
+ actorId
+ });
+
return {
status: CertificateRequestStatus.ISSUED,
certificate: renewalResult.certificate,
diff --git a/backend/src/services/telemetry/telemetry-service.ts b/backend/src/services/telemetry/telemetry-service.ts
index 5b26793804..da56e81f16 100644
--- a/backend/src/services/telemetry/telemetry-service.ts
+++ b/backend/src/services/telemetry/telemetry-service.ts
@@ -38,7 +38,8 @@ export const POSTHOG_AGGREGATED_EVENTS = [
// in the grouping key so each unique value produces its own aggregated event with the
// property as a flat string — enabling clean PostHog breakdowns.
const AGGREGATION_BREAKDOWN_DIMENSIONS: Partial<Record<PostHogEventTypes, string[]>> = {
- [PostHogEventTypes.PkiSyncExecuted]: ["destination"]
+ [PostHogEventTypes.PkiSyncExecuted]: ["destination"],
+ [PostHogEventTypes.IssueCert]: ["enrollmentType", "operation"]
};
// Bucket configuration
diff --git a/backend/src/services/telemetry/telemetry-types.ts b/backend/src/services/telemetry/telemetry-types.ts
index dddbb66e0e..0a09eb5843 100644
--- a/backend/src/services/telemetry/telemetry-types.ts
+++ b/backend/src/services/telemetry/telemetry-types.ts
@@ -22,6 +22,7 @@ import { SecretScanningDataSource } from "@app/ee/services/secret-scanning-v2/se
import { EnforcementLevel, SecretSharingAccessType } from "@app/lib/types";
import { AppConnection } from "@app/services/app-connection/app-connection-enums";
import { AuthMethod } from "@app/services/auth/auth-type";
+import { CertificateIssuanceOperation } from "@app/services/certificate-common/certificate-constants";
import { WebhookType } from "@app/services/webhook/webhook-types";
export type HubSpotSignupMethod = AuthMethod | "invite";
@@ -152,6 +153,7 @@ export enum PostHogEventTypes {
CertificateProfileCreated = "Certificate Profile Created",
CertificateProfileDeleted = "Certificate Profile Deleted",
PkiApplicationCreated = "PKI Application Created",
+ PkiApplicationUpdated = "PKI Application Updated",
PkiApplicationDeleted = "PKI Application Deleted",
PkiApplicationMemberAdded = "PKI Application Member Added",
PkiApplicationProfileAttached = "PKI Application Profile Attached",
@@ -622,8 +624,14 @@ export type TIssueCertificateEvent = {
caId?: string;
certificateTemplateId?: string;
subscriberId?: string;
- commonName: string;
+ commonName?: string;
userAgent?: string;
+ orgId?: string;
+ projectId?: string;
+ profileId?: string;
+ applicationId?: string;
+ enrollmentType?: string;
+ operation?: CertificateIssuanceOperation;
};
};
@@ -1284,6 +1292,15 @@ export type TPkiApplicationCreatedEvent = {
event: PostHogEventTypes.PkiApplicationCreated;
properties: {
orgId: string;
+ applicationId?: string;
+ };
+};
+
+export type TPkiApplicationUpdatedEvent = {
+ event: PostHogEventTypes.PkiApplicationUpdated;
+ properties: {
+ orgId: string;
+ applicationId?: string;
};
};
@@ -1291,6 +1308,7 @@ export type TPkiApplicationDeletedEvent = {
event: PostHogEventTypes.PkiApplicationDeleted;
properties: {
orgId: string;
+ applicationId?: string;
};
};
@@ -2167,6 +2185,7 @@ export type TPostHogEvent = {
| TCertificateProfileCreatedEvent
| TCertificateProfileDeletedEvent
| TPkiApplicationCreatedEvent
+ | TPkiApplicationUpdatedEvent
| TPkiApplicationDeletedEvent
| TPkiApplicationMemberAddedEvent
| TPkiApplicationProfileAttachedEvent