Skip to content

[serve] Add tracing support for Windows and enable test_tracing_utils#62821

Merged
abrarsheikh merged 11 commits intoray-project:masterfrom
baohg153:fix-enable-tracing-windows
Apr 26, 2026
Merged

[serve] Add tracing support for Windows and enable test_tracing_utils#62821
abrarsheikh merged 11 commits intoray-project:masterfrom
baohg153:fix-enable-tracing-windows

Conversation

@TriNguyen1208
Copy link
Copy Markdown
Contributor

@TriNguyen1208 TriNguyen1208 commented Apr 21, 2026

Description

This PR enables test_tracing_utils for Windows by addressing file locking issues and cross-platform line ending discrepancies. It also ensures that tracing tests are no longer skipped on Windows.

Key Changes

  • Re-enabled Windows Tests: Removed pytest.mark.skipif for the win32 platform to allow tracing tests to run in Windows environments.
  • Fixed File Handle Leak in ConsoleSpanExporter: ConsoleSpanExporter was initialized with an inline open() call that was never explicitly closed, causing a PermissionError on Windows when attempting to delete span files after tests. Fixed by subclassing ConsoleSpanExporter with a shutdown() method that explicitly flushes and closes the file handle. provider.shutdown() is now called inside safe_remove() to trigger the cleanup chain before deletion.
  • Improved Span Parsing: Replaced .split("}\n{") with re.split(r'}\s*\n\s*{', file_contents) in load_spans. This regex-based approach correctly handles different newline sequences (\n vs \r\n) and potential whitespace variations between JSON objects, preventing decoding failures.
  • Explicit Exporter Path: Added tracing_exporter_import_path=DEFAULT_TRACING_EXPORTER_IMPORT_PATH across multiple test cases to ensure consistent tracing configuration.

Related issues

Closes #61443


Additional information

  • Cleanup Refactor: Replaced all instances of shutil.rmtree and os.remove with safe_remove_directory for span directory management.
  • Windows Compatibility Fix: The load_spans fix is critical for Windows where ConsoleSpanExporter may output CRLF (\r\n) line endings, which previously broke the manual JSON string splitting logic.

Test Verification

  • Platform: Windows 11 / Windows 10
  • Command: pytest -v python/ray/serve/tests/test_tracing_utils.py
  • Result: Verified that all tests in test_tracing_utils.py pass locally on Windows after applying these changes.
image

Signed-off-by: baohg153 <baohg.main@gmail.com>
Signed-off-by: phmkhoi <phanhuynhminhkhoi@gmail.com>
Signed-off-by: TriNguyen1208 <ductri0981@gmail.com>
@TriNguyen1208 TriNguyen1208 requested a review from a team as a code owner April 21, 2026 16:23
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a safe_remove_directory utility to handle Windows file locking issues during test cleanup and updates tracing tests to utilize a consistent exporter import path. Feedback was provided to improve the robustness of the safe_remove_directory function by addressing potential silent failures, ensuring idempotency, and reducing code duplication. Additionally, it is recommended to remove commented-out code in the load_spans function to improve readability.

Comment thread python/ray/serve/tests/test_tracing_utils.py Outdated
Comment thread python/ray/serve/tests/test_tracing_utils.py Outdated
Comment thread python/ray/serve/tests/test_tracing_utils.py Outdated
Signed-off-by: baohg153 <baohg.main@gmail.com>
Signed-off-by: phmkhoi <phanhuynhminhkhoi@gmail.com>
Signed-off-by: TriNguyen1208 <ductri0981@gmail.com>
Comment thread python/ray/serve/tests/test_tracing_utils.py
Comment thread python/ray/serve/_private/tracing_utils.py Outdated
@phmkhoi
Copy link
Copy Markdown
Contributor

phmkhoi commented Apr 22, 2026

Hi @abrarsheikh @akyang-anyscale,

Could you please take a look at this PR when you have a chance? All available CI checks have passed, though Buildkite premerge is still waiting to be triggered.

Happy to make any changes based on your feedback. Thank you!

@abrarsheikh abrarsheikh added the go add ONLY when ready to merge, run all tests label Apr 22, 2026
TriNguyen1208 and others added 2 commits April 23, 2026 09:12
Signed-off-by: baohg153 <baohg.main@gmail.com>
Signed-off-by: phmkhoi <phanhuynhminhkhoi@gmail.com>
Signed-off-by: TriNguyen1208 <ductri0981@gmail.com>
Comment thread python/ray/serve/tests/test_tracing_utils.py
Signed-off-by: baohg153 <baohg.main@gmail.com>
Signed-off-by: phmkhoi <phanhuynhminhkhoi@gmail.com>
Signed-off-by: TriNguyen1208 <ductri0981@gmail.com>
Signed-off-by: baohg153 <baohg.main@gmail.com>
Signed-off-by: phmkhoi <phanhuynhminhkhoi@gmail.com>
Signed-off-by: TriNguyen1208 <ductri0981@gmail.com>
Comment thread python/ray/serve/tests/test_tracing_utils.py Outdated
phmkhoi added 2 commits April 24, 2026 13:42
Signed-off-by: baohg153 <baohg.main@gmail.com>
Signed-off-by: phmkhoi <phanhuynhminhkhoi@gmail.com>
Signed-off-by: TriNguyen1208 <ductri0981@gmail.com>
Comment thread python/ray/serve/tests/test_tracing_utils.py Outdated
Signed-off-by: baohg153 <baohg.main@gmail.com>
Signed-off-by: phmkhoi <phanhuynhminhkhoi@gmail.com>
Signed-off-by: TriNguyen1208 <ductri0981@gmail.com>

Signed-off-by: Nguyễn Đức Trí <168810923+TriNguyen1208@users.noreply.github.com>
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Reviewed by Cursor Bugbot for commit eaaf573. Configure here.

component_type=ServeComponentType.REPLICA,
component_name="component_name",
component_id="component_id",
tracing_exporter_import_path=DEFAULT_TRACING_EXPORTER_IMPORT_PATH,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Test relies on env var to reach error path

Medium Severity

Removing tracing_exporter_import_path=DEFAULT_TRACING_EXPORTER_IMPORT_PATH from the test_missing_dependencies call to setup_tracing causes the test to depend on the RAY_SERVE_TRACING_EXPORTER_IMPORT_PATH env var being set externally (by Bazel). Without it, the env var defaults to "", and setup_tracing returns False at the tracing_exporter_import_path == "" check before ever reaching the if not trace: check that raises ImportError. The pytest.raises(ImportError) block then fails because no exception is raised. Unlike other tests that inherently need tracing enabled, this test specifically needs a non-empty import path to exercise the dependency-check error path.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit eaaf573. Configure here.

@phmkhoi
Copy link
Copy Markdown
Contributor

phmkhoi commented Apr 26, 2026

Hi @abrarsheikh,

Could you please take a look at this PR again when you have a chance? I have adjusted the code with your previous reviews, and all checks have passed.
Happy to make any changes based on your feedback. Thank you!

@abrarsheikh
Copy link
Copy Markdown
Contributor

@TriNguyen1208 thanks for your contribution, I see you have access to a windows machine, if you wish to maintain serve for windows please reach out over slack, there are many other tests in the repo we are skipping for windows purely because the team doesn't have the bandwidth to maintain it. LMK.

@abrarsheikh abrarsheikh merged commit ba15069 into ray-project:master Apr 26, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-contribution Contributed by the community go add ONLY when ready to merge, run all tests serve Ray Serve Related Issue windows

Development

Successfully merging this pull request may close these issues.

[serve] Add tracing support for windows

3 participants