- Remove last runtimeEnv import from processMessage.ts - Add env: Env param to all functions with 'Cannot find name env' errors - Convert initRedisV2 to lazy initialization (ensureRedisV2 + Proxy) - Add Bindings: Env to StripeWebhookHonoEnv - Fix 12+ files across external/, internal/, queue/ modules - Scanning test passes: 1/1 (runtime-env-imports.test.ts)
53 lines
1.4 KiB
TypeScript
53 lines
1.4 KiB
TypeScript
import { createLogger } from "@/external/logtail/logtailUtils.js";
|
|
import { addRedisToLogs } from "@/utils/logging/addContextToLogs.js";
|
|
import type { RedisKeyContext } from "./parseRedisKeyContext.js";
|
|
import type { ResolvedThresholds } from "./redisSlowlogConfig.js";
|
|
import { shouldEmitSlowLog } from "./slowLogRateLimit.js";
|
|
|
|
/**
|
|
* Emits a structured `redis_slow_command` log for commands that exceeded
|
|
* their severe threshold. Rate-limited per-operation to avoid flooding.
|
|
*/
|
|
export const emitRedisSlowLog = ({
|
|
operation,
|
|
durationMs,
|
|
thresholds,
|
|
keyContext,
|
|
region,
|
|
key,
|
|
}: {
|
|
operation: string;
|
|
durationMs: number;
|
|
thresholds: ResolvedThresholds;
|
|
keyContext: RedisKeyContext;
|
|
region?: string;
|
|
key?: string;
|
|
}): void => {
|
|
try {
|
|
if (!shouldEmitSlowLog({ operation })) return;
|
|
|
|
const slowMs = thresholds.slowMs;
|
|
const breachRatio = slowMs > 0 ? durationMs / slowMs : 0;
|
|
|
|
addRedisToLogs({
|
|
logger,
|
|
redisData: {
|
|
operation,
|
|
duration_ms: durationMs,
|
|
slow_ms: slowMs,
|
|
base_slow_ms: thresholds.baseSlowMs,
|
|
region_baseline_ms: thresholds.regionBaselineMs,
|
|
severe_ms: thresholds.severeMs,
|
|
breach_ratio: breachRatio,
|
|
region,
|
|
key,
|
|
org_id: keyContext.orgId,
|
|
customer_id: keyContext.customerId,
|
|
entity_id: keyContext.entityId,
|
|
},
|
|
}).warn({ type: "redis_slow_command" }, "Redis slow command");
|
|
} catch {
|
|
// swallow — telemetry must never break app commands
|
|
}
|
|
};
|