Skip to content

Conversation

@dagardner-nv
Copy link
Contributor

@dagardner-nv dagardner-nv commented Nov 21, 2025

Description

  • The values of the SpanAttributes enum are defined on import, the fixture originally attempted to reload the span module. However this created a problem since other modules had already imported the span module, which would cause pydantic validation to fail as the original SpanContext class no longer strictly matches the new SpanContext.

  • Unrelated fix: Add the skip_e2e_test tag to the uv pip uninstall dask cell to prevent the notebook from altering the environment mid-test.

  • Silence a warning being emitted by strands that we have no control over [BUG] DeprecationWarning being emitted when importing strands strands-agents/sdk-python#1236

Closes #1197

By Submitting this PR I confirm:

  • I am familiar with the Contributing Guidelines.
  • We require that all contributors "sign-off" on their commits. This certifies that the contribution is your original work, or you have rights to submit it under the same license, or a compatible license.
    • Any contribution which contains commits that are not Signed-Off will not be accepted.
  • When the PR is ready for review, new or existing tests cover these changes.
  • When the PR is ready for review, the documentation is up to date with these changes.

Summary by CodeRabbit

  • Tests
    • Improved test fixture robustness by making reversible in-place adjustments instead of reloading modules or changing environment state.
  • Chores
    • Added a pytest warning filter to suppress a specific deprecation warning.
  • Docs/Examples
    • Marked a notebook step with a skip tag to exclude it from end-to-end test runs.

✏️ Tip: You can customize this high-level summary in your review settings.

Signed-off-by: David Gardner <[email protected]>
…e checks to fail in other modules which have already imported the span module

Signed-off-by: David Gardner <[email protected]>
@dagardner-nv dagardner-nv self-assigned this Nov 21, 2025
@dagardner-nv dagardner-nv added bug Something isn't working non-breaking Non-breaking change labels Nov 21, 2025
@review-notebook-app
Copy link

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@coderabbitai
Copy link

coderabbitai bot commented Nov 21, 2025

Walkthrough

Added a notebook cell metadata tag and refactored a test fixture to perform reversible in-place adjustments to span prefix enum values instead of reloading modules or changing environment variables; also added a pytest warning filter in configuration.

Changes

Cohort / File(s) Summary
Notebook metadata
examples/notebooks/getting_started_with_nat.ipynb
Added skip_e2e_test tag to the code cell metadata for the "uv pip uninstall dask" step.
Test fixture refactor
examples/observability/simple_calculator_observability/tests/test_simple_calc_observability.py
Reworked aiq_compatibility_span_prefix fixture to avoid importlib.reload and env var manipulation. It now reads span._SPAN_PREFIX, updates SpanAttributes enum values in-place (replacing matching prefixes), yields, then restores span._SPAN_PREFIX and original enum values.
Pytest warnings config
pyproject.toml
Added a filterwarnings entry to ignore a specific DeprecationWarning from strands, with an explanatory comment.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Test Runner
    participant Fixture as aiq_compatibility_span_prefix
    participant Span as span module
    participant Enum as SpanAttributes

    Note over Test,Fixture `#EFEFEF`: Test setup
    Test->>Fixture: enter fixture
    Fixture->>Span: read _SPAN_PREFIX (origPrefix)
    Fixture->>Enum: find values starting with origPrefix
    Fixture->>Enum: replace matching prefix with "aiq." (record originals)

    Note over Test,Fixture `#DFF7DF`: Test execution
    Fixture-->>Test: yield (tests run using modified enums)

    Note over Test,Fixture `#FDE8E8`: Teardown
    Test->>Fixture: fixture cleanup
    Fixture->>Span: restore _SPAN_PREFIX to origPrefix
    Fixture->>Enum: restore recorded original enum values
    Fixture-->>Test: teardown complete
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Focus areas during review:
    • Verify the fixture restores SpanAttributes values and span._SPAN_PREFIX reliably, including on exceptions.
    • Confirm no remaining use of importlib.reload or env var edits and that recorded originals cover all modified entries.
    • Ensure the new pytest warning filter targets the intended warning (message and module) without silencing unrelated deprecations.

Pre-merge checks and finishing touches

❌ Failed checks (1 inconclusive)
Check name Status Explanation Resolution
Out of Scope Changes check ❓ Inconclusive The PR includes a secondary unrelated change (adding skip_e2e_test tag to notebook cell), which the description acknowledges as unrelated and is appropriately minor; however, its necessity and scope relative to the main fix is not clearly justified. Consider clarifying whether the notebook tag addition is necessary for this release or should be a separate PR, to maintain clear separation of concerns.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is concise (47 characters), descriptive, uses imperative mood, and clearly describes the main change being a fix to the aiq_compatibility_span_prefix fixture.
Linked Issues check ✅ Passed The PR successfully fixes the aiq_compatibility_span_prefix fixture by eliminating module reloading and using reversible in-place adjustments to SpanAttributes enum values, directly addressing the root cause of pydantic validation errors in issue #1197.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7a5a360 and 8e3f6e3.

📒 Files selected for processing (1)
  • pyproject.toml (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*

⚙️ CodeRabbit configuration file

**/*: # Code Review Instructions

  • Ensure the code follows best practices and coding standards. - For Python code, follow
    PEP 20 and
    PEP 8 for style guidelines.
  • Check for security vulnerabilities and potential issues. - Python methods should use type hints for all parameters and return values (except for return values of None,
    in that situation no return type hint is needed).
    Example:
    def my_function(param1: int, param2: str) -> bool:
        pass
  • For Python exception handling, ensure proper stack trace preservation:
    • When re-raising exceptions: use bare raise statements to maintain the original stack trace,
      and use logger.error() (not logger.exception()) to avoid duplicate stack trace output.
    • When catching and logging exceptions without re-raising: always use logger.exception()
      to capture the full stack trace information.

Documentation Review Instructions - Verify that documentation and comments are clear and comprehensive. - Verify that the documentation doesn't contain any TODOs, FIXMEs or placeholder text like "lorem ipsum". - Verify that the documentation doesn't contain any offensive or outdated terms. - Verify that documentation and comments are free of spelling mistakes, ensure the documentation doesn't contain any

words listed in the ci/vale/styles/config/vocabularies/nat/reject.txt file, words that might appear to be
spelling mistakes but are listed in the ci/vale/styles/config/vocabularies/nat/accept.txt file are OK.

Misc. - All code (except .mdc files that contain Cursor rules) should be licensed under the Apache License 2.0,

and should contain an Apache License 2.0 header comment at the top of each file.

  • Confirm that copyright years are up-to date whenever a file is changed.

Files:

  • pyproject.toml
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: CI Pipeline / Check
🔇 Additional comments (1)
pyproject.toml (1)

305-308: Verify the pytest filterwarnings pattern syntax and matching behavior.

The filterwarnings pattern appears to use an incorrect format. Per pytest documentation, the pattern format is action:message:category:module:lineno. The current pattern:

"ignore:^These events have been moved to production.*strands:DeprecationWarning"

is parsed as: action=ignore, message=^These events have been moved to production.*strands, category=DeprecationWarning. This includes "strands" in the message regex, which means the warning will only be suppressed if the literal warning text contains "strands"—which is unlikely for a warning message.

The intended pattern should likely be:

- "ignore:^These events have been moved to production.*strands:DeprecationWarning",
+ "ignore:^These events have been moved to production.*:DeprecationWarning:strands",

This would correctly match the warning message from the strands module.

Please verify the actual warning message format emitted by strands-agents/sdk-python and confirm the filterwarnings pattern will match it correctly. You may also want to test the filter by running pytest with -W flags to ensure warnings are properly suppressed.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dagardner-nv dagardner-nv marked this pull request as ready for review November 21, 2025 22:26
@dagardner-nv dagardner-nv requested a review from a team as a code owner November 21, 2025 22:26
@dagardner-nv dagardner-nv marked this pull request as draft November 21, 2025 22:28
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
examples/observability/simple_calculator_observability/tests/test_simple_calc_observability.py (1)

79-100: Consider adding type hint for the fixture.

The fixture implementation correctly avoids the module reload issue by mutating enum values in-place. The approach of directly modifying _value_ on enum members is unconventional but necessary given that reloading causes pydantic validation failures (as described in the PR objectives). The restoration logic properly reverts all changes.

Consider adding a return type hint for better type safety:

 @pytest.fixture(name="aiq_compatibility_span_prefix")
-def aiq_compatibility_span_prefix_fixture():
+def aiq_compatibility_span_prefix_fixture() -> Generator[None, None, None]:
     """
     The values of the SpanAttributes are defined on import based upon the NAT_SPAN_PREFIX environment variable.
     Setting the environment variable after the fact has no impact.
     """

As per coding guidelines, Python functions should use type hints for parameters and return values.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6624f8d and 9392219.

📒 Files selected for processing (3)
  • examples/notebooks/getting_started_with_nat.ipynb (1 hunks)
  • examples/notebooks/mcp_setup_and_integration.ipynb (0 hunks)
  • examples/observability/simple_calculator_observability/tests/test_simple_calc_observability.py (1 hunks)
💤 Files with no reviewable changes (1)
  • examples/notebooks/mcp_setup_and_integration.ipynb
🧰 Additional context used
📓 Path-based instructions (2)
**/*

⚙️ CodeRabbit configuration file

**/*: # Code Review Instructions

  • Ensure the code follows best practices and coding standards. - For Python code, follow
    PEP 20 and
    PEP 8 for style guidelines.
  • Check for security vulnerabilities and potential issues. - Python methods should use type hints for all parameters and return values (except for return values of None,
    in that situation no return type hint is needed).
    Example:
    def my_function(param1: int, param2: str) -> bool:
        pass
  • For Python exception handling, ensure proper stack trace preservation:
    • When re-raising exceptions: use bare raise statements to maintain the original stack trace,
      and use logger.error() (not logger.exception()) to avoid duplicate stack trace output.
    • When catching and logging exceptions without re-raising: always use logger.exception()
      to capture the full stack trace information.

Documentation Review Instructions - Verify that documentation and comments are clear and comprehensive. - Verify that the documentation doesn't contain any TODOs, FIXMEs or placeholder text like "lorem ipsum". - Verify that the documentation doesn't contain any offensive or outdated terms. - Verify that documentation and comments are free of spelling mistakes, ensure the documentation doesn't contain any

words listed in the ci/vale/styles/config/vocabularies/nat/reject.txt file, words that might appear to be
spelling mistakes but are listed in the ci/vale/styles/config/vocabularies/nat/accept.txt file are OK.

Misc. - All code (except .mdc files that contain Cursor rules) should be licensed under the Apache License 2.0,

and should contain an Apache License 2.0 header comment at the top of each file.

  • Confirm that copyright years are up-to date whenever a file is changed.

Referenced Documentation Contents

ci/vale/styles/config/vocabularies/nat/reject.txt:
Defines regex patterns ...

Files:

  • examples/notebooks/getting_started_with_nat.ipynb
  • examples/observability/simple_calculator_observability/tests/test_simple_calc_observability.py
examples/**/*

⚙️ CodeRabbit configuration file

examples/**/*: - This directory contains example code and usage scenarios for the toolkit, at a minimum an example should
contain a README.md or file README.ipynb.

  • If an example contains Python code, it should be placed in a subdirectory named src/ and should
    contain a pyproject.toml file. Optionally, it might also contain scripts in a scripts/ directory.
  • If an example contains YAML files, they should be placed in a subdirectory named configs/. - If an example contains sample data files, they should be placed in a subdirectory named data/, and should
    be checked into git-lfs.

Files:

  • examples/notebooks/getting_started_with_nat.ipynb
  • examples/observability/simple_calculator_observability/tests/test_simple_calc_observability.py
🧬 Code graph analysis (1)
examples/observability/simple_calculator_observability/tests/test_simple_calc_observability.py (1)
src/nat/data_models/span.py (1)
  • SpanAttributes (92-106)
🔇 Additional comments (2)
examples/notebooks/getting_started_with_nat.ipynb (1)

437-437: LGTM! Documentation cleanup looks good.

The removal of dask uninstallation instructions simplifies the notebook setup without impacting functionality.

examples/observability/simple_calculator_observability/tests/test_simple_calc_observability.py (1)

81-84: Excellent addition of explanatory docstring.

The docstring clearly explains why this fixture is necessary - the SpanAttributes values are defined at import time based on the environment variable.

This reverts commit bdc6b0a.

Signed-off-by: David Gardner <[email protected]>
…s are not altering the installed packages

Signed-off-by: David Gardner <[email protected]>
@dagardner-nv dagardner-nv marked this pull request as ready for review November 22, 2025 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working non-breaking Non-breaking change

Projects

None yet

Development

Successfully merging this pull request may close these issues.

opentelemetry tests failing when all integration tests are run, passes otherwise

2 participants