Murali
Vercel AI SDK with Svelte
if you only do it on shutdown.. does that mean my localhost has to completely shutdown? I am not sure how to trigger the push of traces.. Because in the exmaple provided on langfuse website.. it calls shutdown in the instrumentation file itself. so everytime I try to get capture traces, I get the server shutdown in debug
13 replies
Vercel AI SDK with Svelte
Hi @Marc - thanks for the response. sdk.shutdown() didnt work for flushing. What I realized is that the langfuse exporter has a forceflush function. So I changed my instrumentation file like this
import { NodeSDK } from "@opentelemetry/sdk-node";
import { getNodeAutoInstrumentations } from "@opentelemetry/auto-instrumentations-node";
import { LangfuseExporter } from "langfuse-vercel";
import { env } from '$env/dynamic/private';
import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base";
/*
export const sdk = new NodeSDK({
traceExporter: new LangfuseExporter({
secretKey: env.LANGFUSE_SECRET_KEY,
publicKey: env.LANGFUSE_PUBLIC_KEY,
baseUrl: env.LANGFUSE_BASE_URL, // optional
debug: true
}),
instrumentations: [getNodeAutoInstrumentations()],
});
*/
const exporter = new LangfuseExporter({
secretKey: env.LANGFUSE_SECRET_KEY,
publicKey: env.LANGFUSE_PUBLIC_KEY,
baseUrl: env.LANGFUSE_BASE_URL,
debug: true,
});
// Create a BatchSpanProcessor with more frequent exports
const spanProcessor = new BatchSpanProcessor(exporter, {
maxExportBatchSize: 3, // Export after 10 spans (adjust as needed)
scheduledDelayMillis: 500, // Export every 1 second (adjust as needed)
});
export const sdk = new NodeSDK({
traceExporter: exporter,
instrumentations: [getNodeAutoInstrumentations()],
});
export async function flush() {
await exporter.forceFlush()
console.log('from instrumentation - flush')
}
export function initializeTracing() {
sdk.start()
console.log('from instrumentation - Tracing initialized');
}
export function shutdownTracing() {
return sdk.shutdown().then(() => console.log('Tracing initialized'))
.catch((error) => console.error('Error initializing tracing', error));
}
Now, I keep calling flush in places where I need to push the data
-- Do you see any issues with this?
13 replies