This repository has been archived by the owner on Jan 12, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8e945d2
commit 0400f2f
Showing
6 changed files
with
83 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
import logging | ||
import os | ||
import platform | ||
|
||
import psutil | ||
import sentry_sdk | ||
|
||
from nanolayer.utils.linux_information_desk import EnvFile | ||
from nanolayer.utils.settings import NanolayerSettings | ||
from nanolayer.utils.version import resolve_own_package_version | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
try: | ||
sentry_sdk.init( | ||
release=resolve_own_package_version(), | ||
traces_sample_rate=1.0, | ||
dsn=NanolayerSettings().analytics_id | ||
if not NanolayerSettings().no_analytics | ||
else "", | ||
# explicitly turn off any feature which have an | ||
# impact on personally identifiable information | ||
send_default_pii=False, | ||
send_client_reports=False, | ||
request_bodies="never", | ||
) | ||
# explicitly strip any identifiable user information | ||
sentry_sdk.set_user(None) | ||
|
||
# ------ add generic non-identifiable hardware metrics ------- | ||
sentry_sdk.set_context( | ||
"nanolayer.python", | ||
{ | ||
# uname -a like | ||
"platform.uname": str(platform.uname()), | ||
# num of cores | ||
"os.cpu_count": os.cpu_count(), | ||
# 4GB 8GB 16GB etc | ||
"psutil.virtual_memory": str(psutil.virtual_memory()), | ||
}, | ||
) | ||
os_release = EnvFile.parse("/etc/os-release") | ||
# x86_64 / ARM | ||
sentry_sdk.set_tag("nanolayer.arch", platform.machine()) | ||
# ubuntu / debian / alpine / fedora etc | ||
sentry_sdk.set_tag("nanolayer.os_release.ID", os_release.get("ID", None)) | ||
# debian for both ubuntu and debian, etc | ||
sentry_sdk.set_tag("nanolayer.os_release.ID_LIKE", os_release.get("ID_LIKE", None)) | ||
# ubuntu 18.04 20.04 22.04 etc | ||
sentry_sdk.set_tag( | ||
"nanolayer.os_release.VERSION_ID", os_release.get("VERSION_ID", None) | ||
) | ||
# true if nanolayer is being used as a binary, false otherwise | ||
sentry_sdk.set_tag("nanolayer.binary_mode", "__file__" not in globals()) | ||
except Exception as e: # no qa | ||
logger.warning("usage metrics are disabled") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
pydantic==1.10.5 | ||
typer | ||
invoke | ||
semver==2.13.0 | ||
semver==2.13.0 | ||
sentry-sdk>=1.19.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters