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
109 changes: 23 additions & 86 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ dependencies = [
"python-dotenv",
"scikit-learn",
"seaborn",
"sentry-sdk (>=1.24.0,<2.0.0)",
"tabulate (>=0.9.0,<0.10.0)",
"tiktoken",
"tqdm",
Expand Down
13 changes: 3 additions & 10 deletions validmind/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

from .client_config import client_config
from .errors import MissingAPICredentialsError, MissingModelIdError, raise_api_error
from .logging import get_logger, init_sentry, log_api_operation, send_single_error
from .logging import get_logger, log_api_operation
from .utils import NumpyEncoder, is_html, md_to_html, run_async
from .vm_models.figure import Figure

Expand Down Expand Up @@ -166,7 +166,7 @@ def _ping() -> Dict[str, Any]:

client_info = r.json()

init_sentry(client_info.get("sentry_config", {}))
# Sentry removed: no telemetry initialization

# Only show this confirmation the first time we connect to the API
ack_connected = not client_config.model
Expand Down Expand Up @@ -244,14 +244,7 @@ def init(

def reload():
"""Reconnect to the ValidMind API and reload the project configuration."""

try:
_ping()
except Exception as e:
# if the api host is https, assume we're not in dev mode and send to sentry
if _api_host.startswith("https://"):
send_single_error(e)
raise e
_ping()


async def aget_metadata(content_id: str) -> Dict[str, Any]:
Expand Down
61 changes: 1 addition & 60 deletions validmind/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,7 @@
import logging
import os
import time
from typing import Any, Awaitable, Callable, Dict, Optional, TypeVar

import sentry_sdk
from sentry_sdk.utils import event_from_exception, exc_info_from_error

from .__version__ import __version__

__dsn = "https://48f446843657444aa1e2c0d716ef864b@o1241367.ingest.sentry.io/4505239625465856"
from typing import Any, Awaitable, Callable, Optional, TypeVar


def _get_log_level() -> int:
Expand Down Expand Up @@ -55,45 +48,6 @@ def get_logger(
return logger


def init_sentry(server_config: Dict[str, Any]) -> None:
"""Initialize Sentry SDK for sending logs back to ValidMind.

This will usually only be called by the API client module to initialize the
Sentry connection after the user calls `validmind.init()`. This is because the DSN
and other config options will be returned by the API.

Args:
server_config (Dict[str, Any]): The config dictionary returned by the API.
- send_logs (bool): Whether to send logs to Sentry (gets removed).
- dsn (str): The Sentry DSN.
...: Other config options for Sentry.

Returns:
None.
"""
if os.getenv("VM_NO_TELEMETRY", False):
return

if not server_config.get("send_logs", False):
return

config = {
"dsn": __dsn,
"traces_sample_rate": 1.0,
"release": f"validmind-python@{__version__}",
"in_app_include": ["validmind"],
"environment": "production",
}
config.update({k: v for k, v in server_config.items() if k != "send_logs"})

try:
sentry_sdk.init(**config)
except Exception as e:
logger = get_logger(__name__)
logger.info("Sentry failed to initialize - ignoring...")
logger.debug(f"Sentry error: {str(e)}")


F = TypeVar("F", bound=Callable[..., Any])
AF = TypeVar("AF", bound=Callable[..., Awaitable[Any]])

Expand Down Expand Up @@ -216,16 +170,3 @@ async def wrapped(*args: Any, **kwargs: Any) -> Any:
return wrapped

return decorator


def send_single_error(error: Exception) -> None:
"""Send a single error to Sentry.

Args:
error (Exception): The exception to send.
"""
event, hint = event_from_exception(exc_info_from_error(error))
client = sentry_sdk.Client(__dsn, release=f"validmind-python@{__version__}")
client.capture_event(event, hint=hint)

time.sleep(0.25) # wait for the event to be sent
Loading