diff --git a/src/sap_cloud_sdk/agentgateway/agw_client.py b/src/sap_cloud_sdk/agentgateway/agw_client.py index efa178b7..349fb740 100644 --- a/src/sap_cloud_sdk/agentgateway/agw_client.py +++ b/src/sap_cloud_sdk/agentgateway/agw_client.py @@ -38,7 +38,7 @@ ) from sap_cloud_sdk.agentgateway._token_cache import _GatewayUrlCache, _TokenCache from sap_cloud_sdk.agentgateway.exceptions import AgentGatewaySDKError -from sap_cloud_sdk.core._telemetry_compat import Module, Operation, record_metrics +from sap_cloud_sdk.core.telemetry import Module, Operation, record_metrics logger = logging.getLogger(__name__) diff --git a/src/sap_cloud_sdk/core/_telemetry_compat.py b/src/sap_cloud_sdk/core/_telemetry_compat.py deleted file mode 100644 index 962a03cd..00000000 --- a/src/sap_cloud_sdk/core/_telemetry_compat.py +++ /dev/null @@ -1,31 +0,0 @@ -"""Conditional telemetry imports for modules that use telemetry as optional dependency. - -This module provides a centralized way to handle optional telemetry dependencies. -When telemetry packages are not installed, it provides no-op implementations. -""" - -from typing import Any, Callable, TypeVar - -_F = TypeVar("_F", bound=Callable[..., Any]) - -try: - from sap_cloud_sdk.core.telemetry import Module, Operation, record_metrics - TELEMETRY_AVAILABLE = True -except ImportError: - # Telemetry packages not installed — provide no-op implementations - TELEMETRY_AVAILABLE = False - Module = None # type: ignore - Operation = None # type: ignore - - def record_metrics(*args: Any, **kwargs: Any) -> Any: # type: ignore - """No-op decorator when telemetry is not available.""" - def decorator(func: _F) -> _F: - return func - if args and callable(args[0]): - # Called without parentheses: @record_metrics - return args[0] - # Called with parentheses: @record_metrics(...) - return decorator - - -__all__ = ["Module", "Operation", "record_metrics", "TELEMETRY_AVAILABLE"] diff --git a/src/sap_cloud_sdk/destination/certificate_client.py b/src/sap_cloud_sdk/destination/certificate_client.py index 99591198..de7589c6 100644 --- a/src/sap_cloud_sdk/destination/certificate_client.py +++ b/src/sap_cloud_sdk/destination/certificate_client.py @@ -4,7 +4,7 @@ from typing import List, Optional, TypeVar, Callable -from sap_cloud_sdk.core._telemetry_compat import Module, Operation, record_metrics +from sap_cloud_sdk.core.telemetry import Module, Operation, record_metrics from sap_cloud_sdk.destination._http import DestinationHttp, API_V1 from sap_cloud_sdk.destination._models import ( AccessStrategy, diff --git a/src/sap_cloud_sdk/destination/client.py b/src/sap_cloud_sdk/destination/client.py index 4339de33..d4ffd3e0 100644 --- a/src/sap_cloud_sdk/destination/client.py +++ b/src/sap_cloud_sdk/destination/client.py @@ -6,9 +6,7 @@ import warnings from typing import Any, Dict, List, Optional, Callable, TypeVar -# Conditional telemetry import - works even when telemetry packages are not installed -from sap_cloud_sdk.core._telemetry_compat import Module, Operation, record_metrics - +from sap_cloud_sdk.core.telemetry import Module, Operation, record_metrics from sap_cloud_sdk.core.secret_resolver import read_from_mount_and_fallback_to_env_var from sap_cloud_sdk.destination._http import DestinationHttp, API_V1, API_V2 from sap_cloud_sdk.destination._models import ( diff --git a/src/sap_cloud_sdk/destination/fragment_client.py b/src/sap_cloud_sdk/destination/fragment_client.py index a6eed88f..bd870ef9 100644 --- a/src/sap_cloud_sdk/destination/fragment_client.py +++ b/src/sap_cloud_sdk/destination/fragment_client.py @@ -4,7 +4,7 @@ from typing import Callable, List, Optional, TypeVar -from sap_cloud_sdk.core._telemetry_compat import Module, Operation, record_metrics +from sap_cloud_sdk.core.telemetry import Module, Operation, record_metrics from sap_cloud_sdk.destination._http import DestinationHttp, API_V1 from sap_cloud_sdk.destination._models import ( AccessStrategy, diff --git a/tests/agentgateway/unit/test_lob.py b/tests/agentgateway/unit/test_lob.py index 5ec781c5..53b1c34f 100644 --- a/tests/agentgateway/unit/test_lob.py +++ b/tests/agentgateway/unit/test_lob.py @@ -28,8 +28,9 @@ from sap_cloud_sdk.agentgateway._models import Agent, AgentCard, MCPTool from sap_cloud_sdk.agentgateway._token_cache import _GatewayUrlCache, _TokenCache from sap_cloud_sdk.agentgateway.config import ClientConfig +from sap_cloud_sdk.destination import ConsumptionOptions, ConsumptionLevel from sap_cloud_sdk.agentgateway.exceptions import AgentGatewaySDKError, MCPServerNotFoundError -from sap_cloud_sdk.destination import ConsumptionLevel, ConsumptionOptions +from sap_cloud_sdk.destination import ConsumptionLevel # Aliases for use in existing test assertions _LABEL_KEY = LABEL_KEY @@ -1065,4 +1066,3 @@ def test_raises_when_landscape_env_not_set(self): with patch("sap_cloud_sdk.agentgateway._lob._ias_dest_name", side_effect=EnvironmentError("APPFND_CONHOS_LANDSCAPE not set")): with pytest.raises(EnvironmentError, match="APPFND_CONHOS_LANDSCAPE"): get_ias_client_id_lob() -