feat: Generate organization and instance id for telemetry
This commit is contained in:
@@ -1,19 +1,31 @@
|
||||
import Analytics, { apiObject } from '@rudderstack/rudder-sdk-node';
|
||||
import organizationId from './organization-id';
|
||||
import instanceId from './instance-id';
|
||||
import appConfig from '../../config/app';
|
||||
|
||||
const WRITE_KEY = '284Py4VgK2MsNYV7xlKzyrALx0v';
|
||||
const DATA_PLANE_URL = 'https://telemetry.automatisch.io/v1/batch';
|
||||
|
||||
class Telemetry {
|
||||
organizationId: string;
|
||||
instanceId: string;
|
||||
client: Analytics;
|
||||
|
||||
constructor() {
|
||||
this.client = new Analytics(WRITE_KEY, DATA_PLANE_URL);
|
||||
this.organizationId = organizationId();
|
||||
this.instanceId = instanceId();
|
||||
}
|
||||
|
||||
track(name: string, properties: apiObject) {
|
||||
properties = {
|
||||
...properties,
|
||||
appEnv: appConfig.appEnv,
|
||||
instanceId: this.instanceId,
|
||||
};
|
||||
|
||||
this.client.track({
|
||||
userId: 'sample',
|
||||
userId: this.organizationId,
|
||||
event: name,
|
||||
properties,
|
||||
});
|
7
packages/backend/src/helpers/telemetry/instance-id.ts
Normal file
7
packages/backend/src/helpers/telemetry/instance-id.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import Crypto from 'crypto';
|
||||
|
||||
const instanceId = () => {
|
||||
return Crypto.randomUUID();
|
||||
};
|
||||
|
||||
export default instanceId;
|
13
packages/backend/src/helpers/telemetry/organization-id.ts
Normal file
13
packages/backend/src/helpers/telemetry/organization-id.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import CryptoJS from 'crypto-js';
|
||||
import appConfig from '../../config/app';
|
||||
|
||||
const organizationId = () => {
|
||||
const key = appConfig.encryptionKey;
|
||||
const hash = CryptoJS.SHA3(key, { outputLength: 256 }).toString(
|
||||
CryptoJS.enc.Hex
|
||||
);
|
||||
|
||||
return hash;
|
||||
};
|
||||
|
||||
export default organizationId;
|
Reference in New Issue
Block a user