Skip to content

fix(http): end redirect and CAE retry spans - #735

Merged
Vincent Biret (baywet) merged 1 commit into
microsoft:mainfrom
rksharma-owg:fix/http-span-cleanup
Sep 16, 2026
Merged

Vincent Biret (baywet) merged 1 commit into
microsoft:mainfrom
rksharma-owg:fix/http-span-cleanup

Conversation

@rksharma-owg

Copy link
Copy Markdown
Contributor

Overview

Redirect-attempt spans and CAE retry-decision spans remain open after successful HTTP operations because their normal exit paths never end them. End each span in a finally block so returns, redirects, transport errors, and cancellation all release it. Record the existing redirect-limit exception before ending its span, and keep the CAE span open until its awaited retry finishes.

Regression tests use real OpenTelemetry spans with an in-memory exporter. They cover successful and disabled redirects, redirect chains and limits, transport failures and cancellation, each no-retry CAE path, and successful or interrupted retries. The existing CAE integration test also verifies both recursive decision spans are exported.

Related Issue

Fixes #508

Testing Instructions

From packages/http/httpx, install requirements-dev.txt, then run:

  • pytest: 124 tests passed on Python 3.12.
  • pytest tests/middleware_tests/test_redirect_handler.py tests/test_httpx_request_adapter.py -q: 77 passed. All 14 added regression cases failed against the unmodified implementation.
  • yapf -dr kiota_http, pylint kiota_http --disable=W --rcfile=.pylintrc, and mypy kiota_http: exited successfully; mypy checked 24 source files.
  • isort --check-only kiota_http/httpx_request_adapter.py kiota_http/middleware/redirect_handler.py: passed.
  • uv build: source distribution and wheel built successfully.

The package-wide isort --check-only kiota_http reports an existing import-order issue in unchanged middleware/options/redirect_handler_option.py; the same check fails on clean main at 1d104f2. Pylint emits the same existing suggestion-mode configuration diagnostic on main and this branch while exiting zero. Neither baseline issue is changed here.

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.

🟢 Approval recommended

No unresolved issues were identified, and regression tests cover the changed paths.

Pull request overview

Fixes stale OpenTelemetry spans in HTTP redirect handling and CAE retry decisions.

Changes:

  • Finalizes redirect spans on all exit paths.
  • Finalizes CAE retry spans after retries, errors, or cancellation.
  • Adds regression tests with an in-memory span exporter.
File summaries
File Description
packages/http/httpx/tests/test_httpx_request_adapter.py Tests CAE span lifecycle and recursion.
packages/http/httpx/tests/middleware_tests/test_redirect_handler.py Tests redirect span completion paths.
packages/http/httpx/tests/conftest.py Adds the OpenTelemetry exporter fixture.
packages/http/httpx/kiota_http/middleware/redirect_handler.py Ensures redirect spans always end.
packages/http/httpx/kiota_http/httpx_request_adapter.py Ensures CAE spans end across all paths.
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@baywet Vincent Biret (baywet) left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for the contribution!

@github-project-automation github-project-automation Bot moved this to In Progress 🚧 in Kiota Sep 16, 2026
Ensure tracing spans end after successful operations, failures, and cancellation, retaining redirect-limit error events.

Fixes microsoft#508
@sonarqubecloud

Copy link
Copy Markdown

@baywet
Vincent Biret (baywet) merged commit ac310b4 into microsoft:main Sep 16, 2026
53 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress 🚧 to Done ✔️ in Kiota Sep 16, 2026
@rksharma-owg
RKS (rksharma-owg) deleted the fix/http-span-cleanup branch September 16, 2026 17:52
@rksharma-owg

Copy link
Copy Markdown
Contributor Author

Cool..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done ✔️

Development

Successfully merging this pull request may close these issues.

httpx: OpenTelemetry spans never end for RedirectHandler_send and retry_cae_response_if_required

3 participants