fix(db): implement ENABLE_REQUEST_LOGS env var override
- Add config priority chain: ENABLE_REQUEST_LOGS > UI setting > OBSERVABILITY_ENABLED fallback - Fix transaction callback syntax from arrow to function - Update saveRequestDetail guard to early return instead of semicolon - Default enableObservability to false (opt-in)
This commit is contained in:
@@ -15,10 +15,25 @@ async function getObservabilityConfig() {
|
||||
try {
|
||||
const { getSettings } = await import("./settingsRepo.js");
|
||||
const settings = await getSettings();
|
||||
const envEnabled = process.env.OBSERVABILITY_ENABLED !== "false";
|
||||
const enabled = typeof settings.enableObservability2 === "boolean"
|
||||
? settings.enableObservability2
|
||||
: envEnabled;
|
||||
const envRequestLogs = process.env.ENABLE_REQUEST_LOGS;
|
||||
if (envRequestLogs !== undefined) {
|
||||
const enabled = envRequestLogs.toLowerCase() === "true";
|
||||
cachedConfig = {
|
||||
enabled,
|
||||
maxRecords: settings.observabilityMaxRecords || parseInt(process.env.OBSERVABILITY_MAX_RECORDS || String(DEFAULT_MAX_RECORDS), 10),
|
||||
batchSize: settings.observabilityBatchSize || parseInt(process.env.OBSERVABILITY_BATCH_SIZE || String(DEFAULT_BATCH_SIZE), 10),
|
||||
flushIntervalMs: settings.observabilityFlushIntervalMs || parseInt(process.env.OBSERVABILITY_FLUSH_INTERVAL_MS || String(DEFAULT_FLUSH_INTERVAL_MS), 10),
|
||||
maxJsonSize: (settings.observabilityMaxJsonSize || parseInt(process.env.OBSERVABILITY_MAX_JSON_SIZE || "5", 10)) * 1024,
|
||||
};
|
||||
cachedConfigTs = Date.now();
|
||||
return cachedConfig;
|
||||
}
|
||||
const envFallback = process.env.OBSERVABILITY_ENABLED !== "false";
|
||||
const uiFlag = typeof settings.enableObservability === "boolean";
|
||||
const enabled = uiFlag
|
||||
? settings.enableObservability
|
||||
: envFallback;
|
||||
|
||||
cachedConfig = {
|
||||
enabled,
|
||||
maxRecords: settings.observabilityMaxRecords || parseInt(process.env.OBSERVABILITY_MAX_RECORDS || String(DEFAULT_MAX_RECORDS), 10),
|
||||
@@ -125,7 +140,7 @@ async function flushToDatabase() {
|
||||
|
||||
export async function saveRequestDetail(detail) {
|
||||
const config = await getObservabilityConfig();
|
||||
if (!config.enabled) return;
|
||||
if (!config.enabled) {return;}
|
||||
|
||||
writeBuffer.push(detail);
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ const DEFAULT_SETTINGS = {
|
||||
oidcClientSecret: "",
|
||||
oidcScopes: "openid profile email",
|
||||
oidcLoginLabel: "Sign in with OIDC",
|
||||
enableObservability: true,
|
||||
enableObservability: false,
|
||||
observabilityMaxRecords: 1000,
|
||||
observabilityBatchSize: 20,
|
||||
observabilityFlushIntervalMs: 5000,
|
||||
@@ -83,13 +83,13 @@ export async function getSettings() {
|
||||
export async function updateSettings(updates) {
|
||||
const db = await getAdapter();
|
||||
let next;
|
||||
db.transaction(() => {
|
||||
db.transaction(function () {
|
||||
const row = db.get(`SELECT data FROM settings WHERE id = 1`);
|
||||
const current = row ? parseJson(row.data, {}) : {};
|
||||
next = { ...current, ...updates };
|
||||
db.run(
|
||||
`INSERT INTO settings(id, data) VALUES(1, ?) ON CONFLICT(id) DO UPDATE SET data = excluded.data`,
|
||||
[stringifyJson(next)]
|
||||
[stringifyJson(next)],
|
||||
);
|
||||
});
|
||||
return mergeWithDefaults(next);
|
||||
|
||||
Reference in New Issue
Block a user