Skip to content

Commit 29fc4af

Browse files
xumapleclaude
andauthored
AI-18: Move set_tracing_disabled from workflow to worker startup (#288)
* AI-18: Move set_tracing_disabled from workflow to worker startup set_tracing_disabled is a global side effect that shouldn't be called inside deterministic workflow code. Move it to the top of main() in the worker files where it runs once at process startup. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * AI-18: Add comment explaining why tracing is disabled at worker startup Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com> * linting --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent ce5d8dd commit 29fc4af

4 files changed

Lines changed: 19 additions & 7 deletions

File tree

openai_agents/model_providers/run_gpt_oss_worker.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,12 @@
33
from datetime import timedelta
44
from typing import Optional
55

6-
from agents import Model, ModelProvider, OpenAIChatCompletionsModel
6+
from agents import (
7+
Model,
8+
ModelProvider,
9+
OpenAIChatCompletionsModel,
10+
set_tracing_disabled,
11+
)
712
from openai import AsyncOpenAI
813
from temporalio.client import Client
914
from temporalio.contrib.openai_agents import ModelActivityParameters, OpenAIAgentsPlugin
@@ -27,6 +32,11 @@ def get_model(self, model_name: Optional[str]) -> Model:
2732

2833

2934
async def main():
35+
# Disable Agents SDK tracing — the default exporter sends traces to OpenAI's
36+
# backend, which requires an OpenAI API key not available in these samples.
37+
# Call here rather than in the workflow because it's a global side effect.
38+
set_tracing_disabled(disabled=True)
39+
3040
# Configure logging to show workflow debug messages
3141
logging.basicConfig(level=logging.WARNING)
3242
logging.getLogger("temporalio.workflow").setLevel(logging.DEBUG)

openai_agents/model_providers/run_litellm_provider_worker.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
22
from datetime import timedelta
33

4+
from agents import set_tracing_disabled
45
from agents.extensions.models.litellm_provider import LitellmProvider
56
from temporalio.client import Client
67
from temporalio.contrib.openai_agents import ModelActivityParameters, OpenAIAgentsPlugin
@@ -12,6 +13,11 @@
1213

1314

1415
async def main():
16+
# Disable Agents SDK tracing — the default exporter sends traces to OpenAI's
17+
# backend, which requires an OpenAI API key not available in these samples.
18+
# Call here rather than in the workflow because it's a global side effect.
19+
set_tracing_disabled(disabled=True)
20+
1521
# Create client connected to server at the given address
1622
client = await Client.connect(
1723
"localhost:7233",

openai_agents/model_providers/workflows/gpt_oss_workflow.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
from __future__ import annotations
22

3-
from agents import Agent, Runner, function_tool, set_tracing_disabled
3+
from agents import Agent, Runner, function_tool
44
from temporalio import workflow
55

66

77
@workflow.defn
88
class GptOssWorkflow:
99
@workflow.run
1010
async def run(self, prompt: str) -> str:
11-
set_tracing_disabled(disabled=True)
12-
1311
@function_tool
1412
def get_weather(city: str):
1513
workflow.logger.debug(f"Getting weather for {city}")

openai_agents/model_providers/workflows/litellm_auto_workflow.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
from __future__ import annotations
22

3-
from agents import Agent, Runner, function_tool, set_tracing_disabled
3+
from agents import Agent, Runner, function_tool
44
from temporalio import workflow
55

66

77
@workflow.defn
88
class LitellmAutoWorkflow:
99
@workflow.run
1010
async def run(self, prompt: str) -> str:
11-
set_tracing_disabled(disabled=True)
12-
1311
@function_tool
1412
def get_weather(city: str):
1513
return f"The weather in {city} is sunny."

0 commit comments

Comments
 (0)