mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-01-02 14:22:28 +08:00
feat: add trace-level input/output to Langfuse observability (#69)
* feat: add trace-level input/output to Langfuse observability - Add @langfuse/client and @langfuse/tracing dependencies - Wrap POST handler with observe() for proper tracing - Use updateActiveTrace() to set trace input, output, sessionId, userId - Filter Next.js HTTP spans in shouldExportSpan so AI SDK spans become root traces - Enable recordInputs/recordOutputs in experimental_telemetry * refactor: extract Langfuse logic to separate lib/langfuse.ts module
This commit is contained in:
@@ -12,11 +12,24 @@ export function register() {
|
||||
publicKey: process.env.LANGFUSE_PUBLIC_KEY,
|
||||
secretKey: process.env.LANGFUSE_SECRET_KEY,
|
||||
baseUrl: process.env.LANGFUSE_BASEURL,
|
||||
// Filter out Next.js HTTP request spans so AI SDK spans become root traces
|
||||
shouldExportSpan: ({ otelSpan }) => {
|
||||
const spanName = otelSpan.name;
|
||||
// Skip Next.js HTTP infrastructure spans
|
||||
if (spanName.startsWith('POST /') ||
|
||||
spanName.startsWith('GET /') ||
|
||||
spanName.includes('BaseServer') ||
|
||||
spanName.includes('handleRequest')) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
});
|
||||
|
||||
const tracerProvider = new NodeTracerProvider({
|
||||
spanProcessors: [langfuseSpanProcessor],
|
||||
});
|
||||
|
||||
// Register globally so AI SDK's telemetry also uses this processor
|
||||
tracerProvider.register();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user