cloakdrone
cloakdrone2mo ago

Is it possible to end a trace?

So i am scraping urls of a domain and doing some analysis on top of it. For each url of that domain, I have a generation. Once all urls are done. I would want to close the trace so that the next domain gets a new trace. 1 trace for 1 domain with 5 generations (1 for each url of that domain). I don't think it is doable since there is no trace.end() and I think I have not understood traces.
Solution:
I'd move the trace creation to the generateThing and create a new trace for every thing
Jump to solution
9 Replies
Marc
Marc2mo ago
How do you instrument your application? Across all our intgerations you can create a separata trace for each domain and then log the 5 llm calls as generations on this trace. The trace does not have an end as it is determined by the last observation within it
cloakdrone
cloakdrone2mo ago
At the top of my file I have
const geminiTrace = langfuse.trace({
name: "generate-things",
tags: ["thing-x"],
});
const geminiTrace = langfuse.trace({
name: "generate-things",
tags: ["thing-x"],
});
Then these functions
async function generateThing(url){
// process url
const generation = geminiTrace.generation({...})
...
generation.update()
}
async function processDomain(...) // calls generateThing in a loop
async function generateThing(url){
// process url
const generation = geminiTrace.generation({...})
...
generation.update()
}
async function processDomain(...) // calls generateThing in a loop
Solution
Marc
Marc2mo ago
I'd move the trace creation to the generateThing and create a new trace for every thing
cloakdrone
cloakdrone2mo ago
Yes i did that, but i thought i would nest the generations under one trace. is this standard practice?
Marc
Marc2mo ago
perfect, the trace most often captures all observations within an api route, see docs for more guidance on this: https://langfuse.com/docs/tracing
LLM Application Tracing - Langfuse
Open Source LLM Observability and Tracing with Langfuse. Integrates with OpenAI, Langchain, LlamaIndex and more.
cloakdrone
cloakdrone2mo ago
got it, i will have to create a new trace for everything or else, all generations will end up under one single trace skewing the latency, cost data
Marc
Marc2mo ago
yes, I'd strongly recommend this
cloakdrone
cloakdrone2mo ago
@Marc I moved trace creation to processDomain instead and passed that trace object to generateThing. This solved my problem of having one trace for a domain and multiple generations nested.
Marc
Marc2mo ago
awesome, thanks for confirming