Repository navigation
fix(cli): register --no_capture_message_content option in argparse - #1969
todkarsant wants to merge 3 commits into
Conversation
The CLI config declared has_negation=True for capture_message_content but parse_arguments() only registered the positive --capture_message_content store_true action. Passing --no_capture_message_content caused argparse to exit with "unrecognized arguments". Register both the positive and negative forms in a mutually-exclusive group so that: - --no_capture_message_content is accepted and exports OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT=false - --capture_message_content still works as before - Specifying both flags together is rejected - When neither flag is given the env var is left untouched Fixes openlit#1962
Reviewer's GuideImplementationRegister mutually exclusive positive and negative capture flags, and export explicit boolean values while preserving environment-variable precedence.
DocumentationDocument the negative capture flag and clarify that either CLI form enables or disables content tracing.
TestsCover parsing, environment export, omitted flags, conflicting flags, and environment-variable precedence for capture-content options.
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
|
@AmanAgarwal041 Could you review this? Fixes the CLI --no_capture_message_content option that was declared (has_negation=True in config) but never registered in argparse. Thanks! |
PR Summary by QodoFix CLI support for disabling message content capture
AI Description
Merge Risk
|
Linked issuesChecked at commit 006a61b #1962 Bug: Python CLI rejects configured --no_capture_message_content option · 3 of 3 met
|
There was a problem hiding this comment.
Hey - I've found 2 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="sdk/python/src/openlit/cli/main.py" line_range="131-136" />
<code_context>
+ # For has_negation params the argparse default is None, so
+ # reaching here with False means the user explicitly passed
+ # the --no_<flag> form and we must honour it.
+ if (
+ cli_value is False
+ and config.get("default") is True
+ and not config.get("has_negation")
+ ):
continue
os.environ[env_var] = "true" if cli_value else "false"
else:
</code_context>
<issue_to_address>
**Empty setting re-enables content capture**
When the CLI is invoked with `--no_capture_message_content` while `OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT` is present but empty, `set_environment_from_cli_args` skips exporting `false` because the variable exists, while `build_config_from_environment` ignores its empty value and `openlit.init` retains the default `True`; message content is captured despite the explicit opt-out.
Treat an empty environment value as unset for CLI precedence, or otherwise ensure it cannot restore the default capture behavior after an explicit opt-out.
</issue_to_address>
### Comment 2
<location path="sdk/python/src/openlit/cli/main.py" line_range="72" />
<code_context>
+ # enable or disable the behaviour. Using a mutually-exclusive
+ # group means argparse will reject contradictory combos like
+ # ``--capture_message_content --no_capture_message_content``.
+ neg_arg = f"--no_{param_name}"
+ neg_help = (
+ f"Disable {config.get('cli_help', '').lower()} "
</code_context>
<issue_to_address>
**Disable option is undocumented**
When a user consults the configuration docs to disable content capture from the CLI, the configuration docs list only `--capture_message_content`, so users looking for a CLI way to disable content capture cannot discover the new negative option.
Document `--no_capture_message_content` in the SDK configuration docs.
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: sdk/python/src/openlit/cli/main.py:136
Code Review by Qodo🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)
Great, no issues found!Qodo reviewed your code and found no material issues that require reviewTip of the day💡 Did you know, you can describe a rule in plain language on the Rules page and Qodo drafts it for you |
When OTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENT was present but empty, the CLI skipped exporting 'false' for --no_capture_message_content because the variable technically existed. The empty value was then ignored downstream, silently re-enabling content capture.
|
Addressed the Sourcery finding in 292293c: When Fixed by treating an empty env var as unset: Re the docs comment: the |
Restrict the empty-environment-variable-as-unset logic to boolean parameters with a has_negation variant. Previously all env vars were affected, which could let CLI args silently overwrite an intentionally empty setting. Also document --no_capture_message_content in the SDK configuration table.
Preview approval requiredThis pull request comes from a fork, so Mintlify won't build a preview until someone with write access approves commit |
Fixes #1962
Summary
--no_capture_message_contentas astore_falseaction alongside the existing--capture_message_contentstore_truein a mutually-exclusive argparse group--no_capture_message_contentis passed andOTEL_INSTRUMENTATION_GENAI_CAPTURE_MESSAGE_CONTENTis not already set, exportfalseto the launched process--capture_message_contentand--no_capture_message_contenttogetherSummary by Sourcery
Allow the CLI to explicitly enable or disable message-content capture without changing existing defaults or environment precedence.
New Features:
--no_capture_message_contentsupport alongside the existing positive flag.Bug Fixes:
falsewhile preserving existing environment-variable precedence and default behavior.Enhancements:
Documentation:
Tests: