Skip to content

Commit

Permalink
Fix unhandled exception, add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
mejroslav committed Aug 21, 2023
1 parent f88a452 commit e8ad5f4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
2 changes: 1 addition & 1 deletion asab/sentry/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
{
"sentry": {
"data_source_name": "",
"environment": "development",
"environment": "not specified",
"traces_sample_rate": 1.0,
},

Expand Down
28 changes: 17 additions & 11 deletions asab/sentry/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,21 @@ class SentryService(asab.Service):
def __init__(self, app, service_name: str):
super().__init__(app, service_name)


# DATA SOURCE NAME (DSN)
# format: https://<public key>@o<secret key>.ingest.sentry.io/<project id>
# DSN is automatically generated when new project is created
# and can be modified: Settings > Client Keys (DSN) > Key Details
# Specification: either in configuration or via $SENTRY_DSN environment variable
self.DataSourceName = asab.Config.get("sentry", "data_source_name", fallback="")
if len(self.DataSourceName) == 0:
self.DataSourceName = os.getenv("SENTRY_DSN", "")
if len(self.DataSourceName) == 0:
L.error("Data source name is not set. Specify it via SENTRY_DSN env variable or in configuration: [sentry] data_source_name.")


# LOGGING LEVELS
# by default, LOG_NOTICE+ are sent to breadcrumbs, ERROR+ to events
levels = {
"debug": logging.DEBUG,
"info": logging.INFO,
Expand All @@ -77,26 +82,24 @@ def __init__(self, app, service_name: str):

# RELEASE
# Release can be obtained from MANIFEST.json if exists
path = asab.Config.get("general", "manifest")
if path == "":
manifest = None
manifest_path = asab.Config.get("general", "manifest", fallback="")
if manifest_path == "":
if os.path.isfile("/app/MANIFEST.json"):
path = "/app/MANIFEST.json"
manifest_path = "/app/MANIFEST.json"
elif os.path.isfile("/MANIFEST.json"):
path = "/MANIFEST.json"
manifest_path = "/MANIFEST.json"
elif os.path.isfile("MANIFEST.json"):
path = "MANIFEST.json"
manifest_path = "MANIFEST.json"

if len(path) != 0:
if len(manifest_path) != 0:
try:
with open(path) as f:
with open(manifest_path) as f:
manifest = json.load(f)
except Exception as e:
L.exception("Error when reading manifest for reason {}".format(e))

else:
manifest = None

if manifest:
if manifest is not None:
self.Release = manifest.get("version", fallback="not specified")
else:
self.Release = "not specified"
Expand All @@ -108,6 +111,8 @@ def __init__(self, app, service_name: str):
self.TracesSampleRate = asab.Config.getfloat("sentry", "traces_sample_rate")
assert 0 <= self.TracesSampleRate <= 1.0, "Traces sample rate must be between 0 and 1."


# INITIALIZATION
sentry_sdk.init(
dsn=self.DataSourceName,
integrations=[
Expand All @@ -126,6 +131,7 @@ def __init__(self, app, service_name: str):
)
# TODO: Investigate CA certs, TLS/SSL, Security Tokens, Allowed Domains


# ADDITIONAL GLOBAL TAGS
# These tags will be set manually or automatically by Remote Control
self.NodeId = os.getenv("NODE_ID", None) # e.g. "lmio-box-testing-1"
Expand Down

0 comments on commit e8ad5f4

Please sign in to comment.