| name | langfuse-deploy-integration |
| description | 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".
|
| allowed-tools | Read, Write, Edit, Bash(docker:*), Bash(vercel:*), Bash(gcloud:*) |
| version | 1.0.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
Langfuse Deploy Integration
Overview
Deploy Langfuse observability with your application across various platforms.
Prerequisites
- Langfuse production API keys
- Deployment platform access (Vercel, AWS, GCP, etc.)
- Application ready for deployment
Instructions
Step 1: Vercel Deployment
vercel env add LANGFUSE_PUBLIC_KEY production
vercel env add LANGFUSE_SECRET_KEY production
vercel env add LANGFUSE_HOST production
{
"env": {
"LANGFUSE_HOST": "https://cloud.langfuse.com"
}
}
import { Langfuse } from "langfuse";
import { NextResponse } from "next/server";
const langfuse = new Langfuse({
publicKey: process.env.LANGFUSE_PUBLIC_KEY!,
secretKey: process.env.LANGFUSE_SECRET_KEY!,
flushAt: 1,
});
export async function POST(request: Request) {
const { message } = await request.json();
const trace = langfuse.trace({
name: "api/chat",
input: { message },
metadata: {
platform: "vercel",
region: process.env.VERCEL_REGION,
},
});
try {
const response = await processChat(message, trace);
trace.update({ output: response });
langfuse.();
.(response);
} (error) {
trace.({ : , : (error) });
langfuse.();
error;
}
}
Step 2: AWS Lambda Deployment
import { Langfuse } from "langfuse";
import { APIGatewayEvent, Context } from "aws-lambda";
const langfuse = new Langfuse({
publicKey: process.env.LANGFUSE_PUBLIC_KEY!,
secretKey: process.env.LANGFUSE_SECRET_KEY!,
flushAt: 1,
});
export async function handler(event: APIGatewayEvent, context: Context) {
context.callbackWaitsForEmptyEventLoop = false;
const trace = langfuse.trace({
name: "lambda/handler",
input: JSON.parse(event.body || "{}"),
metadata: {
requestId: context.awsRequestId,
functionName: context.functionName,
coldStart: !global.,
},
});
. = ;
{
result = (event, trace);
trace.({ : result });
langfuse.();
{
: ,
: .(result),
};
} (error) {
trace.({ : , : (error) });
langfuse.();
{
: ,
: .({ : }),
};
}
}
service: my-llm-app
provider:
name: aws
runtime: nodejs20.x
environment:
LANGFUSE_PUBLIC_KEY: ${ssm:/langfuse/public-key}
LANGFUSE_SECRET_KEY: ${ssm:/langfuse/secret-key}
LANGFUSE_HOST: https://cloud.langfuse.com
functions:
chat:
handler: handler.handler
timeout: 30
events:
- http:
path: /chat
method: post
Step 3: Google Cloud Run Deployment
# Dockerfile
FROM node:20-slim
WORKDIR /app
COPY package*.json ./
RUN npm ci --production
COPY . .
RUN npm run build
# Cloud Run sets PORT
ENV PORT=8080
CMD ["node", "dist/server.js"]
import express from "express";
import { Langfuse } from "langfuse";
const app = express();
const langfuse = new Langfuse({
publicKey: process.env.LANGFUSE_PUBLIC_KEY!,
secretKey: process.env.LANGFUSE_SECRET_KEY!,
});
process.on("SIGTERM", async () => {
console.log("SIGTERM received, flushing Langfuse...");
await langfuse.shutdownAsync();
process.exit(0);
});
app.post("/chat", async (req, res) => {
const trace = langfuse.trace({
name: "cloudrun/chat",
input: req.body,
metadata: {
service: process.env.K_SERVICE,
revision: process.env.K_REVISION,
},
});
});
const port = process.env.PORT || ;
app.(port, {
.();
});
gcloud run deploy my-llm-app \
--source . \
--region us-central1 \
--set-env-vars "LANGFUSE_PUBLIC_KEY=$LANGFUSE_PUBLIC_KEY" \
--set-secrets "LANGFUSE_SECRET_KEY=langfuse-secret-key:latest" \
--allow-unauthenticated
Step 4: Docker Compose Deployment
version: '3.8'
services:
app:
build: .
ports:
- "3000:3000"
environment:
- NODE_ENV=production
- LANGFUSE_PUBLIC_KEY=${LANGFUSE_PUBLIC_KEY}
- LANGFUSE_SECRET_KEY=${LANGFUSE_SECRET_KEY}
- LANGFUSE_HOST=https://cloud.langfuse.com
healthcheck:
test: ["CMD", "curl", "-f", "http://localhost:3000/health"]
interval: 30s
timeout: 10s
retries: 3
deploy:
resources:
limits:
memory: 512M
restart: unless-stopped
langfuse:
image: langfuse/langfuse:latest
ports:
- "3001:3000"
environment:
- DATABASE_URL=postgresql://postgres:postgres@db:5432/langfuse
- NEXTAUTH_SECRET=${NEXTAUTH_SECRET}
-
Step 5: Kubernetes Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: llm-app
spec:
replicas: 3
selector:
matchLabels:
app: llm-app
template:
metadata:
labels:
app: llm-app
spec:
containers:
- name: app
image: myregistry/llm-app:latest
ports:
- containerPort: 3000
env:
- name: LANGFUSE_PUBLIC_KEY
valueFrom:
secretKeyRef:
name: langfuse-secrets
key: public-key
- name: LANGFUSE_SECRET_KEY
valueFrom:
secretKeyRef:
name: langfuse-secrets
key: secret-key
- name: LANGFUSE_HOST
[, , ]
Output
- Platform-specific deployment configurations
- Serverless optimizations (immediate flush)
- Graceful shutdown handling
- Secret management integration
- Health checks configured
Serverless Considerations
| Platform | Flush Strategy | Shutdown Handling |
|---|
| Vercel | flushAt: 1 | Flush before response |
| Lambda | flushAt: 1 | Flush before return |
| Cloud Run | Default batching | SIGTERM handler |
| Kubernetes | Default batching | preStop hook |
Error Handling
| Issue | Cause | Solution |
|---|
| Lost traces (serverless) | No flush before freeze | Add flushAsync() |
| Slow cold starts | Large SDK init | Move init outside handler |
| Secrets exposed | Env vars in logs | Use secret managers |
| Traces delayed | Default batching | Reduce flushInterval |
Resources
Next Steps
For webhooks and events, see langfuse-webhooks-events.