Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/rapidata/rapidata_client/api/rapidata_api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ def _should_suppress_error_logging() -> bool:
return getattr(_thread_local, "suppress_error_logging", False)


@contextmanager
def optional_api_call(description: str):
"""Mark a block as non-critical / best-effort.

Inside the block:
- RapidataApiClient errors are logged at DEBUG instead of ERROR
(via suppress_rapidata_error_logging).
- Any exception that escapes the block is caught and logged at
DEBUG as well. The caller never sees it.

Use for best-effort calls like version checks, telemetry, or
feature-flag lookups where failure must not impact the user.
"""
with suppress_rapidata_error_logging():
try:
yield
except Exception as e:
logger.debug("Optional call '%s' failed: %s", description, e)


class RapidataApiClient(ApiClient):
"""Custom API client that wraps errors in RapidataError."""

Expand Down
9 changes: 3 additions & 6 deletions src/rapidata/rapidata_client/rapidata_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from rapidata.rapidata_client.datapoints._asset_uploader import AssetUploader
from rapidata.rapidata_client.job.rapidata_job_manager import RapidataJobManager
from rapidata.rapidata_client.flow.rapidata_flow_manager import RapidataFlowManager
from rapidata.rapidata_client.api.rapidata_api_client import optional_api_call


class RapidataClient:
Expand Down Expand Up @@ -130,7 +131,7 @@ def clear_all_caches(self):

def _check_beta_features(self):
"""Enable beta features for the client."""
try:
with optional_api_call("check beta features"):
with tracer.start_as_current_span("RapidataClient.check_beta_features"):
result: dict[str, Any] = json.loads(
self._openapi_service.api_client.call_api(
Expand All @@ -154,11 +155,9 @@ def _check_beta_features(self):

logger.debug("User is an admin, enabling beta features")
rapidata_config.enableBetaFeatures = True
except Exception as e:
logger.debug("Failed to check beta features: %s", e)

def _check_version(self):
try:
with optional_api_call("version check"):
response = requests.get(
"https://api.github.com/repos/RapidataAI/rapidata-python-sdk/releases/latest",
headers={"Accept": "application/vnd.github.v3+json"},
Expand All @@ -175,8 +174,6 @@ def _check_version(self):
logger.debug(
"Current version is up to date. Version: %s", __version__
)
except Exception as e:
logger.debug("Failed to check for updates: %s", e)

def __str__(self) -> str:
return f"RapidataClient(environment={self._openapi_service.environment})"
Expand Down
Loading