getsentry / getsentry/sentry-python

Instrument Chat API with `conversation.id` tracking

オープン
#5,824 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
Improvement Python Spans
主要言語
Python
スター
2.2k
フォーク
669
平均マージ
1日 1時間
マージ済み PR(30日)
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 はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。