mirror of
https://github.com/EvolutionAPI/evolution-api.git
synced 2025-12-24 06:07:45 -06:00
feat(config): add telemetry and metrics configuration options
- Introduce new environment variables for telemetry and Prometheus metrics in .env.example - Create example configuration files for Prometheus and Grafana dashboards - Update main application to utilize new configuration settings for Sentry, audio converter, and proxy - Enhance channel services to support audio conversion API integration - Implement middleware for metrics IP whitelisting and basic authentication in routes
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import { configService, Sentry as SentryConfig } from '@config/env.config';
|
||||
import * as Sentry from '@sentry/node';
|
||||
|
||||
const dsn = process.env.SENTRY_DSN;
|
||||
const sentryConfig = configService.get<SentryConfig>('SENTRY');
|
||||
|
||||
if (dsn) {
|
||||
if (sentryConfig.DSN) {
|
||||
Sentry.init({
|
||||
dsn: dsn,
|
||||
dsn: sentryConfig.DSN,
|
||||
environment: process.env.NODE_ENV || 'development',
|
||||
tracesSampleRate: 1.0,
|
||||
profilesSampleRate: 1.0,
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { configService, Telemetry } from '@config/env.config';
|
||||
import axios from 'axios';
|
||||
import fs from 'fs';
|
||||
|
||||
@@ -10,9 +11,9 @@ export interface TelemetryData {
|
||||
}
|
||||
|
||||
export const sendTelemetry = async (route: string): Promise<void> => {
|
||||
const enabled = process.env.TELEMETRY_ENABLED === undefined || process.env.TELEMETRY_ENABLED === 'true';
|
||||
const telemetryConfig = configService.get<Telemetry>('TELEMETRY');
|
||||
|
||||
if (!enabled) {
|
||||
if (!telemetryConfig.ENABLED) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -27,9 +28,7 @@ export const sendTelemetry = async (route: string): Promise<void> => {
|
||||
};
|
||||
|
||||
const url =
|
||||
process.env.TELEMETRY_URL && process.env.TELEMETRY_URL !== ''
|
||||
? process.env.TELEMETRY_URL
|
||||
: 'https://log.evolution-api.com/telemetry';
|
||||
telemetryConfig.URL && telemetryConfig.URL !== '' ? telemetryConfig.URL : 'https://log.evolution-api.com/telemetry';
|
||||
|
||||
axios
|
||||
.post(url, telemetry)
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import { prismaRepository } from '@api/server.module';
|
||||
import { CacheService } from '@api/services/cache.service';
|
||||
import { CacheConf, configService } from '@config/env.config';
|
||||
import { INSTANCE_DIR } from '@config/path.config';
|
||||
import { AuthenticationState, BufferJSON, initAuthCreds, WAProto as proto } from 'baileys';
|
||||
import fs from 'fs/promises';
|
||||
@@ -85,9 +86,10 @@ export default async function useMultiFileAuthStatePrisma(
|
||||
|
||||
async function writeData(data: any, key: string): Promise<any> {
|
||||
const dataString = JSON.stringify(data, BufferJSON.replacer);
|
||||
const cacheConfig = configService.get<CacheConf>('CACHE');
|
||||
|
||||
if (key != 'creds') {
|
||||
if (process.env.CACHE_REDIS_ENABLED === 'true') {
|
||||
if (cacheConfig.REDIS.ENABLED) {
|
||||
return await cache.hSet(sessionId, key, data);
|
||||
} else {
|
||||
await fs.writeFile(localFile(key), dataString);
|
||||
@@ -101,9 +103,10 @@ export default async function useMultiFileAuthStatePrisma(
|
||||
async function readData(key: string): Promise<any> {
|
||||
try {
|
||||
let rawData;
|
||||
const cacheConfig = configService.get<CacheConf>('CACHE');
|
||||
|
||||
if (key != 'creds') {
|
||||
if (process.env.CACHE_REDIS_ENABLED === 'true') {
|
||||
if (cacheConfig.REDIS.ENABLED) {
|
||||
return await cache.hGet(sessionId, key);
|
||||
} else {
|
||||
if (!(await fileExists(localFile(key)))) return null;
|
||||
@@ -123,8 +126,10 @@ export default async function useMultiFileAuthStatePrisma(
|
||||
|
||||
async function removeData(key: string): Promise<any> {
|
||||
try {
|
||||
const cacheConfig = configService.get<CacheConf>('CACHE');
|
||||
|
||||
if (key != 'creds') {
|
||||
if (process.env.CACHE_REDIS_ENABLED === 'true') {
|
||||
if (cacheConfig.REDIS.ENABLED) {
|
||||
return await cache.hDelete(sessionId, key);
|
||||
} else {
|
||||
await fs.unlink(localFile(key));
|
||||
|
||||
Reference in New Issue
Block a user