Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7123297
D8430.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Subscribers
None
D8430.diff
View Options
diff --git a/swh/loader/core/loader.py b/swh/loader/core/loader.py
--- a/swh/loader/core/loader.py
+++ b/swh/loader/core/loader.py
@@ -38,6 +38,9 @@
"max_content_size": 100 * 1024 * 1024,
}
+SENTRY_ORIGIN_URL_TAG_NAME = "swh.loader.origin_url"
+SENTRY_VISIT_TYPE_TAG_NAME = "swh.loader.visit_type"
+
class BaseLoader:
"""Base class for (D)VCS loaders (e.g Svn, Git, Mercurial, ...) or PackageLoader (e.g
@@ -116,6 +119,9 @@
_log = logging.getLogger("requests.packages.urllib3.connectionpool")
_log.setLevel(logging.WARN)
+ sentry_sdk.set_tag(SENTRY_ORIGIN_URL_TAG_NAME, self.origin.url)
+ sentry_sdk.set_tag(SENTRY_VISIT_TYPE_TAG_NAME, self.visit_type)
+
# possibly overridden in self.prepare method
self.visit_date = datetime.datetime.now(tz=datetime.timezone.utc)
diff --git a/swh/loader/core/tests/test_loader.py b/swh/loader/core/tests/test_loader.py
--- a/swh/loader/core/tests/test_loader.py
+++ b/swh/loader/core/tests/test_loader.py
@@ -11,7 +11,12 @@
import pytest
-from swh.loader.core.loader import BaseLoader, DVCSLoader
+from swh.loader.core.loader import (
+ SENTRY_ORIGIN_URL_TAG_NAME,
+ SENTRY_VISIT_TYPE_TAG_NAME,
+ BaseLoader,
+ DVCSLoader,
+)
from swh.loader.core.metadata_fetchers import MetadataFetcherProtocol
from swh.loader.exception import NotFound
from swh.loader.tests import assert_last_visit_matches
@@ -479,3 +484,22 @@
assert result == {"status": "uneventful"}
_check_load_failure(caplog, loader, NotFound, "Unknown origin!", status="not_found")
+
+
+class DummyLoaderWithError(DummyBaseLoader):
+ def prepare(self, *args, **kwargs):
+ raise Exception("error")
+
+
+class DummyDVCSLoaderWithError(DummyDVCSLoader, BaseLoader):
+ def prepare(self, *args, **kwargs):
+ raise Exception("error")
+
+
+@pytest.mark.parametrize("loader_cls", [DummyLoaderWithError, DummyDVCSLoaderWithError])
+def test_loader_sentry_tags_on_error(swh_storage, sentry_events, loader_cls):
+ loader = loader_cls(swh_storage)
+ loader.load()
+ sentry_tags = sentry_events[0]["tags"]
+ assert sentry_tags.get(SENTRY_ORIGIN_URL_TAG_NAME) == ORIGIN.url
+ assert sentry_tags.get(SENTRY_VISIT_TYPE_TAG_NAME) == DummyLoader.visit_type
diff --git a/swh/loader/package/tests/test_loader.py b/swh/loader/package/tests/test_loader.py
--- a/swh/loader/package/tests/test_loader.py
+++ b/swh/loader/package/tests/test_loader.py
@@ -12,6 +12,10 @@
import attr
import pytest
+from swh.loader.core.loader import (
+ SENTRY_ORIGIN_URL_TAG_NAME,
+ SENTRY_VISIT_TYPE_TAG_NAME,
+)
from swh.loader.package.loader import BasePackageInfo, PackageLoader
from swh.model.model import (
Origin,
@@ -518,3 +522,20 @@
AssertionError, match="SWH_CONFIG_FILENAME environment variable is undefined"
):
DummyPackageLoader.from_configfile(url="some-url")
+
+
+class StubPackageLoaderWithError(StubPackageLoader):
+ def get_versions(self, *args, **kwargs):
+ raise Exception("error")
+
+
+def test_loader_sentry_tags_on_error(swh_storage, sentry_events):
+ origin_url = "http://example.org/package/name"
+ loader = StubPackageLoaderWithError(swh_storage, origin_url)
+ loader.load()
+ sentry_tags = sentry_events[0]["tags"]
+ assert sentry_tags.get(SENTRY_ORIGIN_URL_TAG_NAME) == origin_url
+ assert (
+ sentry_tags.get(SENTRY_VISIT_TYPE_TAG_NAME)
+ == StubPackageLoaderWithError.visit_type
+ )
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Dec 18, 1:21 PM (7 h, 35 m ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3228384
Attached To
D8430: loader: Add origin URL and visit type as sentry tags
Event Timeline
Log In to Comment