getsentry / getsentry/sentry-python

Instrument Chat API with `conversation.id` tracking

Aperta
#5,824 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
Improvement Python Spans
Lingua principale
Python
Stelle
2.2k
Fork
669
Merge medio
1g 1h
PR unite (30g)
213

Descrizione

## 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

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.