Trace LlamaIndex Workflows

Trace a workflow run, its steps, and LlamaIndex model calls in Future AGI with the shared LlamaIndex instrumentor.

Trace a two-step workflow that writes a joke and then critiques it. This example uses the standalone LlamaIndex Workflows API and sends the workflow run, step spans, and LlamaIndex model calls to Future AGI.

If you’ve already enabled LlamaIndexInstrumentor, reuse that provider and instrumentation rather than registering another one.

1. Install

Use Python 3.10–3.13 and traceAI-llamaindex 0.1.10. Version 0.1.9 cannot initialize on LlamaIndex core 0.13 or later. Install the standalone workflow package and the OpenAI integration for this example.

pip install traceAI-llamaindex==0.1.10 llama-index-core==0.14.25 llama-index-workflows==2.26.1 llama-index-llms-openai==0.8.3

2. Set credentials

Set your Future AGI and OpenAI credentials for this example.

import os

os.environ["FI_API_KEY"] = "your-futureagi-api-key"
os.environ["FI_SECRET_KEY"] = "your-futureagi-secret-key"
os.environ["OPENAI_API_KEY"] = "your-openai-api-key"

3. Register tracing

Choose the Observe project that will receive the spans.

from fi_instrumentation import register
from fi_instrumentation.fi_types import ProjectType

trace_provider = register(
    project_type=ProjectType.OBSERVE,
    project_name="llamaindex_workflows_project",
)

4. Instrument LlamaIndex

Enable the instrumentor before constructing or running the workflow. LlamaIndex core and standalone Workflows share an instrumentation dispatcher, so the same instrumentor captures the workflow run, its decorated steps, and nested LlamaIndex model calls. You do not need a separate workflow instrumentor.

Warning

The instrumentor captures inputs, outputs and error details by default. This example hides input and output values and messages with TraceConfig. Error text and custom attributes can still contain sensitive data; review span masking before sending private workloads.

from fi_instrumentation import TraceConfig
from traceai_llamaindex import LlamaIndexInstrumentor

LlamaIndexInstrumentor().instrument(
    tracer_provider=trace_provider,
    config=TraceConfig(hide_inputs=True, hide_outputs=True),
)

To capture prompt and response content, set both hide options to False only for data you are allowed to store in Future AGI.


5. Run the workflow

Run the setup blocks and the following code in one Python script. Each step makes a LlamaIndex OpenAI.acomplete call. The finally block flushes queued spans before the script exits.

import asyncio

from workflows import Workflow, step
from workflows.events import Event, StartEvent, StopEvent
from llama_index.llms.openai import OpenAI

class JokeEvent(Event):
    joke: str

class JokeFlow(Workflow):
    llm = OpenAI(model="gpt-4o-mini")

    @step
    async def generate_joke(self, ev: StartEvent) -> JokeEvent:
        topic = ev.topic

        prompt = f"Write your best joke about {topic}."
        response = await self.llm.acomplete(prompt)
        return JokeEvent(joke=str(response))

    @step
    async def critique_joke(self, ev: JokeEvent) -> StopEvent:
        joke = ev.joke

        prompt = f"Give a thorough analysis and critique of the following joke: {joke}"
        response = await self.llm.acomplete(prompt)
        return StopEvent(result=str(response))

async def main():
    w = JokeFlow(timeout=60, verbose=False)
    result = await w.run(topic="pirates")
    print(str(result))

if __name__ == "__main__":
    try:
        asyncio.run(main())
    finally:
        trace_provider.shutdown()

View the trace

Open Observe in Future AGI and select the llamaindex_workflows_project project. Expand JokeFlow.run to see the JokeFlow.generate_joke and JokeFlow.critique_joke steps, each with a nested OpenAI.acomplete span. With the privacy settings above, input and output content is hidden.

Was this page helpful?

Questions & Discussion