Skip to content

fix: wire SGP_CLIENT_BASE_URL and silence openai-agents tracer in templates#352

Merged
danielmillerp merged 1 commit intonextfrom
dm/template-tracing-fixes
May 8, 2026
Merged

fix: wire SGP_CLIENT_BASE_URL and silence openai-agents tracer in templates#352
danielmillerp merged 1 commit intonextfrom
dm/template-tracing-fixes

Conversation

@danielmillerp
Copy link
Copy Markdown
Contributor

@danielmillerp danielmillerp commented May 8, 2026

Summary

Two tracing pitfalls hit when running the openai-agents templates against a non-default SGP environment with a LiteLLM proxy key:

  1. SGP_CLIENT_BASE_URL was being silently dropped. The sync-openai-agents and temporal-openai-agents templates constructed SGPTracingProcessorConfig without sgp_base_url, so the SDK fell back to its default host regardless of what the user set in .env. Result: 404s from the wrong SGP environment until you noticed and patched it yourself. (sync-langgraph and default-langgraph already had this wired up — no change needed there.)
  2. openai-agents SDK native tracer was 401'ing every request. It ships traces to api.openai.com using OPENAI_API_KEY, which fails when that key is actually a LiteLLM proxy key (the recommended setup per the templates' own LiteLLM key swap). Calling set_tracing_disabled(True) at module load silences that exporter. SGP traces continue to flow via the Agentex tracing manager.

Also added # SGP_CLIENT_BASE_URL= to every .env.example.j2 so the knob is visible when users copy .env.example to .env.

Files changed

  • templates/*/.env.example.j2 (all 7) — add commented SGP_CLIENT_BASE_URL
  • templates/sync-openai-agents/project/acp.py.j2 — wire sgp_base_url + set_tracing_disabled(True)
  • templates/temporal-openai-agents/project/workflow.py.j2 — same two fixes

Test plan

  • Run agentex init for sync-openai-agents against an SGP environment that requires a non-default base URL (e.g. enterprise SGP), set SGP_CLIENT_BASE_URL in .env, and confirm spans land in the dashboard
  • Confirm no Tracing client error 401: ... Incorrect API key provided: sk-... lines appear in logs when running with a LiteLLM proxy key as OPENAI_API_KEY
  • Repeat for temporal-openai-agents

🤖 Generated with Claude Code

Greptile Summary

This PR fixes two tracing pitfalls in the sync-openai-agents and temporal-openai-agents templates: it wires SGP_CLIENT_BASE_URL into SGPTracingProcessorConfig (matching the existing langgraph templates) and disables the openai-agents SDK's native tracer to prevent 401s when OPENAI_API_KEY is a LiteLLM proxy key. All seven .env.example.j2 files also gain a commented-out SGP_CLIENT_BASE_URL line for discoverability.

Confidence Score: 4/5

Safe to merge — fixes real user-facing bugs with no regressions; only finding is a minor import-ordering style issue in a template file.

All changes are P2 or lower. The fixes are correct and consistent with the pre-existing langgraph template pattern. One style issue (E402 mid-import execution in workflow.py.j2) has no runtime impact but is worth cleaning up in a generated template.

src/agentex/lib/cli/templates/temporal-openai-agents/project/workflow.py.j2 — import ordering style issue

Important Files Changed

Filename Overview
src/agentex/lib/cli/templates/sync-openai-agents/project/acp.py.j2 Adds set_tracing_disabled(True) and wires SGP_CLIENT_BASE_URL into SGPTracingProcessorConfig; changes are correct and consistent with langgraph templates
src/agentex/lib/cli/templates/temporal-openai-agents/project/workflow.py.j2 Mirrors acp.py.j2 fixes; set_tracing_disabled(True) is placed mid-import which is unconventional but intentional; sgp_base_url wired correctly
src/agentex/lib/cli/templates/sync-openai-agents/.env.example.j2 Adds commented SGP_CLIENT_BASE_URL knob for discoverability; straightforward documentation improvement
src/agentex/lib/cli/templates/temporal-openai-agents/.env.example.j2 Adds commented SGP_CLIENT_BASE_URL knob; same as all other .env.example.j2 templates

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[Module load] --> B[import agents SDK]
    B --> C["set_tracing_disabled(True)"]
    C --> D{SGP_API_KEY\n& SGP_ACCOUNT_ID\nset?}
    D -- Yes --> E["add_tracing_processor_config(\n  SGPTracingProcessorConfig(\n    sgp_base_url=SGP_CLIENT_BASE_URL\n  )\n)"]
    D -- No --> F[Tracing disabled / no-op]
    E --> G[SGP Tracing Active\nvia Agentex manager]
    C --> H[openai-agents native tracer\nsilenced — no calls to\napi.openai.com]
    G --> I[Spans land in\nSGP dashboard]
Loading

Fix All in Cursor Fix All in Claude Code Fix All in Codex

Prompt To Fix All With AI
Fix the following 1 code review issue. Work through them one at a time, proposing concise fixes.

---

### Issue 1 of 1
src/agentex/lib/cli/templates/temporal-openai-agents/project/workflow.py.j2:13-29
Module-level code between import blocks is an E402 violation and is inconsistent with how the same fix is applied in `acp.py.j2` (where `set_tracing_disabled(True)` comes after all imports). Moving all imports to the top and calling `set_tracing_disabled` afterward keeps the intent intact without breaking PEP 8 / isort expectations in the generated file.

```suggestion
from agents import Agent, Runner, set_tracing_disabled
from agentex.lib.core.temporal.plugins.openai_agents.hooks.hooks import TemporalStreamingHooks
from pydantic import BaseModel
from typing import List, Dict, Any
from temporalio.contrib import openai_agents
from project.activities import get_weather
from agentex.lib.core.tracing.tracing_processor_manager import (
    add_tracing_processor_config,
)
from agentex.lib.types.tracing import SGPTracingProcessorConfig
from datetime import timedelta

# Disable the openai-agents SDK's native tracer so it doesn't ship traces to
# api.openai.com using OPENAI_API_KEY (which may be a LiteLLM proxy key).
# SGP tracing below still runs via the Agentex tracing manager.
set_tracing_disabled(True)
```

Reviews (1): Last reviewed commit: "fix: wire SGP_CLIENT_BASE_URL and silenc..." | Re-trigger Greptile

…plates

Two tracing pitfalls hit when running the openai-agents templates against a
non-default SGP environment with a LiteLLM proxy key:

1. SGPTracingProcessorConfig hardcoded sgp_base_url=None so traces always went
   to the SDK default (api.egp.scale.com) regardless of SGP_CLIENT_BASE_URL.
   Wired the env var through for sync-openai-agents and temporal-openai-agents.
   sync-langgraph and default-langgraph already had this; no change there.

2. The openai-agents SDK's native tracer ships traces to api.openai.com using
   OPENAI_API_KEY. When OPENAI_API_KEY is a LiteLLM proxy key the SDK errors
   with 401 on every request. Calling set_tracing_disabled(True) at module
   load silences that exporter; SGP traces still flow through the Agentex
   tracing manager.

Also added SGP_CLIENT_BASE_URL to every .env.example.j2 so users see the knob
when they copy .env.example to .env.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@danielmillerp danielmillerp changed the base branch from main to next May 8, 2026 18:59
@danielmillerp danielmillerp merged commit 870324e into next May 8, 2026
33 of 34 checks passed
@danielmillerp danielmillerp deleted the dm/template-tracing-fixes branch May 8, 2026 19:01
@stainless-app stainless-app Bot mentioned this pull request May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant