Find answers from the community

Updated 2 months ago

Phoenix and llama-index integration issue with Workflow and StopEvent

hey folks, i'm seeing an issue with phoenix and llama-index integration using llama index's Workflow s-- the exact error message is:

Plain Text
 python
... earlier workflow logic
Step initialize_reasoning produced event InputEvent
Running step handle_llm_input
Step handle_llm_input produced event StopEvent
Failed to detach context
Traceback (most recent call last):
  File "/Users/james/Library/Caches/pypoetry/virtualenvs/viv-UNwrkwNB-py3.12/lib/python3.12/site-packages/opentelemetry/context/__init__.py", line 154, in detach
    _RUNTIME_CONTEXT.detach(token)
  File "/Users/james/Library/Caches/pypoetry/virtualenvs/viv-UNwrkwNB-py3.12/lib/python3.12/site-packages/opentelemetry/context/contextvars_context.py", line 50, in detach
    self._current_context.reset(token)  # type: ignore
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: <Token var=<ContextVar name='current_context' default={} at 0x168757fb0> at 0x16b6ead80> was created in a different Context

FWIW, the backtrace not shown here fails when trying to exit a span that was created on an async function, using the async

if i remove the dispatcher.span on Workflow.run, then this error disappears, so it seems to be related with exiting the Workflow.run span.

fwiw, executing my workflow with the following line: res = await agent.run()
1
L
5 comments
also, fwiw, backtrace of the fail is:
Plain Text
 python
llama_index/core/instrumentation/dispatcher.py(281)handle_future_result()
-> self.span_exit(
  llama_index/core/instrumentation/dispatcher.py(227)span_exit()
-> h.span_exit(
  llama_index/core/instrumentation/span_handlers/base.py(86)span_exit()
-> span = self.prepare_to_exit_span(
  openinference/instrumentation/llama_index/_handler.py(753)prepare_to_exit_span()
-> detach(token)
> opentelemetry/context/__init__.py(157)detach()
-> logger.exception("Failed to detach context")
This is a non-error, pretty sure the trace still shows up on arize properly
I tried a lot to fix this in the dispatcher, but couldn't totally get it to avoid printing that error
it has to do with how .run() returns a future, and how thats handled in the dispatcher
Add a reply
Sign up and join the conversation on Discord