Deploy Langfuse with your application across different platforms.
Use when deploying Langfuse to Vercel, AWS, GCP, or Docker,
or integrating Langfuse into your deployment pipeline.
Trigger with phrases like "deploy langfuse", "langfuse Vercel",
"langfuse AWS", "langfuse Docker", "langfuse production deploy".
Deploy Langfuse LLM observability alongside your application. Covers integrating the SDK for serverless (Vercel/Lambda), Docker, Cloud Run, and self-hosting the Langfuse server itself.
Prerequisites
Langfuse API keys (cloud or self-hosted)
Application using Langfuse SDK
Target platform CLI installed
Instructions
Step 1: Vercel / Next.js Deployment
set -euo pipefail
# Add secrets to Vercel
vercel env add LANGFUSE_PUBLIC_KEY production
vercel env add LANGFUSE_SECRET_KEY production
vercel env add LANGFUSE_BASE_URL production
Serverless note: Langfuse SDK v4+ uses OTel which handles flushing asynchronously. For v3, always call await langfuse.flushAsync() before the response returns -- serverless functions may freeze after response.
Step 2: AWS Lambda / Serverless
// handler.ts
import { LangfuseSpanProcessor } from "@langfuse/otel";
import { NodeSDK } from "@opentelemetry/sdk-node";
import { startActiveObservation, updateActiveObservation } from "@langfuse/tracing";
// Initialize OUTSIDE handler for connection reuse
const sdk = new NodeSDK({
spanProcessors: [
new LangfuseSpanProcessor({
exportIntervalMillis: 1000, // Flush fast in serverless
}),
],
});
sdk.start();
export const handler = async (event: any) => {
return await startActiveObservation("lambda-handler", async () => {
updateActiveObservation({ input: event });
const result = await processRequest(event);
updateActiveObservation({ output: result });
// Force flush before Lambda freezes
await sdk.shutdown();
return { statusCode: 200, body: JSON.stringify(result) };
});
};