forked from langfuse/langfuse
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web): send trace events via Redis instead of Rest (langfuse#2579)
- Loading branch information
1 parent
90fc9fb
commit 6554c5e
Showing
28 changed files
with
239 additions
and
165 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 10 additions & 10 deletions
20
worker/src/redis.ts → packages/shared/src/server/redis/redis.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import { randomUUID } from "crypto"; | ||
import { | ||
QueueJobs, | ||
QueueName, | ||
TQueueJobTypes, | ||
TraceUpsertEventType, | ||
} from "../../queues"; | ||
import { Queue } from "bullmq"; | ||
import { redis } from "./redis"; | ||
|
||
export const traceUpsertQueue = redis | ||
? new Queue<TQueueJobTypes[QueueName.TraceUpsert]>(QueueName.TraceUpsert, { | ||
connection: redis, | ||
}) | ||
: null; | ||
|
||
export function convertTraceUpsertEventsToRedisEvents( | ||
events: TraceUpsertEventType[] | ||
) { | ||
const uniqueTracesPerProject = events.reduce((acc, event) => { | ||
if (!acc.get(event.projectId)) { | ||
acc.set(event.projectId, new Set()); | ||
} | ||
acc.get(event.projectId)?.add(event.traceId); | ||
return acc; | ||
}, new Map<string, Set<string>>()); | ||
|
||
const jobs = [...uniqueTracesPerProject.entries()] | ||
.map((tracesPerProject) => { | ||
const [projectId, traceIds] = tracesPerProject; | ||
|
||
return [...traceIds].map((traceId) => ({ | ||
name: QueueJobs.TraceUpsert, | ||
data: { | ||
payload: { | ||
projectId, | ||
traceId, | ||
}, | ||
id: randomUUID(), | ||
timestamp: new Date(), | ||
name: QueueJobs.TraceUpsert as const, | ||
}, | ||
opts: { | ||
removeOnFail: 10000, | ||
removeOnComplete: true, | ||
attempts: 5, | ||
backoff: { | ||
type: "exponential", | ||
delay: 1000, | ||
}, | ||
}, | ||
})); | ||
}) | ||
.flat(); | ||
return jobs; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import teardown from "@/src/__tests__/teardown"; | ||
|
||
afterAll(async () => { | ||
await teardown(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export default async function teardown() { | ||
const { redis } = await import("@langfuse/shared/src/server"); | ||
console.log(`Redis status ${redis?.status}`); | ||
if (!redis) { | ||
return; | ||
} | ||
if (redis.status === "end") { | ||
console.log("Redis connection already closed"); | ||
return; | ||
} | ||
redis?.disconnect(); | ||
console.log("Teardown complete"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.