🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
chore: add redis.full_command to redis traces (#13169)
Valery Meleshkinf741f84e9708
diff --git a/packages/shared/src/server/instrumentation/index.ts b/packages/shared/src/server/instrumentation/index.tsindex f9ff20cf49..43a5f537b8 100644--- a/packages/shared/src/server/instrumentation/index.ts+++ b/packages/shared/src/server/instrumentation/index.ts@@ -9,6 +9,31 @@ import { logger } from "../logger";// type CallbackFn<T> = () => T;+/**+ * IORedis request hook that records the full Redis command as a span attribute.+ * Redacts credentials from AUTH/HELLO and values from API key cache operations.+ */+export function ioredisRequestHook(+ span: opentelemetry.Span,+ { cmdName, cmdArgs }: { cmdName: string; cmdArgs: unknown[] },+): void {+ if (!Array.isArray(cmdArgs) || cmdArgs.length === 0) return;+ const cmd = cmdName.toUpperCase();+ // AUTH and HELLO carry raw credentials — redact all args+ if (cmd === "AUTH" || cmd === "HELLO") {+ span.setAttribute("redis.full_command", `${cmdName} [REDACTED]`);+ return;+ }+ const args = [...cmdArgs].map(String);+ // Redact API key cache values: SET [prefix:]api-key:{hash} <json>+ if (args[0]?.includes("api-key:")) {+ for (let i = 1; i < args.length; i++) {+ args[i] = "[REDACTED]";+ }+ }+ span.setAttribute("redis.full_command", `${cmdName} ${args.join(" ")}`);+}+export type TCarrier = {traceparent?: string;tracestate?: string;diff --git a/web/src/observability.config.ts b/web/src/observability.config.tsindex f47413a54d..e2b24a8e0a 100644--- a/web/src/observability.config.ts+++ b/web/src/observability.config.ts@@ -8,6 +8,7 @@ import { PrismaInstrumentation } from "@prisma/instrumentation";import { WinstonInstrumentation } from "@opentelemetry/instrumentation-winston";import { AwsInstrumentation } from "@opentelemetry/instrumentation-aws-sdk";import { BullMQInstrumentation } from "@appsignal/opentelemetry-instrumentation-bullmq";+import { ioredisRequestHook } from "@langfuse/shared/src/server";import {envDetector,processDetector,@@ -31,7 +32,7 @@ const sdk = new NodeSDK({url: `${env.OTEL_EXPORTER_OTLP_ENDPOINT}/v1/traces`,}),instrumentations: [- new IORedisInstrumentation(),+ new IORedisInstrumentation({ requestHook: ioredisRequestHook }),new HttpInstrumentation({requireParentforOutgoingSpans: true,ignoreIncomingRequestHook: (req) => {diff --git a/worker/src/instrumentation.ts b/worker/src/instrumentation.tsindex 4ce431f778..a5213eabaf 100644--- a/worker/src/instrumentation.ts+++ b/worker/src/instrumentation.ts@@ -8,6 +8,7 @@ import { PrismaInstrumentation } from "@prisma/instrumentation";import { WinstonInstrumentation } from "@opentelemetry/instrumentation-winston";import { AwsInstrumentation } from "@opentelemetry/instrumentation-aws-sdk";import { BullMQInstrumentation } from "@appsignal/opentelemetry-instrumentation-bullmq";+import { ioredisRequestHook } from "@langfuse/shared/src/server";import {envDetector,processDetector,@@ -31,7 +32,7 @@ const sdk = new NodeSDK({url: `${env.OTEL_EXPORTER_OTLP_ENDPOINT}/v1/traces`,}),instrumentations: [- new IORedisInstrumentation(),+ new IORedisInstrumentation({ requestHook: ioredisRequestHook }),new HttpInstrumentation({requireParentforOutgoingSpans: true,ignoreIncomingRequestHook: (req) => {