From 38246c9e2850a5171fb6c8f612e03426609e2778 Mon Sep 17 00:00:00 2001 From: Hemant Mishra Date: Fri, 16 Jan 2026 17:17:09 +0530 Subject: [PATCH] Improve Error logging --- CHANGELOG.md | 6 ++++++ cognite/extractorutils/__init__.py | 2 +- cognite/extractorutils/unstable/core/base.py | 4 ++-- cognite/extractorutils/unstable/core/checkin_worker.py | 2 +- cognite/extractorutils/unstable/core/runtime.py | 1 + pyproject.toml | 2 +- tests/test_unstable/test_errors.py | 2 +- 7 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4d2cc27..97edbc85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,12 @@ Changes are grouped as follows - `Security` in case of vulnerabilities. +## 7.11.4 + +### Fixed +* In the `unstable` package: Improved error logging and error messages when config revision changes are detected + + ## 7.11.3 ### Fixed diff --git a/cognite/extractorutils/__init__.py b/cognite/extractorutils/__init__.py index 0e9eb81f..5c5bbebb 100644 --- a/cognite/extractorutils/__init__.py +++ b/cognite/extractorutils/__init__.py @@ -16,7 +16,7 @@ Cognite extractor utils is a Python package that simplifies the development of new extractors. """ -__version__ = "7.11.3" +__version__ = "7.11.4" from .base import Extractor __all__ = ["Extractor"] diff --git a/cognite/extractorutils/unstable/core/base.py b/cognite/extractorutils/unstable/core/base.py index 9befd387..977e3ca4 100644 --- a/cognite/extractorutils/unstable/core/base.py +++ b/cognite/extractorutils/unstable/core/base.py @@ -427,9 +427,9 @@ def run_task(task_context: TaskContext) -> None: target(task_context) except Exception as e: - # Task crashed, record it as a fatal error + # Task failed, record it as a fatal error task_context.exception( - f"Task {task.name} crashed unexpectedly", + f"Task {task.name} failed unexpectedly", e, level=ErrorLevel.fatal, ) diff --git a/cognite/extractorutils/unstable/core/checkin_worker.py b/cognite/extractorutils/unstable/core/checkin_worker.py index 8a01c27c..2b83ecf7 100644 --- a/cognite/extractorutils/unstable/core/checkin_worker.py +++ b/cognite/extractorutils/unstable/core/checkin_worker.py @@ -195,7 +195,6 @@ def _handle_checkin_response(self, response: JSONType) -> None: "and configured to use remote config for the new config to take effect.", ) elif self._active_revision < checkin_response.last_config_revision: - self._active_revision = checkin_response.last_config_revision if self._on_revision_change is not None: self._logger.info( "Remote config revision changed %s -> %s. The extractor will now use the new configuration.", @@ -203,6 +202,7 @@ def _handle_checkin_response(self, response: JSONType) -> None: checkin_response.last_config_revision, ) self._on_revision_change(checkin_response.last_config_revision) + self._active_revision = checkin_response.last_config_revision def flush(self, cancellation_token: CancellationToken) -> None: """ diff --git a/cognite/extractorutils/unstable/core/runtime.py b/cognite/extractorutils/unstable/core/runtime.py index 52b78bfc..30d7d2fa 100644 --- a/cognite/extractorutils/unstable/core/runtime.py +++ b/cognite/extractorutils/unstable/core/runtime.py @@ -337,6 +337,7 @@ def _safe_get_application_config( # Same error as before, no need to log it again self._cancellation_token.wait(randint(1, self.RETRY_CONFIG_INTERVAL)) continue + self.logger.error(error_message) prev_error = error_message ts = now() diff --git a/pyproject.toml b/pyproject.toml index 14d6d58c..6beead78 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "cognite-extractor-utils" -version = "7.11.3" +version = "7.11.4" description = "Utilities for easier development of extractors for CDF" authors = [ {name = "Mathias Lohne", email = "mathias.lohne@cognite.com"} diff --git a/tests/test_unstable/test_errors.py b/tests/test_unstable/test_errors.py index 09c34e65..6654d4bf 100644 --- a/tests/test_unstable/test_errors.py +++ b/tests/test_unstable/test_errors.py @@ -177,7 +177,7 @@ def task(_tc: TaskContext) -> None: assert len(worker._errors) == 1 error = next(iter(worker._errors.values())) - assert error.description == "Task TestTask crashed unexpectedly" + assert error.description == "Task TestTask failed unexpectedly" assert error.level == ErrorLevel.fatal # Make sure error was recorded as a task error