mirror of
https://github.com/directus/directus.git
synced 2026-04-25 03:00:53 -04:00
Add telemetry
This commit is contained in:
74
api/src/utils/track.ts
Normal file
74
api/src/utils/track.ts
Normal file
@@ -0,0 +1,74 @@
|
||||
import axios from 'axios';
|
||||
import os from 'os';
|
||||
import { machineId } from 'node-machine-id';
|
||||
import ms from 'ms';
|
||||
|
||||
import logger from '../logger';
|
||||
|
||||
import env from '../env';
|
||||
// @ts-ignore
|
||||
import { version } from '../../package.json';
|
||||
|
||||
export async function track(event: string) {
|
||||
const info = await getEnvInfo(event);
|
||||
|
||||
try {
|
||||
await axios.post('https://telemetry.directus.io/', info);
|
||||
} catch (err) {
|
||||
if (process.env.NODE_ENV === 'development') {
|
||||
logger.error(err);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
async function getEnvInfo(event: string) {
|
||||
return {
|
||||
version: version,
|
||||
event: event,
|
||||
project_id: env.KEY,
|
||||
machine_id: await machineId(),
|
||||
environment: process.env.NODE_ENV,
|
||||
stack: 'node',
|
||||
os: {
|
||||
arch: os.arch(),
|
||||
platform: os.platform(),
|
||||
release: os.release(),
|
||||
},
|
||||
rate_limiter: {
|
||||
enabled: env.RATE_LIMITER_ENABLED,
|
||||
points: +env.RATE_LIMITER_POINTS,
|
||||
duration: +env.RATE_LIMITER_DURATION,
|
||||
store: env.RATE_LIMITER_STORE,
|
||||
},
|
||||
cache: {
|
||||
enabled: env.CACHE_ENABLED,
|
||||
ttl: ms(env.CACHE_TTL),
|
||||
store: env.CACHE_STORE,
|
||||
},
|
||||
storage: {
|
||||
drivers: getStorageDrivers()
|
||||
},
|
||||
cors: {
|
||||
enabled: env.CORS_ENABLED,
|
||||
},
|
||||
email: {
|
||||
transport: env.EMAIL_TRANSPORT,
|
||||
},
|
||||
oauth: {
|
||||
providers: env.OAUTH_PROVIDERS.split(',').filter((p?: string) => p).map((p: string) => p.trim()),
|
||||
},
|
||||
db_client: env.DB_CLIENT
|
||||
}
|
||||
}
|
||||
|
||||
function getStorageDrivers() {
|
||||
const drivers: string[] = [];
|
||||
const locations = env.STORAGE_LOCATIONS.split(',').filter((l?: string) => l).map((l: string) => l.trim());
|
||||
|
||||
for (const location of locations) {
|
||||
const driver = env[`STORAGE_${location.toUpperCase()}_DRIVER`];
|
||||
drivers.push(driver);
|
||||
}
|
||||
|
||||
return drivers;
|
||||
}
|
||||
Reference in New Issue
Block a user