getsentry / getsentry/sentry-python

Instrument Chat API with `conversation.id` tracking

Abierto
#5,824 1 comentario 0 reacciones 0 asignados Ver en GitHub
Improvement Python Spans
Lenguaje dominante
Python
Estrellas
2.2k
Forks
669
Merge medio
1 d 1 h
PR fusionados (30 d)
213

Descripción

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

Guía de contribución

Abrir la guía de contribución

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.