Skip to content

Backport 2400 to 0.10.x release branch - #2417

Merged
EItanya merged 1 commit into
kagent-dev:release/v0.10.xfrom
krisztianfekete:backport-2400-release-v0.10.x
Aug 10, 2026
Merged

Backport 2400 to 0.10.x release branch#2417
EItanya merged 1 commit into
kagent-dev:release/v0.10.xfrom
krisztianfekete:backport-2400-release-v0.10.x

Conversation

@krisztianfekete

Copy link
Copy Markdown
Contributor

Backports #2400 to release/v0.10.x.

Cherry-picked 74321ee6b0d4e3b1ca7366ffc36d8703c94d5106 as 2400e7a2.

The cherry-pick applied without conflicts. One adaptation was needed: the new test_tracing.py agent-card fixture used the A2A v1.0 supportedInterfaces shape, which does not exist on
this branch (a2a-sdk 0.3.x), where AgentCard.url is required instead. Replaced with "url": "http://localhost:8080".

Validation:

  • uv sync --frozen (lock matches the bumped pin; opentelemetry-instrumentation-openai-agents already resolves to 0.52.5 here)
  • uv run pytest packages/kagent-openai/tests/ packages/kagent-core/tests/test_tracing_configure.py — 32 passed
  • uv run ruff check / ruff format --check
  • go build ./... && go vet ./pkg/telemetry/... && go test ./... in go/adk

…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)
Copilot AI lite review requested due to automatic review settings August 10, 2026 08:42
@krisztianfekete
krisztianfekete requested a review from a team as a code owner August 10, 2026 08:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 except block logs only the exception message, losing the traceback. Using logger.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.

Comment thread python/packages/kagent-openai/src/kagent/openai/_a2a.py
Comment thread python/packages/kagent-openai/src/kagent/openai/_a2a.py
@EItanya
EItanya merged commit 4cbb6ed into kagent-dev:release/v0.10.x Aug 10, 2026
32 checks passed
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.

5 participants