getsentry / getsentry/sentry-python
Instrument Chat API with `conversation.id` tracking
- Langage dominant
- Python
- Étoiles
- 2.2k
- Forks
- 669
- Merge moyen
- 1 j 1 h
- PR mergées (30 j)
- 213
Description
## Problem
The `client.chats` API (`Chats.create` / `Chat.send_message` / `Chat.send_message_stream`) provides stateful multi-turn chat. `send_message` internally calls `generate_content`, so individual calls produce spans. However, there is no `gen_ai.conversation.id` set, so there's no way to correlate multiple calls as part of the same conversation.
## Context
The SDK already has `set_conversation_id()` in `sentry_sdk/ai/utils.py` and a `SPANDATA.GEN_AI_CONVERSATION_ID` constant. The Chat/AsyncChat objects could be patched to assign a conversation ID when created, and propagate it to child spans.
## Files
* `sentry_sdk/integrations/google_genai/__init__.py` — `setup_once()` needs to patch `Chats`/`AsyncChats`
* `sentry_sdk/ai/utils.py` — `set_conversation_id()`
## Acceptance Criteria
* `Chats.create` assigns a unique conversation ID
* All `send_message` / `send_message_stream` spans within a chat session include `gen_ai.conversation.id`
* Test verifying conversation ID propagation across multiple messages
Guide de contribution
Ouvrir le guide de contribution
Évaluation
Cette issue n'a pas encore été évaluée.