fix(http): end redirect and CAE retry spans - #735
Merged
Vincent Biret (baywet) merged 1 commit intoSep 16, 2026
Merged
Conversation
There was a problem hiding this comment.
🟢 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.
Vincent Biret (baywet)
approved these changes
Sep 16, 2026
Vincent Biret (baywet)
left a comment
Member
There was a problem hiding this comment.
Thanks for the contribution!
Ensure tracing spans end after successful operations, failures, and cancellation, retaining redirect-limit error events. Fixes microsoft#508
Vincent Biret (baywet)
force-pushed
the
fix/http-span-cleanup
branch
from
September 16, 2026 17:44
850afb9 to
ee1682a
Compare
Vincent Biret (baywet)
enabled auto-merge
September 16, 2026 17:44
|
Contributor
Author
|
Cool.. |
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.



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
finallyblock 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, installrequirements-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, andmypy 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_httpreports an existing import-order issue in unchangedmiddleware/options/redirect_handler_option.py; the same check fails on clean main at1d104f2. Pylint emits the same existingsuggestion-modeconfiguration diagnostic on main and this branch while exiting zero. Neither baseline issue is changed here.