Best Practices for Instrumenting Phoenix in FastAPI Websockets
RunLLM What are some best pracitces for instrumenting phoenix in a fastapi backend connected to frontend via websocket i have 4 apis exposed from fast api create_session - http get_session - http delete_session - http process_session_messages - ws websocket stays open until one of 2 conditions is reached 1) inactivity for an extended period of time 2) user changes to a different chat/homepage general flow goes create -> get (to show user latest state) -> process_session_messages (when there is a new user message) -> keep ws open for response + send additional user messages -> user moves away and we close the connection I am connecting all this using a session_id that is generated in create now my issue is that the first 2 steps come as traces correctly the third one only shows up as a trace + connected to session ONLY after the websocket completely disconnects, this make sense since the backend is listening and the connection is open, however this is an issue for me since we can have long running sessions and i wanna see traces of process_session_messages after every turn is done, how can i achieve this? currently doing this for every route's method
@app.websocket(
"/api/sessions/{session_id}/ws"
)
async def websocket_endpoint(
websocket: WebSocket, organization_id: str, environment_id: str, session_id: str
):
with tracer.start_as_current_span(name="process_session_messages"):
current_span = trace.get_current_span()
current_span.set_attribute(SpanAttributes.SESSION_ID, session_id)
with using_session(session_id):
more code