diff --git a/packages/backend/src/helpers/telemetry/index.ts b/packages/backend/src/helpers/telemetry/index.ts index 7a85646b..a752de79 100644 --- a/packages/backend/src/helpers/telemetry/index.ts +++ b/packages/backend/src/helpers/telemetry/index.ts @@ -3,6 +3,7 @@ import organizationId from './organization-id'; import instanceId from './instance-id'; import appConfig from '../../config/app'; import Step from '../../models/step'; +import Flow from '../../models/flow'; const WRITE_KEY = '284Py4VgK2MsNYV7xlKzyrALx0v'; const DATA_PLANE_URL = 'https://telemetry.automatisch.io/v1/batch'; @@ -54,6 +55,26 @@ class Telemetry { updatedAt: step.updatedAt, }); } + + flowCreated(flow: Flow) { + this.track('flowCreated', { + flowId: flow.id, + name: flow.name, + active: flow.active, + createdAt: flow.createdAt, + updatedAt: flow.updatedAt, + }); + } + + flowUpdated(flow: Flow) { + this.track('flowUpdated', { + flowId: flow.id, + name: flow.name, + active: flow.active, + createdAt: flow.createdAt, + updatedAt: flow.updatedAt, + }); + } } const telemetry = new Telemetry(); diff --git a/packages/backend/src/models/flow.ts b/packages/backend/src/models/flow.ts index d489ee50..5d6dbf59 100644 --- a/packages/backend/src/models/flow.ts +++ b/packages/backend/src/models/flow.ts @@ -1,8 +1,9 @@ import { ValidationError } from 'objection'; -import type { ModelOptions } from 'objection'; +import type { ModelOptions, QueryContext } from 'objection'; import Base from './base'; import Step from './step'; import Execution from './execution'; +import Telemetry from '../helpers/telemetry'; class Flow extends Base { id!: string; @@ -71,6 +72,16 @@ class Flow extends Base { return; } + + async $afterInsert(queryContext: QueryContext) { + await super.$afterInsert(queryContext); + Telemetry.flowCreated(this); + } + + async $afterUpdate(opt: ModelOptions, queryContext: QueryContext) { + await super.$afterUpdate(opt, queryContext); + Telemetry.flowUpdated(this); + } } export default Flow;