-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #738 from shauneccles/build/refactor_sentry_and_ad…
…d_sha build: refactor sentry init, refactor spec files, wheel workflow, add sha and release to /api/info
- Loading branch information
Showing
9 changed files
with
149 additions
and
80 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
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,63 +1,62 @@ | ||
import logging | ||
import os | ||
import sys | ||
|
||
import sentry_sdk | ||
from dotenv import load_dotenv | ||
from sentry_sdk.integrations.aiohttp import AioHttpIntegration | ||
|
||
from ledfx.consts import PROJECT_VERSION | ||
from ledfx.utils import currently_frozen | ||
|
||
_LOGGER = logging.getLogger(__name__) | ||
|
||
# Load the prod.env - this does not exist by default, and will thus be false when run from source | ||
extDataDir = os.path.dirname(os.path.realpath(__file__)) | ||
|
||
if currently_frozen(): | ||
extDataDir = sys._MEIPASS | ||
load_dotenv(dotenv_path=os.path.join(extDataDir, "prod.env")) | ||
else: | ||
parent_dir = os.path.dirname(extDataDir) | ||
load_dotenv(dotenv_path=os.path.join(parent_dir, "prod.env")) | ||
|
||
|
||
is_release = os.getenv("IS_RELEASE", "false").lower() | ||
|
||
if is_release == "false": | ||
_LOGGER.debug("Running in development mode.") | ||
sentry_dsn = "https://b192934eebd517c86bf7e9c512b3888a@o482797.ingest.sentry.io/4506350241841152" | ||
# Change sample_rate to 1 to look at http calls, so all rest traffic stats | ||
sample_rate = 0 | ||
|
||
try: | ||
from subprocess import PIPE, Popen | ||
|
||
process = Popen(["git", "rev-parse", "HEAD"], stdout=PIPE) | ||
(commit_hash, err) = process.communicate() | ||
commit_hash = commit_hash[:7].decode("utf-8") | ||
exit_code = process.wait() | ||
# TODO: trap explicit exceptions if it becomes clear what they are | ||
except Exception as e: | ||
commit_hash = os.getenv("GITHUB_SHA", "unknown") | ||
commit_hash = commit_hash[:7].decode("utf-8") | ||
_LOGGER.warning(f"Failed to get git commit hash: {e}") | ||
release = f"ledfx@{PROJECT_VERSION}-{commit_hash}" | ||
else: | ||
_LOGGER.debug("Running in production mode.") | ||
# production / release behaviour due to injection of "prod" or anything really into ENVIRONMENT env variable | ||
sentry_dsn = "https://dc6070345a8dfa1f2f24433d16f7a133@o482797.ingest.sentry.io/4506350233321472" | ||
sample_rate = 0 | ||
release = f"ledfx@{PROJECT_VERSION}" | ||
|
||
_LOGGER.info("Sentry Configuration:") | ||
_LOGGER.info(f"DSN (first ten): {sentry_dsn[8:18]}") | ||
_LOGGER.info(f"Sample rate: {sample_rate}") | ||
_LOGGER.info(f"LedFx release: {release}") | ||
|
||
sentry_sdk.init( | ||
sentry_dsn, | ||
traces_sample_rate=sample_rate, | ||
integrations=[AioHttpIntegration()], | ||
release=release, | ||
) | ||
|
||
def setup_sentry(): | ||
""" | ||
Set up the Sentry configuration based on the environment variables. | ||
If running in development mode, a development Sentry DSN is used along with a sample rate of 0. | ||
If running in production mode, a production Sentry DSN is used along with a sample rate of 0. | ||
The release version is determined based on the project version and the git commit hash. | ||
""" | ||
is_release = os.getenv("IS_RELEASE", "false").lower() | ||
|
||
if is_release == "false": | ||
_LOGGER.debug("Running in development mode.") | ||
sentry_dsn = "https://b192934eebd517c86bf7e9c512b3888a@o482797.ingest.sentry.io/4506350241841152" | ||
# Change sample_rate to 1 to look at http calls, so all rest traffic stats | ||
sample_rate = 0 | ||
|
||
try: | ||
if currently_frozen(): | ||
commit_hash = os.getenv("GITHUB_SHA", "unknown") | ||
else: | ||
from subprocess import PIPE, Popen | ||
|
||
process = Popen(["git", "rev-parse", "HEAD"], stdout=PIPE) | ||
(commit_hash, err) = process.communicate() | ||
commit_hash = commit_hash[:7].decode("utf-8") | ||
exit_code = process.wait() | ||
# TODO: trap explicit exceptions if it becomes clear what they are | ||
except Exception as e: | ||
commit_hash = "unknown" | ||
_LOGGER.warning(f"Failed to get git commit hash: {e}") | ||
finally: | ||
commit_hash = commit_hash[:7] | ||
release = f"ledfx@{PROJECT_VERSION}-{commit_hash}" | ||
else: | ||
_LOGGER.debug("Running in production mode.") | ||
# production / release behaviour due to injection of "prod" or anything really into ENVIRONMENT env variable | ||
sentry_dsn = "https://dc6070345a8dfa1f2f24433d16f7a133@o482797.ingest.sentry.io/4506350233321472" | ||
sample_rate = 0 | ||
release = f"ledfx@{PROJECT_VERSION}" | ||
|
||
_LOGGER.info("Sentry Configuration:") | ||
_LOGGER.info(f"DSN (first ten): {sentry_dsn[8:18]}") | ||
_LOGGER.info(f"Sample rate: {sample_rate}") | ||
_LOGGER.info(f"LedFx release: {release}") | ||
|
||
sentry_sdk.init( | ||
sentry_dsn, | ||
traces_sample_rate=sample_rate, | ||
integrations=[AioHttpIntegration()], | ||
release=release, | ||
) |
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