From 2e6ee5d61eb1ab2542cc20a44a9832e9407302fa Mon Sep 17 00:00:00 2001 From: hajdul88 <52442977+hajdul88@users.noreply.github.com> Date: Mon, 27 Oct 2025 16:38:23 +0100 Subject: [PATCH] feature: adds new tenant id (if available) to telemetry packages for basic cognee operations (#1676) ## Description Adds new tenant id (if available) to telemetry packages for basic cognee operations ## Type of Change - [ ] Bug fix (non-breaking change that fixes an issue) - [ ] New feature (non-breaking change that adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to change) - [ ] Documentation update - [x] Code refactoring - [ ] Performance improvement - [ ] Other (please specify): ## Screenshots/Videos (if applicable) ## Pre-submission Checklist - [x] **I have tested my changes thoroughly before submitting this PR** - [x] **This PR contains minimal changes necessary to address the issue/feature** - [x] My code follows the project's coding standards and style guidelines - [x] I have added tests that prove my fix is effective or that my feature works - [x] I have added necessary documentation (if applicable) - [x] All new and existing tests pass - [x] I have searched existing PRs to ensure this change hasn't been submitted already - [x] I have linked any relevant issues in the description - [x] My commits have clear and descriptive messages ## DCO Affirmation I affirm that all code in every commit of this pull request conforms to the terms of the Topoteretes Developer Certificate of Origin. --- cognee/modules/pipelines/operations/run_tasks_base.py | 3 +++ .../pipelines/operations/run_tasks_with_telemetry.py | 3 +++ cognee/modules/search/methods/search.py | 10 ++++++++-- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/cognee/modules/pipelines/operations/run_tasks_base.py b/cognee/modules/pipelines/operations/run_tasks_base.py index ee2ccfd8c..79d37a451 100644 --- a/cognee/modules/pipelines/operations/run_tasks_base.py +++ b/cognee/modules/pipelines/operations/run_tasks_base.py @@ -27,6 +27,7 @@ async def handle_task( additional_properties={ "task_name": running_task.executable.__name__, "cognee_version": cognee_version, + "tenant_id": str(user.tenant_id) if user.tenant_id else "Single User Tenant", }, ) @@ -49,6 +50,7 @@ async def handle_task( additional_properties={ "task_name": running_task.executable.__name__, "cognee_version": cognee_version, + "tenant_id": str(user.tenant_id) if user.tenant_id else "Single User Tenant", }, ) except Exception as error: @@ -62,6 +64,7 @@ async def handle_task( additional_properties={ "task_name": running_task.executable.__name__, "cognee_version": cognee_version, + "tenant_id": str(user.tenant_id) if user.tenant_id else "Single User Tenant", }, ) raise error diff --git a/cognee/modules/pipelines/operations/run_tasks_with_telemetry.py b/cognee/modules/pipelines/operations/run_tasks_with_telemetry.py index 9a52bf854..ae968c7a5 100644 --- a/cognee/modules/pipelines/operations/run_tasks_with_telemetry.py +++ b/cognee/modules/pipelines/operations/run_tasks_with_telemetry.py @@ -28,6 +28,7 @@ async def run_tasks_with_telemetry( additional_properties={ "pipeline_name": str(pipeline_name), "cognee_version": cognee_version, + "tenant_id": str(user.tenant_id) if user.tenant_id else "Single User Tenant", } | config, ) @@ -42,6 +43,7 @@ async def run_tasks_with_telemetry( additional_properties={ "pipeline_name": str(pipeline_name), "cognee_version": cognee_version, + "tenant_id": str(user.tenant_id) if user.tenant_id else "Single User Tenant", } | config, ) @@ -58,6 +60,7 @@ async def run_tasks_with_telemetry( additional_properties={ "pipeline_name": str(pipeline_name), "cognee_version": cognee_version, + "tenant_id": str(user.tenant_id) if user.tenant_id else "Single User Tenant", } | config, ) diff --git a/cognee/modules/search/methods/search.py b/cognee/modules/search/methods/search.py index 93c0ef5c8..aab004924 100644 --- a/cognee/modules/search/methods/search.py +++ b/cognee/modules/search/methods/search.py @@ -67,7 +67,10 @@ async def search( send_telemetry( "cognee.search EXECUTION STARTED", user.id, - additional_properties={"cognee_version": cognee_version}, + additional_properties={ + "cognee_version": cognee_version, + "tenant_id": str(user.tenant_id) if user.tenant_id else "Single User Tenant", + }, ) # Use search function filtered by permissions if access control is enabled @@ -108,7 +111,10 @@ async def search( send_telemetry( "cognee.search EXECUTION COMPLETED", user.id, - additional_properties={"cognee_version": cognee_version}, + additional_properties={ + "cognee_version": cognee_version, + "tenant_id": str(user.tenant_id) if user.tenant_id else "Single User Tenant", + }, ) await log_result(