misc: added env-based flag for enabling telemetry

This commit is contained in:
Sheen Capadngan
2024-06-06 00:56:11 +08:00
parent 33b49f4466
commit 9a7e05369c
4 changed files with 11 additions and 3 deletions

View File

@@ -64,4 +64,5 @@ CLIENT_SECRET_GITHUB_LOGIN=
CLIENT_ID_GITLAB_LOGIN= CLIENT_ID_GITLAB_LOGIN=
CLIENT_SECRET_GITLAB_LOGIN= CLIENT_SECRET_GITLAB_LOGIN=
OTEL_COLLECTOR_OTLP_URL= OTEL_COLLECTOR_OTLP_URL=
OTEL_TELEMETRY_COLLECTION_ENABLED=

View File

@@ -120,6 +120,7 @@ const envSchema = z
.optional(), .optional(),
INFISICAL_CLOUD: zodStrBool.default("false"), INFISICAL_CLOUD: zodStrBool.default("false"),
MAINTENANCE_MODE: zodStrBool.default("false"), MAINTENANCE_MODE: zodStrBool.default("false"),
OTEL_TELEMETRY_COLLECTION_ENABLED: zodStrBool.default("false"),
OTEL_COLLECTOR_OTLP_URL: zpStr(z.string().optional()) OTEL_COLLECTOR_OTLP_URL: zpStr(z.string().optional())
}) })
.transform((data) => ({ .transform((data) => ({

View File

@@ -15,7 +15,9 @@ const run = async () => {
const logger = await initLogger(); const logger = await initLogger();
const appCfg = initEnvConfig(logger); const appCfg = initEnvConfig(logger);
await initTelemetry({ otlpURL: appCfg.OTEL_COLLECTOR_OTLP_URL }); if (appCfg.OTEL_TELEMETRY_COLLECTION_ENABLED) {
await initTelemetry({ otlpURL: appCfg.OTEL_COLLECTOR_OTLP_URL });
}
const db = initDbConnection({ const db = initDbConnection({
dbConnectionUri: appCfg.DB_CONNECTION_URI, dbConnectionUri: appCfg.DB_CONNECTION_URI,

View File

@@ -63,7 +63,11 @@ export const main = async ({ db, smtp, logger, queue, keyStore }: TMain) => {
}); });
// pull ip based on various proxy headers // pull ip based on various proxy headers
await server.register(fastifyIp); await server.register(fastifyIp);
await server.register(apiMetrics);
if (appCfg.OTEL_TELEMETRY_COLLECTION_ENABLED) {
await server.register(apiMetrics);
}
await server.register(fastifySwagger); await server.register(fastifySwagger);
await server.register(fastifyFormBody); await server.register(fastifyFormBody);
await server.register(fastifyErrHandler); await server.register(fastifyErrHandler);