8000 feat: Add environment variable setting for default retention policy by fjcasti1 · Pull Request #8178 · Arize-ai/phoenix · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

feat: Add environment variable setting for default retention policy #8178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

fjcasti1
Copy link
Contributor
@fjcasti1 fjcasti1 commented Jun 20, 2025

Summary by Sourcery

Add an environment variable to configure the default trace retention policy and apply it in the database facilitator

New Features:

  • Introduce PHOENIX_DEFAULT_RETENTION_POLICY_DAYS environment variable and constant
  • Implement get_env_default_retention_policy_days() to parse the new environment variable

Enhancements:

  • Use get_env_default_retention_policy_days() in ProjectTraceRetentionPolicy default rule instead of a hardcoded value

@fjcasti1 fjcasti1 requested a review from a team as a code owner June 20, 2025 16:37
@github-project-automation github-project-automation bot moved this to 📘 Todo in phoenix Jun 20, 2025
@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jun 20, 2025
Copy link
Contributor
@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @fjcasti1 - I've reviewed your changes - here's some feedback:

  • The docstring for get_env_default_retention_policy_days is incorrect (mentions a boolean and cert verification); please update it to accurately describe the integer days and default behavior.
  • Using assert for validating the env var can be skipped in optimized runs—consider raising a ValueError or handling negative values more explicitly.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The docstring for get_env_default_retention_policy_days is incorrect (mentions a boolean and cert verification); please update it to accurately describe the integer days and default behavior.
- Using assert for validating the env var can be skipped in optimized runs—consider raising a ValueError or handling negative values more explicitly.

## Individual Comments

### Comment 1
<location> `src/phoenix/config.py:463` </location>
<code_context>
     return _bool_val(ENV_PHOENIX_TLS_VERIFY_CLIENT, False)


+def get_env_default_retention_policy_days() -> int:
+    """
+    Gets the value of the PHOENIX_DEFAULT_RETENTION_POLICY_DAYS environment variable.
</code_context>

<issue_to_address>
The docstring for get_env_default_retention_policy_days is inaccurate.

Update the docstring to state that the function returns the number of days for the default retention policy, defaulting to 0 if not set.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
    """
    Gets the value of the PHOENIX_DEFAULT_RETENTION_POLICY_DAYS environment variable.

    Returns:
        int: True if client certificate verification is enabled, False otherwise. Defaults to False
        if the environment variable is not set.
    """  # noqa: E501
=======
    """
    Returns the number of days for the default retention policy as set by the
    PHOENIX_DEFAULT_RETENTION_POLICY_DAYS environment variable, defaulting to 0 if not set.

    Returns:
        int: Number of days for the default retention policy. Defaults to 0 if the environment variable is not set.
    """  # noqa: E501
>>>>>>> REPLACE

</suggested_fix>

### Comment 2
<location> `src/phoenix/config.py:472` </location>
<code_context>
+        if the environment variable is not set.
+    """  # noqa: E501
+    days = _int_val(ENV_PHOENIX_DEFAULT_RETENTION_POLICY_DAYS, 0)
+    assert days >= 0
+    return days
+
</code_context>

<issue_to_address>
Using assert for input validation may not be reliable in production.

Assertions can be disabled at runtime, so use an explicit exception (e.g., raise ValueError) to enforce this check reliably.
</issue_to_address>

<suggested_fix>
<<<<<<< SEARCH
    days = _int_val(ENV_PHOENIX_DEFAULT_RETENTION_POLICY_DAYS, 0)
    assert days >= 0
    return days
=======
    days = _int_val(ENV_PHOENIX_DEFAULT_RETENTION_POLICY_DAYS, 0)
    if days < 0:
        raise ValueError("PHOENIX_DEFAULT_RETENTION_POLICY_DAYS must be non-negative")
    return days
>>>>>>> REPLACE

</suggested_fix>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines 467 to 469
Returns:
int: True if client certificate verification is enabled, False otherwise. Defaults to False
if the environment variable is not set.
Copy link
Contributor

Choose a reason for hiding this comment

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

The docstring for get_env_default_retention_policy_days() contains incorrect return value documentation. It appears to be copied from another function and describes boolean behavior related to client certificate verification, but this function actually returns an integer representing days.

The return documentation should be updated to:

Returns:
    int: The default retention policy in days. Defaults to 0 if the environment variable is not set.
Suggested change
Returns:
int: True if client certificate verification is enabled, False otherwise. Defaults to False
if the environment variable is not set.
Returns:
int: The default retention policy in days. Defaults to 0 if the environment variable is not set.

Spotted by Diamond

Is this helpful? React 👍 or 👎 to let us know.

fjcasti1 and others added 2 commits June 20, 2025 09:46
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Co-authored-by: sourcery-ai[bot] <58596630+sourcery-ai[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:S This PR changes 10-29 lines, ignoring generated files.
Projects
Status: 📘 Todo
Development

Successfully merging this pull request may close these issues.

1 participant
0