feat: Implement telemetry for connection creation and updates

This commit is contained in:
Faruk AYDIN
2022-05-05 01:34:26 +02:00
parent 00b8f83da5
commit 21836bc5f1
2 changed files with 32 additions and 0 deletions

View File

@@ -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();

View File

@@ -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<void> {
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;