feat: add telemetry events for integration deletion and synchronization, including new event types and properties

This commit is contained in:
Victor Santos
2025-11-26 11:44:54 -03:00
parent 5c7f07c838
commit 0e49aaf1e6
2 changed files with 111 additions and 33 deletions
@@ -10,7 +10,12 @@ import { verifyAuth } from "@app/server/plugins/auth/verify-auth";
import { AuthMode } from "@app/services/auth/auth-type"; import { AuthMode } from "@app/services/auth/auth-type";
import { IntegrationMetadataSchema } from "@app/services/integration/integration-schema"; import { IntegrationMetadataSchema } from "@app/services/integration/integration-schema";
import { Integrations } from "@app/services/integration-auth/integration-list"; import { Integrations } from "@app/services/integration-auth/integration-list";
import { PostHogEventTypes, TIntegrationCreatedEvent } from "@app/services/telemetry/telemetry-types"; import {
PostHogEventTypes,
TIntegrationCreatedEvent,
TIntegrationDeletedEvent,
TIntegrationSyncedEvent
} from "@app/services/telemetry/telemetry-types";
import {} from "../sanitizedSchemas"; import {} from "../sanitizedSchemas";
@@ -288,31 +293,46 @@ export const registerIntegrationRouter = async (server: FastifyZodProvider) => {
shouldDeleteIntegrationSecrets: req.query.shouldDeleteIntegrationSecrets shouldDeleteIntegrationSecrets: req.query.shouldDeleteIntegrationSecrets
}); });
const deleteIntegrationEventProperty = shake({
integrationId: integration.id,
integration: integration.integration,
environment: integration.environment.slug,
secretPath: integration.secretPath,
url: integration.url,
app: integration.app,
appId: integration.appId,
targetEnvironment: integration.targetEnvironment,
targetEnvironmentId: integration.targetEnvironmentId,
targetService: integration.targetService,
targetServiceId: integration.targetServiceId,
path: integration.path,
region: integration.region
}) as TIntegrationDeletedEvent["properties"];
await server.services.auditLog.createAuditLog({ await server.services.auditLog.createAuditLog({
...req.auditLogInfo, ...req.auditLogInfo,
projectId: integration.projectId, projectId: integration.projectId,
event: { event: {
type: EventType.DELETE_INTEGRATION, type: EventType.DELETE_INTEGRATION,
// eslint-disable-next-line // eslint-disable-next-line
metadata: shake({ metadata: {
integrationId: integration.id, ...deleteIntegrationEventProperty,
integration: integration.integration,
environment: integration.environment.slug,
secretPath: integration.secretPath,
url: integration.url,
app: integration.app,
appId: integration.appId,
targetEnvironment: integration.targetEnvironment,
targetEnvironmentId: integration.targetEnvironmentId,
targetService: integration.targetService,
targetServiceId: integration.targetServiceId,
path: integration.path,
region: integration.region,
shouldDeleteIntegrationSecrets: req.query.shouldDeleteIntegrationSecrets shouldDeleteIntegrationSecrets: req.query.shouldDeleteIntegrationSecrets
// eslint-disable-next-line } as any
}) as any
} }
}); });
await server.services.telemetry.sendPostHogEvents({
event: PostHogEventTypes.IntegrationDeleted,
organizationId: req.permission.orgId,
distinctId: getTelemetryDistinctId(req),
properties: {
...deleteIntegrationEventProperty,
projectId: integration.projectId,
...req.auditLogInfo
}
});
return { integration }; return { integration };
} }
}); });
@@ -351,28 +371,41 @@ export const registerIntegrationRouter = async (server: FastifyZodProvider) => {
id: req.params.integrationId id: req.params.integrationId
}); });
const syncIntegrationEventProperty = shake({
integrationId: integration.id,
integration: integration.integration,
environment: integration.environment.slug,
secretPath: integration.secretPath,
url: integration.url,
app: integration.app,
appId: integration.appId,
targetEnvironment: integration.targetEnvironment,
targetEnvironmentId: integration.targetEnvironmentId,
targetService: integration.targetService,
targetServiceId: integration.targetServiceId,
path: integration.path,
region: integration.region
}) as TIntegrationSyncedEvent["properties"];
await server.services.auditLog.createAuditLog({ await server.services.auditLog.createAuditLog({
...req.auditLogInfo, ...req.auditLogInfo,
projectId: integration.projectId, projectId: integration.projectId,
event: { event: {
type: EventType.MANUAL_SYNC_INTEGRATION, type: EventType.MANUAL_SYNC_INTEGRATION,
// eslint-disable-next-line // eslint-disable-next-line
metadata: shake({ metadata: syncIntegrationEventProperty as any
integrationId: integration.id, }
integration: integration.integration, });
environment: integration.environment.slug,
secretPath: integration.secretPath, await server.services.telemetry.sendPostHogEvents({
url: integration.url, event: PostHogEventTypes.IntegrationSynced,
app: integration.app, organizationId: req.permission.orgId,
appId: integration.appId, distinctId: getTelemetryDistinctId(req),
targetEnvironment: integration.targetEnvironment, properties: {
targetEnvironmentId: integration.targetEnvironmentId, ...syncIntegrationEventProperty,
targetService: integration.targetService, projectId: integration.projectId,
targetServiceId: integration.targetServiceId, isManualSync: true,
path: integration.path, ...req.auditLogInfo
region: integration.region
// eslint-disable-next-line
}) as any
} }
}); });
@@ -21,6 +21,8 @@ export enum PostHogEventTypes {
SecretScannerPush = "cloud secret scan", SecretScannerPush = "cloud secret scan",
ProjectCreated = "Project Created", ProjectCreated = "Project Created",
IntegrationCreated = "Integration Created", IntegrationCreated = "Integration Created",
IntegrationSynced = "Integration Synced",
IntegrationDeleted = "Integration Deleted",
MachineIdentityCreated = "Machine Identity Created", MachineIdentityCreated = "Machine Identity Created",
UserOrgInvitation = "User Org Invitation", UserOrgInvitation = "User Org Invitation",
TelemetryInstanceStats = "Self Hosted Instance Stats", TelemetryInstanceStats = "Self Hosted Instance Stats",
@@ -126,6 +128,47 @@ export type TIntegrationCreatedEvent = {
}; };
}; };
export type TIntegrationSyncedEvent = {
event: PostHogEventTypes.IntegrationSynced;
properties: {
projectId: string;
integrationId: string;
integration: string;
environment: string;
secretPath: string;
isManualSync: boolean;
url?: string;
app?: string;
appId?: string;
targetEnvironment?: string;
targetEnvironmentId?: string;
targetService?: string;
targetServiceId?: string;
path?: string;
region?: string;
};
};
export type TIntegrationDeletedEvent = {
event: PostHogEventTypes.IntegrationDeleted;
properties: {
projectId: string;
integrationId: string;
integration: string;
environment: string;
secretPath: string;
url?: string;
app?: string;
appId?: string;
targetEnvironment?: string;
targetEnvironmentId?: string;
targetService?: string;
targetServiceId?: string;
path?: string;
region?: string;
};
};
export type TUserOrgInvitedEvent = { export type TUserOrgInvitedEvent = {
event: PostHogEventTypes.UserOrgInvitation; event: PostHogEventTypes.UserOrgInvitation;
properties: { properties: {
@@ -249,6 +292,8 @@ export type TPostHogEvent = { distinctId: string; organizationId?: string } & (
| TUserOrgInvitedEvent | TUserOrgInvitedEvent
| TMachineIdentityCreatedEvent | TMachineIdentityCreatedEvent
| TIntegrationCreatedEvent | TIntegrationCreatedEvent
| TIntegrationSyncedEvent
| TIntegrationDeletedEvent
| TProjectCreateEvent | TProjectCreateEvent
| TTelemetryInstanceStatsEvent | TTelemetryInstanceStatsEvent
| TSecretRequestCreatedEvent | TSecretRequestCreatedEvent