diff --git a/packages/backend/src/helpers/telemetry/index.ts b/packages/backend/src/helpers/telemetry/index.ts index eacea02d..998d3a72 100644 --- a/packages/backend/src/helpers/telemetry/index.ts +++ b/packages/backend/src/helpers/telemetry/index.ts @@ -6,6 +6,7 @@ import Step from '../../models/step'; import Flow from '../../models/flow'; import Execution from '../../models/execution'; import ExecutionStep from '../../models/execution-step'; +import Connection from '../../models/connection'; const WRITE_KEY = '284Py4VgK2MsNYV7xlKzyrALx0v'; const DATA_PLANE_URL = 'https://telemetry.automatisch.io/v1/batch'; @@ -98,6 +99,26 @@ class Telemetry { updatedAt: executionStep.updatedAt, }); } + + connectionCreated(connection: Connection) { + this.track('connectionCreated', { + connectionId: connection.id, + key: connection.key, + verified: connection.verified, + createdAt: connection.createdAt, + updatedAt: connection.updatedAt, + }); + } + + connectionUpdated(connection: Connection) { + this.track('connectionUpdated', { + connectionId: connection.id, + key: connection.key, + verified: connection.verified, + createdAt: connection.createdAt, + updatedAt: connection.updatedAt, + }); + } } const telemetry = new Telemetry(); diff --git a/packages/backend/src/models/connection.ts b/packages/backend/src/models/connection.ts index 5f8cb669..2c53c6ee 100644 --- a/packages/backend/src/models/connection.ts +++ b/packages/backend/src/models/connection.ts @@ -5,6 +5,7 @@ import Base from './base'; import User from './user'; import appConfig from '../config/app'; import { IJSONObject } from '@automatisch/types'; +import Telemetry from '../helpers/telemetry'; class Connection extends Base { id!: string; @@ -87,6 +88,16 @@ class Connection extends Base { async $afterFind(): Promise { this.decryptData(); } + + async $afterInsert(queryContext: QueryContext) { + await super.$afterInsert(queryContext); + Telemetry.connectionCreated(this); + } + + async $afterUpdate(opt: ModelOptions, queryContext: QueryContext) { + await super.$afterUpdate(opt, queryContext); + Telemetry.connectionUpdated(this); + } } export default Connection;