Python: Disable mem0 telemetry by default (#3506)

* disable mem0 telemetry by default

* test fix

* addressed comments
This commit is contained in:
Giles Odigwe
2026-01-30 13:17:52 -08:00
committed by GitHub
Unverified
parent 8b475afe17
commit f3e0be9555
4 changed files with 67 additions and 1 deletions
@@ -1,6 +1,9 @@
# Copyright (c) Microsoft. All rights reserved.
# pyright: reportPrivateUsage=false
import importlib
import os
import sys
from unittest.mock import AsyncMock, patch
import pytest
@@ -592,3 +595,43 @@ class TestMem0ProviderBuildFilters:
filters = provider._build_filters()
assert filters == {}
class TestMem0Telemetry:
"""Test telemetry configuration for Mem0."""
def test_mem0_telemetry_disabled_by_default(self, monkeypatch: pytest.MonkeyPatch) -> None:
"""Test that MEM0_TELEMETRY is set to 'false' by default when importing the package."""
# Ensure MEM0_TELEMETRY is not set before importing the module under test
monkeypatch.delenv("MEM0_TELEMETRY", raising=False)
# Remove cached modules to force re-import and trigger module-level initialization
modules_to_remove = [key for key in sys.modules if key.startswith("agent_framework_mem0")]
for mod in modules_to_remove:
del sys.modules[mod]
# Import (and reload) the module so that it can set MEM0_TELEMETRY when unset
import agent_framework_mem0
importlib.reload(agent_framework_mem0)
# The environment variable should be set to "false" after importing
assert os.environ.get("MEM0_TELEMETRY") == "false"
def test_mem0_telemetry_respects_user_setting(self, monkeypatch: pytest.MonkeyPatch) -> None:
"""Test that user-set MEM0_TELEMETRY value is not overwritten."""
# Remove cached modules to force re-import
modules_to_remove = [key for key in sys.modules if key.startswith("agent_framework_mem0")]
for mod in modules_to_remove:
del sys.modules[mod]
# Set user preference before import
monkeypatch.setenv("MEM0_TELEMETRY", "true")
# Re-import the module
import agent_framework_mem0
importlib.reload(agent_framework_mem0)
# User setting should be preserved
assert os.environ.get("MEM0_TELEMETRY") == "true"