From 991fb41d8fe72df910dec5895b1f0cd5b6c895b2 Mon Sep 17 00:00:00 2001 From: Erica Pisani Date: Tue, 1 Sep 2026 15:21:35 -0400 Subject: [PATCH] feat(test-openai): Migrate start_transaction to streamed spans Under trace_lifecycle="stream", sentry_sdk.start_transaction() returns a NoOpSpan, so convert the 8 live calls to sentry_sdk.traces.start_span() across main.py, main_async.py, main_custom.py, main_streamed.py, main_truncation.py, main_conversation.py, and main_conversation_async.py. --- test-openai/main.py | 3 ++- test-openai/main_async.py | 3 ++- test-openai/main_conversation.py | 5 +++-- test-openai/main_conversation_async.py | 3 ++- test-openai/main_custom.py | 3 ++- test-openai/main_streamed.py | 3 ++- test-openai/main_truncation.py | 3 ++- 7 files changed, 15 insertions(+), 8 deletions(-) diff --git a/test-openai/main.py b/test-openai/main.py index 90defb0..5fe0093 100644 --- a/test-openai/main.py +++ b/test-openai/main.py @@ -3,6 +3,7 @@ from openai import OpenAI import sentry_sdk +import sentry_sdk.traces from sentry_sdk.ai.monitoring import ai_track from sentry_sdk.integrations.openai import OpenAIIntegration from sentry_sdk.integrations.stdlib import StdlibIntegration @@ -33,7 +34,7 @@ @ai_track("My sync OpenAI workflow") def my_workflow(client): - with sentry_sdk.start_transaction(name="openai-sync"): + with sentry_sdk.traces.start_span(name="openai-sync"): # Responses API with tools response = client.responses.create( model="gpt-4o-mini", diff --git a/test-openai/main_async.py b/test-openai/main_async.py index a4fe895..44ef5bd 100644 --- a/test-openai/main_async.py +++ b/test-openai/main_async.py @@ -4,6 +4,7 @@ from openai import AsyncOpenAI import sentry_sdk +import sentry_sdk.traces from sentry_sdk.ai.monitoring import ai_track from sentry_sdk.integrations.openai import OpenAIIntegration from sentry_sdk.integrations.stdlib import StdlibIntegration @@ -36,7 +37,7 @@ @ai_track("My async OpenAI workflow") async def my_workflow(client): - with sentry_sdk.start_transaction(name="openai-async"): + with sentry_sdk.traces.start_span(name="openai-async"): # Responses API with tools response = await client.responses.create( model="gpt-4o-mini", diff --git a/test-openai/main_conversation.py b/test-openai/main_conversation.py index 147c1c5..ca8186a 100644 --- a/test-openai/main_conversation.py +++ b/test-openai/main_conversation.py @@ -4,6 +4,7 @@ from openai import OpenAI import sentry_sdk +import sentry_sdk.traces from sentry_sdk.ai.monitoring import ai_track from sentry_sdk.ai.utils import set_conversation_id from sentry_sdk.integrations.openai import OpenAIIntegration @@ -21,7 +22,7 @@ def conversation_workflow(client): messages = [] - with sentry_sdk.start_transaction(name="openai-conversation"): + with sentry_sdk.traces.start_span(name="openai-conversation"): # Turn 1: Initial question messages.append({"role": "user", "content": "Hi! I'm planning a trip to Japan. What's the best time to visit?"}) @@ -80,7 +81,7 @@ def interleaved_conversations_workflow(client): messages_a = [] messages_b = [] - with sentry_sdk.start_transaction(name="openai-interleaved-conversations"): + with sentry_sdk.traces.start_span(name="openai-interleaved-conversations"): # Conversation A - Turn 1 set_conversation_id(conversation_id_a) messages_a.append({"role": "user", "content": "I want to learn Python. Where should I start?"}) diff --git a/test-openai/main_conversation_async.py b/test-openai/main_conversation_async.py index daaf712..e5a507f 100644 --- a/test-openai/main_conversation_async.py +++ b/test-openai/main_conversation_async.py @@ -5,6 +5,7 @@ from openai import AsyncOpenAI import sentry_sdk +import sentry_sdk.traces from sentry_sdk.ai.monitoring import ai_track from sentry_sdk.ai.utils import set_conversation_id from sentry_sdk.integrations.asyncio import AsyncioIntegration @@ -95,7 +96,7 @@ async def concurrent_conversations_workflow(client): print(f"Conversation A ID: {conversation_id_a}") print(f"Conversation B ID: {conversation_id_b}") - with sentry_sdk.start_transaction(name="openai-concurrent-conversations"): + with sentry_sdk.traces.start_span(name="openai-concurrent-conversations"): # Run both conversations concurrently results = await asyncio.gather( conversation_a(client, conversation_id_a), diff --git a/test-openai/main_custom.py b/test-openai/main_custom.py index 8a795c3..13959e4 100644 --- a/test-openai/main_custom.py +++ b/test-openai/main_custom.py @@ -3,6 +3,7 @@ from openai import OpenAI import sentry_sdk +import sentry_sdk.traces from sentry_sdk.consts import SPANTEMPLATE, SPANDATA from sentry_sdk.integrations.openai import OpenAIIntegration from sentry_sdk.integrations.stdlib import StdlibIntegration @@ -65,7 +66,7 @@ def main(): api_key=os.environ.get("OPENAI_API_KEY"), ) - with sentry_sdk.start_transaction(name="main"): + with sentry_sdk.traces.start_span(name="main"): my_socalled_agent(client) print("--------------------------------") diff --git a/test-openai/main_streamed.py b/test-openai/main_streamed.py index af79ffb..c363d6d 100644 --- a/test-openai/main_streamed.py +++ b/test-openai/main_streamed.py @@ -3,6 +3,7 @@ from openai import OpenAI import sentry_sdk +import sentry_sdk.traces from sentry_sdk.ai.monitoring import ai_track from sentry_sdk.integrations.openai import OpenAIIntegration from sentry_sdk.integrations.stdlib import StdlibIntegration @@ -10,7 +11,7 @@ @ai_track("Streamed OpenAI workflow") def streamed_workflow(client): - with sentry_sdk.start_transaction(name="openai-streamed"): + with sentry_sdk.traces.start_span(name="openai-streamed"): # Chat Completions API with streaming print("Starting streamed chat completion...") stream = client.chat.completions.create( diff --git a/test-openai/main_truncation.py b/test-openai/main_truncation.py index 98e6c89..161bef1 100644 --- a/test-openai/main_truncation.py +++ b/test-openai/main_truncation.py @@ -3,6 +3,7 @@ from openai import OpenAI import sentry_sdk +import sentry_sdk.traces from sentry_sdk.ai.monitoring import ai_track from sentry_sdk.integrations.openai import OpenAIIntegration from sentry_sdk.integrations.stdlib import StdlibIntegration @@ -24,7 +25,7 @@ def generate_long_message(index): @ai_track("My truncation test workflow") def my_truncation_workflow(client): - with sentry_sdk.start_transaction(name="openai-truncation-test"): + with sentry_sdk.traces.start_span(name="openai-truncation-test"): messages = [] for i in range(25):