Adding Feedback Annotations to Phoenix Traces in FastAPI Application
Hi! I'm running Phoenix in a Docker container (and also in production on a self-hosted Kubernetes) and would like to add thumbs up/down feedback as annotations to my traces. I found the following page: https://docs.arize.com/phoenix/tracing/how-to-tracing/capture-feedback, but unfortunately I'm nog getting it to work for my use case, which is a fairly simple FastAPI + LangChain application. In main.py I have:
python
from openinference.instrumentation.langchain import LangChainInstrumentor
from phoenix.otel import register
tracer_provider = register(
endpoint=os.getenv("PHOENIX_COLLECTOR_ENDPOINT"),
project_name=os.getenv("PHOENIX_PROJECT_NAME"),
)
LangChainInstrumentor().instrument(tracer_provider=tracer_provider)
// Other FastAPI code for endpointsmain.py also imports another file called generate_answer.py where the LangChain invoke functions are called. In this file, I have the following code related to Phoenix:
python
from opentelemetry import trace
span = trace.get_current_span()
span_id = span.get_span_context().span_id.to_bytes(8, "big").hex()
import httpx
client = httpx.Client()
annotation_payload = {
"data": [
{
"span_id": span_id,
"name": "user feedback",
"annotator_kind": "HUMAN",
"result": {"label": "thumbs-up", "score": 1},
"metadata": {},
}
]
}
client.post(
f"{os.getenv('PHOENIX_UI_ENDPOINT')}/v1/span_annotations?sync=false",
json=annotation_payload,
)--- Now my problems: 1. (The main problem): The span that I'm returned is NonRecordingSpan(SpanContext(trace_id=0x00000000000000000000000000000000, span_id=0x0000000000000000, trace_flags=0x00, trace_state=[], is_remote=False)) so my span_id becomes 0000000000000000. How can I retrieve the span_id for my LangChain trace that is created when invoke is called? 2. My collector endpoint is on port 4317, but the feedback seems to only be accepted on port 6006 (as it is an HTTP request). Can I also send feedback to port 4317? Or is it HTTP only, thus therefore only for port 6006? 3. Is there a Python package to send feedback to Phoenix? Or is it only possible via HTTP? Thank you very much for taking the time to answer my question. I've tried to make the situation as clear as possible.
