-
-
Notifications
You must be signed in to change notification settings - Fork 55
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
f39fef9
commit 8ce3f8f
Showing
4 changed files
with
57 additions
and
0 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
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 |
---|---|---|
|
@@ -26,6 +26,7 @@ dependencies = [ | |
"uvicorn", | ||
"pydantic_settings", | ||
"httpx", | ||
"sentry_sdk" | ||
] | ||
|
||
[project.urls] | ||
|
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
""" Log usage of this package to Sentry """ | ||
|
||
import sentry_sdk | ||
from quartz_solar_forecast.pydantic_models import PVSite | ||
|
||
import os | ||
|
||
quartz_solar_forecast_logging = bool(os.getenv("QUARTZ_SOLAR_FORECAST_LOGGING", True)) | ||
|
||
SENTRY_DSN = 'https://[email protected]/4508439933157376' | ||
sentry_sdk.init( | ||
dsn=SENTRY_DSN, | ||
) | ||
|
||
|
||
def write_sentry(params): | ||
""" | ||
Log usage of this package to Sentry | ||
""" | ||
|
||
if not quartz_solar_forecast_logging: | ||
return | ||
|
||
try: | ||
for key, value in params.items(): | ||
|
||
# we want to make sure we don't store the exact location of the site | ||
if isinstance(value, PVSite): | ||
value.round_latitude_and_longitude() | ||
|
||
# set sentry tag | ||
sentry_sdk.set_tag(key, value) | ||
|
||
message = "quartz_solar_forecast is being used" | ||
|
||
if os.getenv("PYTEST_CURRENT_TEST") is not None: | ||
message += ": in CI tests" | ||
|
||
sentry_sdk.capture_message(message) | ||
|
||
except Exception as _: # noqa | ||
pass |