Skip to content

Commit

Permalink
feat(sentry): Adding version tag, cleaning up version logic (#145)
Browse files Browse the repository at this point in the history
  • Loading branch information
IanWoodard authored Nov 14, 2024
1 parent 58647fd commit 7cc444d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion devservices/commands/check_for_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from urllib.request import urlopen


def check_for_update(current_version: str) -> str | None:
def check_for_update() -> str | None:
url = "https://api.github.com/repos/getsentry/devservices/releases/latest"
with urlopen(url) as response:
if response.status == 200:
Expand Down
2 changes: 1 addition & 1 deletion devservices/commands/update.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def add_parser(subparsers: _SubParsersAction[ArgumentParser]) -> None:
def update(args: Namespace) -> None:
console = Console()
current_version = metadata.version("devservices")
latest_version = check_for_update(current_version)
latest_version = check_for_update()

if latest_version is None:
raise DevservicesUpdateError("Failed to check for updates.")
Expand Down
24 changes: 14 additions & 10 deletions devservices/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
import os
from importlib import metadata

import sentry_sdk
from sentry_sdk import capture_exception
from sentry_sdk import flush
from sentry_sdk import init
from sentry_sdk import set_tag
from sentry_sdk import set_user
from sentry_sdk import start_transaction
from sentry_sdk.integrations.argv import ArgvIntegration

from devservices.commands import list_dependencies
Expand All @@ -34,7 +38,7 @@
logging.basicConfig(level=logging.INFO)

if not disable_sentry:
sentry_sdk.init(
init(
dsn="https://[email protected]/4507946704961536",
traces_sample_rate=1.0,
profiles_sample_rate=1.0,
Expand All @@ -43,16 +47,18 @@
environment=sentry_environment,
)
username = getpass.getuser()
sentry_sdk.set_user({"username": username})
set_user({"username": username})


@atexit.register
def cleanup() -> None:
sentry_sdk.flush()
flush()


def main() -> None:
console = Console()
current_version = metadata.version("devservices")
set_tag("devservices_version", current_version)
try:
check_docker_compose_version()
except DockerDaemonNotRunningError as e:
Expand All @@ -68,9 +74,7 @@ def main() -> None:
description="CLI tool for managing service dependencies.",
usage="devservices [-h] [--version] COMMAND ...",
)
parser.add_argument(
"--version", action="version", version=metadata.version("devservices")
)
parser.add_argument("--version", action="version", version=current_version)

subparsers = parser.add_subparsers(dest="command", title="commands", metavar="")

Expand All @@ -93,14 +97,14 @@ def main() -> None:

if args.command:
# Call the appropriate function based on the command
with sentry_sdk.start_transaction(op="command", name=args.command):
with start_transaction(op="command", name=args.command):
args.func(args)
else:
parser.print_help()

if args.command != "update":
newest_version = check_for_update(metadata.version("devservices"))
if newest_version != metadata.version("devservices"):
newest_version = check_for_update()
if newest_version != current_version:
console.warning(
f"WARNING: A new version of devservices is available: {newest_version}"
)
Expand Down

0 comments on commit 7cc444d

Please sign in to comment.