mirror of
https://github.com/khoj-ai/khoj.git
synced 2024-11-23 15:38:55 +01:00
Allow disabling Khoj telemetry via KHOJ_TELEMETRY_DISABLE env var
This commit is contained in:
parent
dc109559d4
commit
e1d0015248
7 changed files with 27 additions and 17 deletions
|
@ -61,6 +61,10 @@ services:
|
|||
# - KHOJ_NO_HTTPS=True
|
||||
# - KHOJ_DOMAIN=192.168.0.104
|
||||
# - KHOJ_DOMAIN=khoj.example.com
|
||||
# Uncomment the line below to disable telemetry.
|
||||
# Telemetry helps us prioritize feature development and understand how people are using Khoj
|
||||
# Read more at https://docs.khoj.dev/miscellaneous/telemetry
|
||||
# - KHOJ_TELEMETRY_DISABLE=True
|
||||
command: --host="0.0.0.0" --port=42110 -vv --anonymous-mode --non-interactive
|
||||
|
||||
|
||||
|
|
|
@ -14,13 +14,6 @@ We don't send any personal information or any information from/about your conten
|
|||
|
||||
## Disable Telemetry
|
||||
|
||||
If you're self-hosting Khoj, you can opt out of telemetry at any time. To do so,
|
||||
1. Open `~/.khoj/khoj.yml`
|
||||
2. Add the following configuration:
|
||||
```
|
||||
app:
|
||||
should-log-telemetry: false
|
||||
```
|
||||
3. Save the file and restart Khoj
|
||||
If you're self-hosting Khoj, you can opt out of telemetry at any time by setting the `KHOJ_TELEMETRY_DISABLE` environment variable to `True` via shell or `docker-compose.yml`
|
||||
|
||||
If you have any questions or concerns, please reach out to us on [Discord](https://discord.gg/BDgyabRM6e).
|
||||
|
|
|
@ -249,7 +249,11 @@ def configure_server(
|
|||
state.search_models = configure_search(state.search_models, state.config.search_type)
|
||||
setup_default_agent(user)
|
||||
|
||||
message = "📡 Telemetry disabled" if telemetry_disabled(state.config.app) else "📡 Telemetry enabled"
|
||||
message = (
|
||||
"📡 Telemetry disabled"
|
||||
if telemetry_disabled(state.config.app, state.telemetry_disabled)
|
||||
else "📡 Telemetry enabled"
|
||||
)
|
||||
logger.info(message)
|
||||
|
||||
if not init:
|
||||
|
@ -361,7 +365,7 @@ def configure_search_types():
|
|||
|
||||
@schedule.repeat(schedule.every(2).minutes)
|
||||
def upload_telemetry():
|
||||
if telemetry_disabled(state.config.app) or not state.telemetry:
|
||||
if telemetry_disabled(state.config.app, state.telemetry_disabled) or not state.telemetry:
|
||||
return
|
||||
|
||||
try:
|
||||
|
|
|
@ -204,7 +204,12 @@ def update_telemetry_state(
|
|||
|
||||
state.telemetry += [
|
||||
log_telemetry(
|
||||
telemetry_type=telemetry_type, api=api, client=client, app_config=state.config.app, properties=user_state
|
||||
telemetry_type=telemetry_type,
|
||||
api=api,
|
||||
client=client,
|
||||
app_config=state.config.app,
|
||||
disable_telemetry_env=state.telemetry_disabled,
|
||||
properties=user_state,
|
||||
)
|
||||
]
|
||||
|
||||
|
|
|
@ -16,7 +16,7 @@ from khoj.migrations.migrate_processor_config_openai import (
|
|||
)
|
||||
from khoj.migrations.migrate_server_pg import migrate_server_pg
|
||||
from khoj.migrations.migrate_version import migrate_config_to_version
|
||||
from khoj.utils.helpers import in_debug_mode, resolve_absolute_path
|
||||
from khoj.utils.helpers import in_debug_mode, is_env_var_true, resolve_absolute_path
|
||||
from khoj.utils.yaml import parse_config_from_file
|
||||
|
||||
|
||||
|
@ -79,7 +79,7 @@ def cli(args=None):
|
|||
else:
|
||||
args = run_migrations(args)
|
||||
args.config = parse_config_from_file(args.config_file)
|
||||
if in_debug_mode():
|
||||
if is_env_var_true("KHOJ_TELEMETRY_DISABLE") or in_debug_mode():
|
||||
args.config.app.should_log_telemetry = False
|
||||
|
||||
return args
|
||||
|
|
|
@ -254,8 +254,10 @@ def get_server_id():
|
|||
return server_id
|
||||
|
||||
|
||||
def telemetry_disabled(app_config: AppConfig):
|
||||
return not app_config or not app_config.should_log_telemetry
|
||||
def telemetry_disabled(app_config: AppConfig, telemetry_disable_env) -> bool:
|
||||
return (
|
||||
not app_config.should_log_telemetry if app_config and app_config.should_log_telemetry else telemetry_disable_env
|
||||
)
|
||||
|
||||
|
||||
def log_telemetry(
|
||||
|
@ -263,11 +265,12 @@ def log_telemetry(
|
|||
api: str = None,
|
||||
client: Optional[str] = None,
|
||||
app_config: Optional[AppConfig] = None,
|
||||
disable_telemetry_env: bool = False,
|
||||
properties: dict = None,
|
||||
):
|
||||
"""Log basic app usage telemetry like client, os, api called"""
|
||||
# Do not log usage telemetry, if telemetry is disabled via app config
|
||||
if telemetry_disabled(app_config):
|
||||
if telemetry_disabled(app_config, disable_telemetry_env):
|
||||
return []
|
||||
|
||||
if properties.get("server_id") is None:
|
||||
|
|
|
@ -12,7 +12,7 @@ from khoj.database.models import ProcessLock
|
|||
from khoj.processor.embeddings import CrossEncoderModel, EmbeddingsModel
|
||||
from khoj.utils import config as utils_config
|
||||
from khoj.utils.config import OfflineChatProcessorModel, SearchModels
|
||||
from khoj.utils.helpers import LRU, get_device
|
||||
from khoj.utils.helpers import LRU, get_device, is_env_var_true
|
||||
from khoj.utils.rawconfig import FullConfig
|
||||
|
||||
# Application Global State
|
||||
|
@ -34,6 +34,7 @@ SearchType = utils_config.SearchType
|
|||
scheduler: BackgroundScheduler = None
|
||||
schedule_leader_process_lock: ProcessLock = None
|
||||
telemetry: List[Dict[str, str]] = []
|
||||
telemetry_disabled: bool = is_env_var_true("KHOJ_TELEMETRY_DISABLE")
|
||||
khoj_version: str = None
|
||||
device = get_device()
|
||||
chat_on_gpu: bool = True
|
||||
|
|
Loading…
Reference in a new issue