Skip to content

fix(plugins): don't fail calls on interface URLs without a valid port - #1573

Open
ShivamSharma43 wants to merge 3 commits into
a2aproject:mainfrom
ShivamSharma43:fix/otel-invalid-port
Open

ShivamSharma43 wants to merge 3 commits into
a2aproject:mainfrom
ShivamSharma43:fix/otel-invalid-port

Conversation

@ShivamSharma43

@ShivamSharma43 ShivamSharma43 commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Description

The OpenTelemetry plugin (a2a.plugins.otel) sets server.address and server.port on client spans from the selected interface URL, using _semconv.host_port. That function returns urlparse(...).port, and urlparse's port property raises ValueError when the text after the last : is not a valid port. The call happens in before_client_request (plugin.py → _set_client_request_attributes → _set_interface_attributes), so the exception escapes from BaseClient._execute_with_interceptors and the client call fails before the transport is reached.

This affects valid gRPC target strings that the gRPC transport passes as-is to grpc_channel_factory, as well as malformed URLs:

Interface URL Before After
http://remote:9000, localhost:50051, ipv6:[::1]:50051 address and port set unchanged
ipv4:10.0.0.1:50051 ValueError: Port could not be cast to integer value as '10.0.0.1:50051', call fails call succeeds, address and port not set
unix-abstract:name, vsock:3:50051 ValueError, call fails call succeeds, address and port not set
http://remote:invalid, http://remote:99999, http://[::1 ValueError from the plugin before the transport runs address and port not set; the call goes on to the transport

Fix

host_port catches ValueError from urlparse and returns (None, None), so neither attribute is set. The span is still created and the other attributes are unchanged. Both values are left out, not only the port, because for these inputs the parsed hostname is wrong too (ipv4 for ipv4:10.0.0.1:50051).

Tests

  • Added grpc-ipv4-target (ipv4:10.0.0.1:50051) and invalid-port (http://remote:invalid) cases to test_interface_and_tenant_attributes in tests/plugins/test_otel.py. Both fail on main with the ValueError raised from before_client_request, and pass with the fix.
  • pytest tests/plugins: 109 passed.
  • Full pytest tests on Windows: the only failures are in tests/integration subprocess tests (test_samples_smoke.py, cross_version/, push_notifications/test_default_push_notification_support.py). They fail for local Windows reasons (cp1252 console encoding, multiprocessing spawn pickling, invalid subprocess handle) and don't touch the plugin.
  • ruff check and ruff format --check pass on the changed files. ty check passes on _semconv.py.

This PR was prepared with AI assistance (Claude Code).

🤖 Generated with Claude Code

The OpenTelemetry plugin reads server.address and server.port from the
selected interface URL through urlparse, whose port property raises
ValueError when the text after the last colon is not a valid port. That
covers valid gRPC targets such as 'ipv4:10.0.0.1:50051',
'unix-abstract:name' or 'vsock:3:50051', and malformed URLs. The error
was raised from before_client_request, so the client call failed before
reaching the transport.

Leave both attributes unset when the URL cannot be parsed as host:port.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ShivamSharma43
ShivamSharma43 requested a review from a team as a code owner December 1, 2026 16:47
Copilot AI balanced review requested due to automatic review settings December 1, 2026 16:47

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

@github-actions

github-actions Bot commented Dec 1, 2026 •

Copy link
Copy Markdown

🧪 Code Coverage (vs main)

⬇️ Download Full Report

Base PR Delta
src/a2a/plugins/otel/_semconv.py 95.65% 96.00% 🟢 +0.35%
src/a2a/plugins/otel/plugin.py 94.99% 95.28% 🟢 +0.29%
Total 94.31% 94.32% 🟢 +0.01%

Generated by coverage-comment.yml

This branch has not been deployed

No deployments
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.

2 participants