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
+11
View File
@@ -18,3 +18,14 @@ See the [Mem0 basic example](https://github.com/microsoft/agent-framework/tree/m
- Teaching the agent user preferences
- Retrieving information using remembered context across new threads
- Persistent memory
## Telemetry
Mem0's telemetry is **disabled by default** when using this package. If you want to enable telemetry, set the environment variable before importing:
```python
import os
os.environ["MEM0_TELEMETRY"] = "true"
from agent_framework.mem0 import Mem0Provider
```
@@ -1,6 +1,12 @@
# Copyright (c) Microsoft. All rights reserved.
import importlib.metadata
import os
# Disable Mem0 telemetry by default to prevent usage data from being sent to telemetry provider.
# Users can opt-in by setting MEM0_TELEMETRY=true before importing this package.
if os.environ.get("MEM0_TELEMETRY") is None:
os.environ["MEM0_TELEMETRY"] = "false"
from ._provider import Mem0Provider
@@ -30,7 +30,13 @@ MemorySearchResponse_v2 = list[dict[str, Any]]
class Mem0Provider(ContextProvider):
"""Mem0 Context Provider."""
"""Mem0 Context Provider.
Note:
Mem0's telemetry is disabled by default when using this package.
To enable telemetry, set the environment variable ``MEM0_TELEMETRY=true`` before
importing this package.
"""
def __init__(
self,
@@ -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"