Skip to content

Commit e4e74bf

Browse files
fix: implement some sentry tagging to help identify issues
1 parent 03f2564 commit e4e74bf

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

codecov-cli/codecov_cli/helpers/args.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import click
66

77
from codecov_cli import __version__
8+
from codecov_cli.opentelemetry import set_cli_tags
89

910
logger = logging.getLogger("codecovcli")
1011

@@ -28,4 +29,6 @@ def get_cli_args(ctx: click.Context):
2829
except Exception:
2930
continue
3031

32+
set_cli_tags(filtered_args, ctx)
33+
3134
return filtered_args

codecov-cli/codecov_cli/opentelemetry.py

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import os
2-
import time
32

43
import sentry_sdk
54

65
from codecov_cli import __version__
76

7+
_SKIP_TAG_KEYS = {"branch", "flags", "commit_sha", "env_vars"}
8+
89

910
def init_telem(ctx):
1011
if ctx["disable_telem"]:
@@ -22,5 +23,33 @@ def init_telem(ctx):
2223
)
2324

2425

26+
def set_cli_tags(args: dict, ctx):
27+
"""Set Sentry tags from resolved CLI arguments."""
28+
for key, value in args.items():
29+
if key in _SKIP_TAG_KEYS:
30+
continue
31+
if value is None or value in ([], (), {}):
32+
continue
33+
if isinstance(value, (list, tuple)):
34+
value = ",".join(str(v) for v in value)
35+
elif isinstance(value, dict):
36+
value = ",".join(
37+
f"{k}={v}" for k, v in value.items() if v is not None
38+
)
39+
sentry_sdk.set_tag(f"cli.{key}", str(value)[:200])
40+
41+
token = ctx.params.get("token") if hasattr(ctx, "params") else None
42+
sentry_sdk.set_tag("cli.token_provided", str(bool(token)).lower())
43+
44+
ci_adapter = (
45+
ctx.obj.get("ci_adapter") if hasattr(ctx, "obj") and ctx.obj else None
46+
)
47+
if ci_adapter is not None:
48+
try:
49+
sentry_sdk.set_tag("cli.ci_adapter", ci_adapter.get_service_name())
50+
except Exception:
51+
pass
52+
53+
2554
def close_telem():
2655
sentry_sdk.flush()

0 commit comments

Comments
 (0)