LlamaIndex traces grouping #3552
-
|
Hi there! When using the llamaindex integration as in the docs (langfuse_callback_handler / CallbackManager), I get the spans and generations correctly logged in LangFuse, but each step (ReAct agent) is being logged as a trace. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
|
Hello @ivanviragine! I'm here to help you with any bugs, questions, or contributions you have. I found a similar discussion regarding customizing trace grouping in Langfuse. You can configure the LlamaIndex integration to log all ReAct agent steps as a single trace by setting a root trace for your Here's how you can do it: from llama_index.core import Settings
from llama_index.core.callbacks import CallbackManager
from langfuse import Langfuse
from langfuse.llama_index import LlamaIndexCallbackHandler
# Instantiate a Langfuse Client
langfuse = Langfuse()
# Instantiate a new LlamaIndexCallbackHandler and register it in the LlamaIndex Settings
langfuse_callback_handler = LlamaIndexCallbackHandler(
public_key="pk-lf-...",
secret_key="sk-lf-...",
host="https://cloud.langfuse.com"
)
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)This setup ensures that all steps are logged under a single trace. Make sure to configure the |
Beta Was this translation helpful? Give feedback.
-
|
Can you try the (beta) integration via the instrumentation module? @hassiebp is currently rewriting the integration as llamaindex will eventually deprecate the callback based integration. |
Beta Was this translation helpful? Give feedback.
Can you try the (beta) integration via the instrumentation module?
https://langfuse.com/docs/integrations/llama-index/get-started#beta-observability-based-on-llamaindex-instrumentation-module
@hassiebp is currently rewriting the integration as llamaindex will eventually deprecate the callback based integration.