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:
parent
d06e0d26c6
commit
3fab15ae3e
2 changed files with 23 additions and 8 deletions
|
|
@ -15,10 +15,25 @@ async function getObservabilityConfig() {
|
||||||
try {
|
try {
|
||||||
const { getSettings } = await import("./settingsRepo.js");
|
const { getSettings } = await import("./settingsRepo.js");
|
||||||
const settings = await getSettings();
|
const settings = await getSettings();
|
||||||
const envEnabled = process.env.OBSERVABILITY_ENABLED !== "false";
|
const envRequestLogs = process.env.ENABLE_REQUEST_LOGS;
|
||||||
const enabled = typeof settings.enableObservability2 === "boolean"
|
if (envRequestLogs !== undefined) {
|
||||||
? settings.enableObservability2
|
const enabled = envRequestLogs.toLowerCase() === "true";
|
||||||
: envEnabled;
|
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 = {
|
cachedConfig = {
|
||||||
enabled,
|
enabled,
|
||||||
maxRecords: settings.observabilityMaxRecords || parseInt(process.env.OBSERVABILITY_MAX_RECORDS || String(DEFAULT_MAX_RECORDS), 10),
|
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) {
|
export async function saveRequestDetail(detail) {
|
||||||
const config = await getObservabilityConfig();
|
const config = await getObservabilityConfig();
|
||||||
if (!config.enabled) return;
|
if (!config.enabled) {return;}
|
||||||
|
|
||||||
writeBuffer.push(detail);
|
writeBuffer.push(detail);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,7 @@ const DEFAULT_SETTINGS = {
|
||||||
oidcClientSecret: "",
|
oidcClientSecret: "",
|
||||||
oidcScopes: "openid profile email",
|
oidcScopes: "openid profile email",
|
||||||
oidcLoginLabel: "Sign in with OIDC",
|
oidcLoginLabel: "Sign in with OIDC",
|
||||||
enableObservability: true,
|
enableObservability: false,
|
||||||
observabilityMaxRecords: 1000,
|
observabilityMaxRecords: 1000,
|
||||||
observabilityBatchSize: 20,
|
observabilityBatchSize: 20,
|
||||||
observabilityFlushIntervalMs: 5000,
|
observabilityFlushIntervalMs: 5000,
|
||||||
|
|
@ -83,13 +83,13 @@ export async function getSettings() {
|
||||||
export async function updateSettings(updates) {
|
export async function updateSettings(updates) {
|
||||||
const db = await getAdapter();
|
const db = await getAdapter();
|
||||||
let next;
|
let next;
|
||||||
db.transaction(() => {
|
db.transaction(function () {
|
||||||
const row = db.get(`SELECT data FROM settings WHERE id = 1`);
|
const row = db.get(`SELECT data FROM settings WHERE id = 1`);
|
||||||
const current = row ? parseJson(row.data, {}) : {};
|
const current = row ? parseJson(row.data, {}) : {};
|
||||||
next = { ...current, ...updates };
|
next = { ...current, ...updates };
|
||||||
db.run(
|
db.run(
|
||||||
`INSERT INTO settings(id, data) VALUES(1, ?) ON CONFLICT(id) DO UPDATE SET data = excluded.data`,
|
`INSERT INTO settings(id, data) VALUES(1, ?) ON CONFLICT(id) DO UPDATE SET data = excluded.data`,
|
||||||
[stringifyJson(next)]
|
[stringifyJson(next)],
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
return mergeWithDefaults(next);
|
return mergeWithDefaults(next);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue