diff --git a/ultralytics/hub/utils.py b/ultralytics/hub/utils.py index 2fc956fb..469a1c37 100644 --- a/ultralytics/hub/utils.py +++ b/ultralytics/hub/utils.py @@ -170,7 +170,7 @@ def smart_request(method, url, retry=3, timeout=30, thread=True, code=-1, verbos class Events: """ A class for collecting anonymous event analytics. Event analytics are enabled when sync=True in settings and - disabled when sync=False. Run 'yolo settings' to see and update settings YAML file. + disabled when sync=False. Run 'yolo settings' to see and update settings. Attributes: url (str): The URL to send anonymous events. diff --git a/ultralytics/utils/__init__.py b/ultralytics/utils/__init__.py index e122d4b5..81d29781 100644 --- a/ultralytics/utils/__init__.py +++ b/ultralytics/utils/__init__.py @@ -971,7 +971,7 @@ def threaded(func): def set_sentry(): """ Initialize the Sentry SDK for error tracking and reporting. Only used if sentry_sdk package is installed and - sync=True in settings. Run 'yolo settings' to see and update settings YAML file. + sync=True in settings. Run 'yolo settings' to see and update settings. Conditions required to send errors (ALL conditions must be met or no errors will be reported): - sentry_sdk package is installed @@ -983,36 +983,11 @@ def set_sentry(): - online environment - CLI used to run package (checked with 'yolo' as the name of the main CLI command) - The function also configures Sentry SDK to ignore KeyboardInterrupt and FileNotFoundError - exceptions and to exclude events with 'out of memory' in their exception message. + The function also configures Sentry SDK to ignore KeyboardInterrupt and FileNotFoundError exceptions and to exclude + events with 'out of memory' in their exception message. Additionally, the function sets custom tags and user information for Sentry events. """ - - def before_send(event, hint): - """ - Modify the event before sending it to Sentry based on specific exception types and messages. - - Args: - event (dict): The event dictionary containing information about the error. - hint (dict): A dictionary containing additional information about the error. - - Returns: - dict: The modified event or None if the event should not be sent to Sentry. - """ - if "exc_info" in hint: - exc_type, exc_value, tb = hint["exc_info"] - if exc_type in {KeyboardInterrupt, FileNotFoundError} or "out of memory" in str(exc_value): - return None # do not send event - - event["tags"] = { - "sys_argv": ARGV[0], - "sys_argv_name": Path(ARGV[0]).name, - "install": "git" if IS_GIT_DIR else "pip" if IS_PIP_PACKAGE else "other", - "os": ENVIRONMENT, - } - return event - if ( SETTINGS["sync"] and RANK in {-1, 0} @@ -1028,8 +1003,32 @@ def set_sentry(): except ImportError: return + def before_send(event, hint): + """ + Modify the event before sending it to Sentry based on specific exception types and messages. + + Args: + event (dict): The event dictionary containing information about the error. + hint (dict): A dictionary containing additional information about the error. + + Returns: + dict: The modified event or None if the event should not be sent to Sentry. + """ + if "exc_info" in hint: + exc_type, exc_value, _ = hint["exc_info"] + if exc_type in {KeyboardInterrupt, FileNotFoundError} or "out of memory" in str(exc_value): + return None # do not send event + + event["tags"] = { + "sys_argv": ARGV[0], + "sys_argv_name": Path(ARGV[0]).name, + "install": "git" if IS_GIT_DIR else "pip" if IS_PIP_PACKAGE else "other", + "os": ENVIRONMENT, + } + return event + sentry_sdk.init( - dsn="https://5ff1556b71594bfea135ff0203a0d290@o4504521589325824.ingest.sentry.io/4504521592406016", + dsn="https://888e5a0778212e1d0314c37d4b9aae5d@o4504521589325824.ingest.us.sentry.io/4504521592406016", debug=False, traces_sample_rate=1.0, release=__version__, @@ -1170,25 +1169,26 @@ class SettingsManager(JSONDict): self.file = Path(file) self.version = version self.defaults = { - "settings_version": version, - "datasets_dir": str(datasets_root / "datasets"), - "weights_dir": str(root / "weights"), - "runs_dir": str(root / "runs"), - "uuid": hashlib.sha256(str(uuid.getnode()).encode()).hexdigest(), - "sync": True, - "api_key": "", - "openai_api_key": "", - "clearml": True, # integrations - "comet": True, - "dvc": True, - "hub": True, - "mlflow": True, - "neptune": True, - "raytune": True, - "tensorboard": True, - "wandb": True, - "vscode_msg": True, + "settings_version": version, # Settings schema version + "datasets_dir": str(datasets_root / "datasets"), # Datasets directory + "weights_dir": str(root / "weights"), # Model weights directory + "runs_dir": str(root / "runs"), # Experiment runs directory + "uuid": hashlib.sha256(str(uuid.getnode()).encode()).hexdigest(), # SHA-256 anonymized UUID hash + "sync": True, # Enable synchronization + "api_key": "", # Ultralytics API Key + "openai_api_key": "", # OpenAI API Key + "clearml": True, # ClearML integration + "comet": True, # Comet integration + "dvc": True, # DVC integration + "hub": True, # Ultralytics HUB integration + "mlflow": True, # MLflow integration + "neptune": True, # Neptune integration + "raytune": True, # Ray Tune integration + "tensorboard": True, # TensorBoard logging + "wandb": True, # Weights & Biases logging + "vscode_msg": True, # VSCode messaging } + self.help_msg = ( f"\nView Ultralytics Settings with 'yolo settings' or at '{self.file}'" "\nUpdate Settings with 'yolo settings key=value', i.e. 'yolo settings runs_dir=path/to/dir'. "