Find answers from the community

Updated 3 months ago

question about langfuse integration: if

question about langfuse integration: if i wanted to retrieve the trace_id to subsequently add a user-inputted score to a trace, one example i've seen sets a root trace before invoking llama-index
Plain Text
langfuse_callback_handler = LlamaIndexCallbackHandler()
Settings.callback_manager = CallbackManager([langfuse_callback_handler])

def my_func():
  # Create a new trace on your main execution path
  root_trace = langfuse.trace(name="trace-name")
 
  # Set the root trace, subsequent LlamaIndex observations will be nested under root

  langfuse_callback_handler.set_root(root_trace)
 
  # Your LlamaIndex code here
 
  # Reset root, subsequent LlamaIndex observations will now use the default grouping and trace creation

  langfuse_callback_handler.set_root(None)


is this thread-safe? or would we need to create and pass a new callback handler/manager for each invocation?

or is there a simpler way to retrieve the trace_id so that it can be manually updated via langfuse sdk later?
L
e
2 comments
I kind of doubt its thread safe -- this is a key limitation of the existing callback system, and also why we are trying to get integrations to migrate to our newer instrumentation system
roger that - thanks.
Add a reply
Sign up and join the conversation on Discord