Backport 2400 to 0.10.x release branch - #2417
Merged
EItanya merged 1 commit intoAug 10, 2026
Merged
Conversation
…dev#2400) The Agents SDK registers a trace processor that POSTs everything to a hardcoded `https://api.openai.com/v1/traces/ingest` using `OPENAI_API_KEY`. It ignores `OPENAI_API_BASE`, so anyone behind other proxies is shipping their gateway's key to OpenAI and getting 401s back. `OpenAIAgentsInstrumentor` adds the OTel processor next to that one rather than replacing it, and `set_tracing_disabled(True)` would silence the OTel spans too, so we now drop the built-in processor before instrumenting. Set `KAGENT_OPENAI_AGENTS_NATIVE_TRACING=true` to keep it if you're using a real OpenAI key. Using `OpenAIAgentsInstrumentor(replace_existing_processors=True)` as suggested in review, with the pin bumped to `>=0.52.3,<0.53.0` since that's when the kwarg landed. Doing it through the kwarg also means a second `build()` can't wipe the OTel processor, since `instrument()` no-ops once instrumented. Cleaned up a couple of other smaller stuff: - `Resource(...)` -> `Resource.create(...)`: the bare constructor ignores `OTEL_RESOURCE_ATTRIBUTES` and drops `telemetry.sdk.*`, so nobody could set `deployment.environment.name` or `service.version` at all. - Same bug in the Go ADK, `resource.New` starts empty so it needs `WithFromEnv()` + `WithTelemetrySDK()`. - `HTTPXClientInstrumentor().instrument(excluded_urls=...)` did nothing, cleaned it up. - `_a2a.py` read `self.config.kagent_url` but `KAgentConfig` only has `url`, which blows up whenever `KAGENT_URL` isn't set. Rebased onto main, which dropped the Gemini bullet from this PR since main landed the same fix independently. --------- Signed-off-by: krisztianfekete <git@krisztianfekete.org> (cherry picked from commit 74321ee)
Contributor
There was a problem hiding this comment.
Pull request overview
Backports #2400 onto release/v0.10.x to prevent the OpenAI Agents SDK from exporting traces to the hardcoded api.openai.com ingest endpoint by default, routing tracing through OpenTelemetry instead, and ensuring OTel resource attributes from the environment are preserved in both Python and Go.
Changes:
- Update OpenAI Agents SDK tracing setup to drop the SDK’s native exporter by default (opt-in to keep it via env var), with new Python tests covering the behavior.
- Fix KAgent OpenAI app config usage (
KAgentConfig.url), and harden build-time tracing behavior when tracing configuration fails. - Use OTel resource constructors that merge
OTEL_RESOURCE_ATTRIBUTES/telemetry.sdk.*, with corresponding unit tests in Python and Go.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| python/uv.lock | Narrows opentelemetry-instrumentation-openai-agents pin to include the needed kwarg behavior. |
| python/packages/kagent-openai/pyproject.toml | Bumps opentelemetry-instrumentation-openai-agents dependency range to >=0.52.3,<0.53.0. |
| python/packages/kagent-openai/src/kagent/openai/_a2a.py | Drops Agents SDK native trace exporter by default; fixes config URL field usage; adjusts tracing setup flow. |
| python/packages/kagent-openai/tests/test_tracing.py | Adds regression tests ensuring native exporter is removed (unless opted-in) and spans still reach OTel. |
| python/packages/kagent-core/src/kagent/core/tracing/_utils.py | Switches to Resource.create(...) and removes ineffective HTTPX excluded_urls wiring. |
| python/packages/kagent-core/tests/test_tracing_configure.py | Adds test asserting OTEL_RESOURCE_ATTRIBUTES are merged into the configured resource. |
| go/adk/pkg/telemetry/tracing.go | Builds OTel resources with WithFromEnv() + WithTelemetrySDK() to preserve env/SDK attributes. |
| go/adk/pkg/telemetry/tracing_test.go | Adds test verifying env resource attributes and telemetry.sdk.* are present and merged correctly. |
Suppressed comments (1)
python/packages/kagent-openai/src/kagent/openai/_a2a.py:211
- This
exceptblock logs only the exception message, losing the traceback. Usinglogger.exception(...)here will include stack details, which is important for diagnosing instrumentation failures.
except Exception as e:
logger.error(f"Failed to configure OpenAI Agents SDK tracing: {e}")
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
dhaifley
approved these changes
Aug 10, 2026
peterj
approved these changes
Aug 10, 2026
EItanya
approved these changes
Aug 10, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backports #2400 to
release/v0.10.x.Cherry-picked
74321ee6b0d4e3b1ca7366ffc36d8703c94d5106as2400e7a2.The cherry-pick applied without conflicts. One adaptation was needed: the new
test_tracing.pyagent-card fixture used the A2A v1.0supportedInterfacesshape, which does not exist onthis branch (a2a-sdk 0.3.x), where
AgentCard.urlis required instead. Replaced with"url": "http://localhost:8080".Validation:
uv sync --frozen(lock matches the bumped pin;opentelemetry-instrumentation-openai-agentsalready resolves to 0.52.5 here)uv run pytest packages/kagent-openai/tests/ packages/kagent-core/tests/test_tracing_configure.py— 32 passeduv run ruff check/ruff format --checkgo build ./... && go vet ./pkg/telemetry/... && go test ./...ingo/adk