Skip to content

Commit 7cc444d

Browse files
authored
feat(sentry): Adding version tag, cleaning up version logic (#145)
1 parent 58647fd commit 7cc444d

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

devservices/commands/check_for_update.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
from urllib.request import urlopen
55

66

7-
def check_for_update(current_version: str) -> str | None:
7+
def check_for_update() -> str | None:
88
url = "https://api.github.com/repos/getsentry/devservices/releases/latest"
99
with urlopen(url) as response:
1010
if response.status == 200:

devservices/commands/update.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def add_parser(subparsers: _SubParsersAction[ArgumentParser]) -> None:
4444
def update(args: Namespace) -> None:
4545
console = Console()
4646
current_version = metadata.version("devservices")
47-
latest_version = check_for_update(current_version)
47+
latest_version = check_for_update()
4848

4949
if latest_version is None:
5050
raise DevservicesUpdateError("Failed to check for updates.")

devservices/main.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@
77
import os
88
from importlib import metadata
99

10-
import sentry_sdk
1110
from sentry_sdk import capture_exception
11+
from sentry_sdk import flush
12+
from sentry_sdk import init
13+
from sentry_sdk import set_tag
14+
from sentry_sdk import set_user
15+
from sentry_sdk import start_transaction
1216
from sentry_sdk.integrations.argv import ArgvIntegration
1317

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

3640
if not disable_sentry:
37-
sentry_sdk.init(
41+
init(
3842
dsn="https://[email protected]/4507946704961536",
3943
traces_sample_rate=1.0,
4044
profiles_sample_rate=1.0,
@@ -43,16 +47,18 @@
4347
environment=sentry_environment,
4448
)
4549
username = getpass.getuser()
46-
sentry_sdk.set_user({"username": username})
50+
set_user({"username": username})
4751

4852

4953
@atexit.register
5054
def cleanup() -> None:
51-
sentry_sdk.flush()
55+
flush()
5256

5357

5458
def main() -> None:
5559
console = Console()
60+
current_version = metadata.version("devservices")
61+
set_tag("devservices_version", current_version)
5662
try:
5763
check_docker_compose_version()
5864
except DockerDaemonNotRunningError as e:
@@ -68,9 +74,7 @@ def main() -> None:
6874
description="CLI tool for managing service dependencies.",
6975
usage="devservices [-h] [--version] COMMAND ...",
7076
)
71-
parser.add_argument(
72-
"--version", action="version", version=metadata.version("devservices")
73-
)
77+
parser.add_argument("--version", action="version", version=current_version)
7478

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

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

9498
if args.command:
9599
# Call the appropriate function based on the command
96-
with sentry_sdk.start_transaction(op="command", name=args.command):
100+
with start_transaction(op="command", name=args.command):
97101
args.func(args)
98102
else:
99103
parser.print_help()
100104

101105
if args.command != "update":
102-
newest_version = check_for_update(metadata.version("devservices"))
103-
if newest_version != metadata.version("devservices"):
106+
newest_version = check_for_update()
107+
if newest_version != current_version:
104108
console.warning(
105109
f"WARNING: A new version of devservices is available: {newest_version}"
106110
)

0 commit comments

Comments
 (0)