getsentry / getsentry/sentry-python
Instrument Chat API with `conversation.id` tracking
- 主要语言
- Python
- 星标
- 2.2k
- 派生
- 669
- 平均合并
- 1 天 1 小时
- 30 天内合并 PR
- 213
描述
## 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
贡献指南
评估
这个 Issue 还没有评估数据。