Unable to see first trace by following quickstart #11325
-
Describe your questionVery frustrating. I am on a m2 mac mini and on the latest mac os version. I followed https://langfuse.com/docs/observability/sdk/overview for the ts sdk. I copied over the code and when running it seems to work, but then when I check langfuse, I see nothing. I have copied over the .env secrets it gave me on the page Here is my code in And my code in Notice I added the line
I have ran I've deleted all dependencies except for what's needed for the quickstart, this is my Cannot figure out why my home dashboard still looks like this: Tracing page is similarly empty. node version: v22.20.0 I have even created a new folder, copied over all my files, npm installed everything again and ran it to the same result. Langfuse Cloud or Self-Hosted?Langfuse Cloud If Langfuse Cloudhttps://us.cloud.langfuse.com/project/cmjizmh2d02zoad0765an7jg1
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
|
The issue is likely that your short-lived application exits before the trace data is sent to Langfuse. The JS/TS SDK sends data asynchronously in the background.(1) For short-lived applications like your script, you need to ensure the SDK has time to flush the data before the process exits. Add a shutdown handler to your import "./instrumentation";
import { startActiveObservation } from "@langfuse/tracing";
async function main() {
await startActiveObservation("my-first-trace", async (span) => {
span.update({
input: "Hello, Langfuse!",
output: "This is my first trace!",
});
});
}
main();Then update your import { NodeSDK } from "@opentelemetry/sdk-node";
import { LangfuseSpanProcessor } from "@langfuse/otel";
import dotenv from "dotenv";
dotenv.config();
const sdk = new NodeSDK({
spanProcessors: [new LangfuseSpanProcessor()],
});
sdk.start();The key issue is that the OpenTelemetry SDK needs to be properly shut down to ensure all spans are exported before the process exits. Since your script completes almost instantly, it exits before the background export happens.(1) Add a shutdown call after your main function completes: import "./instrumentation";
import { startActiveObservation } from "@langfuse/tracing";
import { opentelemetry } from "@opentelemetry/api";
async function main() {
await startActiveObservation("my-first-trace", async (span) => {
span.update({
input: "Hello, Langfuse!",
output: "This is my first trace!",
});
});
// Give the SDK time to flush
await new Promise(resolve => setTimeout(resolve, 2000));
}
main().then(() => process.exit(0));This gives the SDK 2 seconds to export the trace data before the process exits. After making this change, you should see your trace appear in the Langfuse UI.(1) 📚 Sources: Have another question? Just tag @inkeep. |
Beta Was this translation helpful? Give feedback.


Hi @kleenkanteen,
The issue is that your application exits before the traces are sent to Langfuse. You can find more on this here: https://langfuse.com/docs/observability/data-model#short-lived-applications
You can fix this by explicitly telling the OpenTelemetry SDK to flush all pending spans and wait for them to be sent, before exiting the application:
In your
instrumentation.tsfile, export the SDK so that you can use it inindex.ts:Import and shut down the SDK after your main function completes: