| name | langfuse-ci-integration |
| description | Configure Langfuse CI/CD integration with GitHub Actions and automated testing.
Use when setting up automated testing, configuring CI pipelines,
or integrating Langfuse tests into your build process.
Trigger with phrases like "langfuse CI", "langfuse GitHub Actions",
"langfuse automated tests", "CI langfuse", "langfuse pipeline".
|
| allowed-tools | Read, Write, Edit, Bash(gh:*) |
| version | 1.0.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
Langfuse CI Integration
Overview
Set up CI/CD pipelines for Langfuse integrations with automated testing and validation.
Prerequisites
- GitHub repository with Actions enabled
- Langfuse test project API keys
- npm/pnpm project configured
Instructions
Step 1: Create GitHub Actions Workflow
Create .github/workflows/langfuse-integration.yml:
name: Langfuse Integration Tests
on:
push:
branches: [main, develop]
pull_request:
branches: [main]
schedule:
- cron: '0 6 * * *'
env:
NODE_VERSION: '20'
jobs:
test:
runs-on: ubuntu-latest
environment: test
env:
LANGFUSE_PUBLIC_KEY: ${{ secrets.LANGFUSE_PUBLIC_KEY_TEST }}
LANGFUSE_SECRET_KEY: ${{ secrets.LANGFUSE_SECRET_KEY_TEST }}
LANGFUSE_HOST: https://cloud.langfuse.com
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run unit tests
run: npm test -- --coverage
- name: Run Langfuse integration tests
run: npm run test:integration
timeout-minutes: 10
- name: Upload coverage
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
validate-traces:
runs-on: ubuntu-latest
needs: test
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
env:
LANGFUSE_PUBLIC_KEY: ${{ secrets.LANGFUSE_PUBLIC_KEY_TEST }}
LANGFUSE_SECRET_KEY: ${{ secrets.LANGFUSE_SECRET_KEY_TEST }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Validate Langfuse traces
run: npm run validate:langfuse
Step 2: Configure Secrets
gh secret set LANGFUSE_PUBLIC_KEY_TEST --body "pk-lf-test-..."
gh secret set LANGFUSE_SECRET_KEY_TEST --body "sk-lf-test-..."
gh secret set LANGFUSE_PUBLIC_KEY_PROD --body "pk-lf-prod-..."
gh secret set LANGFUSE_SECRET_KEY_PROD --body "sk-lf-prod-..."
Step 3: Create Integration Tests
import { describe, it, expect, beforeAll, afterAll } from "vitest";
import { Langfuse } from "langfuse";
const SKIP_INTEGRATION = !process.env.LANGFUSE_PUBLIC_KEY;
describe.skipIf(SKIP_INTEGRATION)("Langfuse Integration", () => {
let langfuse: Langfuse;
beforeAll(() => {
langfuse = new Langfuse({
publicKey: process.env.LANGFUSE_PUBLIC_KEY!,
secretKey: process.env.LANGFUSE_SECRET_KEY!,
baseUrl: process.env.LANGFUSE_HOST,
});
});
afterAll(async () => {
await langfuse.shutdownAsync();
});
it("should connect to Langfuse", async () => {
const trace = langfuse.trace({
name: "ci-connection-test",
metadata: {
ci: true,
commit: process.env.GITHUB_SHA,
: process..,
},
});
(trace.).();
langfuse.();
});
(, () => {
trace = langfuse.({
: ,
: { : },
});
span = trace.({
: ,
: { : },
});
generation = span.({
: ,
: ,
: [{ : , : }],
});
generation.({
: ,
: { : , : },
});
span.({ : { : } });
trace.({ : { : } });
langfuse.();
traceUrl = trace.();
(traceUrl).();
});
(, () => {
trace = langfuse.({
: ,
});
trace.({
: ,
: ,
});
langfuse.();
(trace.).();
});
});
Step 4: Add Validation Script
import { Langfuse } from "langfuse";
async function validateLangfuseSetup() {
console.log("=== Langfuse CI Validation ===\n");
const langfuse = new Langfuse();
const checks = [
{
name: "Create trace",
test: async () => {
const trace = langfuse.trace({
name: "ci-validation",
metadata: { validation: true },
});
return !!trace.id;
},
},
{
name: "Create span",
test: async () => {
const trace = langfuse.trace({ name: "span-test" });
const span = trace.span({ name: "test-span" });
span.end();
return !!span.id;
},
},
{
name: "Create generation",
test: async () => {
const trace = langfuse.({ : });
gen = trace.({
: ,
: ,
});
gen.({ : });
!!gen.;
},
},
{
: ,
: () => {
langfuse.();
;
},
},
{
: ,
: () => {
langfuse.();
;
},
},
];
passed = ;
failed = ;
( { name, test } checks) {
{
result = ();
(result) {
.();
passed++;
} {
.();
failed++;
}
} (error) {
.();
failed++;
}
}
.();
(failed > ) {
process.();
}
}
();
Step 5: Add package.json Scripts
{
"scripts": {
"test": "vitest run",
"test:integration": "vitest run tests/*.integration.test.ts",
"validate:langfuse": "tsx scripts/validate-langfuse.ts"
}
}
Output
- Automated test pipeline
- PR checks configured
- Coverage reports uploaded
- Daily validation runs
- Trace validation on merge
PR Status Checks
required_status_checks:
strict: true
contexts:
- "test"
- "validate-traces"
Error Handling
| Issue | Cause | Solution |
|---|
| Secret not found | Missing configuration | Add secret via gh secret set |
| Tests timeout | Network issues | Increase timeout or add retry |
| Auth failures | Invalid key | Check secret value |
| Flaky tests | Race conditions | Add proper flush/wait |
Examples
Matrix Testing (Multiple Node Versions)
jobs:
test:
strategy:
matrix:
node-version: [18, 20, 22]
steps:
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node-version }}
Release Workflow with Langfuse Validation
name: Release
on:
push:
tags: ['v*']
jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
registry-url: 'https://registry.npmjs.org'
- name: Install dependencies
run: npm ci
- name: Validate Langfuse integration
env:
LANGFUSE_PUBLIC_KEY: ${{ secrets.LANGFUSE_PUBLIC_KEY_PROD }}
LANGFUSE_SECRET_KEY: ${{ secrets.LANGFUSE_SECRET_KEY_PROD }}
run: npm run validate:langfuse
- name: Build
run: npm
Resources
Next Steps
For deployment patterns, see langfuse-deploy-integration.