Troubleshooting LangChain Tracing with Phoenix in Python
Hi, I want to trace my langchain chain with phoenix in a python script:
from phoenix.trace.langchain import OpenInferenceTracer, LangChainInstrumentor
from phoenix.trace.exporter import HttpExporter
tracer = OpenInferenceTracer(exporter=HttpExporter(endpoint="http://0.0.0.0:6006"))
LangChainInstrumentor(tracer).instrument()
chain.invoke(input=chain_input)
The tracing itself works and I can observe the spans on port 6006, when I launch the app via jupyter notebook. Additionally it would be quite nice to not only access the dataframe in a jupyter notebook spans_df = px.active_session().get_spans_dataframe() ... but to write it directly to a file as part of my script. In the docs I found the following how-to-article:
from phoenix.trace.span_json_encoder import spans_to_jsonl
with open("trace.jsonl", "w") as f:
f.write(spans_to_jsonl(tracer.get_spans())) Even though I followed the instructions in the tutorial precisely I get an empty file. In PyCharm I also get the warning for the tracer object: Expected type 'list[Span]', got 'Iterator[Span]' instead Anyone with an idea how to solve this?
