fix(traces): align consent semantics with framework, clarify enable message

This commit is contained in:
Greyson Lalonde
2026-05-05 05:18:25 +08:00
parent dc9e033571
commit b8c671042c
2 changed files with 11 additions and 10 deletions

View File

@@ -801,9 +801,10 @@ def traces_enable() -> None:
_save_user_data(user_data)
panel = Panel(
"✅ Trace collection has been enabled!\n\n"
"Your crew/flow executions will now send traces to CrewAI+.\n"
"Use 'crewai traces disable' to turn off trace collection.",
"✅ Trace consent recorded.\n\n"
"To activate trace collection, set [bold]CREWAI_TRACING_ENABLED=true[/bold] "
"in your environment or .env file.\n"
"Use 'crewai traces disable' to revoke consent.",
title="Traces Enabled",
border_style="green",
padding=(1, 2),

View File

@@ -58,14 +58,14 @@ def _save_user_data(data: dict[str, Any]) -> None:
def is_tracing_enabled() -> bool:
"""Check if tracing is enabled.
Returns True when the user has positively consented (e.g. via
``crewai traces enable``), False when they have declined, and falls back
to the ``CREWAI_TRACING_ENABLED`` env var when consent is unset.
Mirrors ``crewai.events.listeners.tracing.utils.is_tracing_enabled``:
consent only *blocks* tracing; activation requires
``CREWAI_TRACING_ENABLED=true``.
"""
data = _load_user_data()
trace_consent = data.get("trace_consent")
if trace_consent is True:
return True
if data.get("first_execution_done", False) and trace_consent is False:
if (
data.get("first_execution_done", False)
and data.get("trace_consent", False) is False
):
return False
return os.getenv("CREWAI_TRACING_ENABLED", "false").lower() == "true"