mirror of
https://github.com/FJurmanovic/sugarr.git
synced 2026-11-11 15:51:09 +00:00
Group pipeline runs into Langfuse sessions, tagged by trigger source
Each pipeline invocation (runAsync/searchAsync) now gets a fresh sessionId, wrapped via the new Tracer.runWithSession() (implemented with @langfuse/tracing's propagateAttributes, since v5 has no direct sessionId/tags option on startObservation) so it shows up in Langfuse's Sessions view. The session is also tagged with what triggered the run: "cron", "api-list", "api-trigger", "api-search". Verified: full test suite (79/79) passing, tsc/eslint clean, real docker compose build + container smoke test against /health.
This commit is contained in:
@@ -1,9 +1,15 @@
|
||||
import { NodeSDK } from '@opentelemetry/sdk-node';
|
||||
import { LangfuseSpanProcessor } from '@langfuse/otel';
|
||||
import { startObservation } from '@langfuse/tracing';
|
||||
import { propagateAttributes, startObservation } from '@langfuse/tracing';
|
||||
import type { LangfuseGeneration, LangfuseSpan } from '@langfuse/tracing';
|
||||
import { Tracer } from '../llm/Tracer';
|
||||
import type { GenerationHandle, GenerationInput, GenerationOutput, TraceHandle } from '../llm/Tracer';
|
||||
import type {
|
||||
GenerationHandle,
|
||||
GenerationInput,
|
||||
GenerationOutput,
|
||||
SessionInfo,
|
||||
TraceHandle,
|
||||
} from '../llm/Tracer';
|
||||
|
||||
export class LangfuseTracer extends Tracer {
|
||||
private readonly processor: LangfuseSpanProcessor;
|
||||
@@ -48,6 +54,10 @@ export class LangfuseTracer extends Tracer {
|
||||
await this.processor.forceFlush();
|
||||
}
|
||||
|
||||
runWithSession<T>(session: SessionInfo, fn: () => Promise<T>): Promise<T> {
|
||||
return propagateAttributes({ sessionId: session.sessionId, tags: session.tags }, fn);
|
||||
}
|
||||
|
||||
async shutdown(): Promise<void> {
|
||||
await this.sdk.shutdown();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user