From 63a084f16395a3013c13e64a4378db3d9599e092 Mon Sep 17 00:00:00 2001 From: thomasrockhu-codecov Date: Tue, 24 Mar 2026 22:38:27 +0900 Subject: [PATCH] fix: implement some sentry tagging to help identify issues --- codecov-cli/codecov_cli/helpers/args.py | 3 +++ codecov-cli/codecov_cli/opentelemetry.py | 31 +++++++++++++++++++++++- 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/codecov-cli/codecov_cli/helpers/args.py b/codecov-cli/codecov_cli/helpers/args.py index 0d797692..ea30891c 100644 --- a/codecov-cli/codecov_cli/helpers/args.py +++ b/codecov-cli/codecov_cli/helpers/args.py @@ -5,6 +5,7 @@ import click from codecov_cli import __version__ +from codecov_cli.opentelemetry import set_cli_tags logger = logging.getLogger("codecovcli") @@ -28,4 +29,6 @@ def get_cli_args(ctx: click.Context): except Exception: continue + set_cli_tags(filtered_args, ctx) + return filtered_args diff --git a/codecov-cli/codecov_cli/opentelemetry.py b/codecov-cli/codecov_cli/opentelemetry.py index bec54273..442bfaf2 100644 --- a/codecov-cli/codecov_cli/opentelemetry.py +++ b/codecov-cli/codecov_cli/opentelemetry.py @@ -1,10 +1,11 @@ import os -import time import sentry_sdk from codecov_cli import __version__ +_SKIP_TAG_KEYS = {"branch", "flags", "commit_sha", "env_vars"} + def init_telem(ctx): if ctx["disable_telem"]: @@ -22,5 +23,33 @@ def init_telem(ctx): ) +def set_cli_tags(args: dict, ctx): + """Set Sentry tags from resolved CLI arguments.""" + for key, value in args.items(): + if key in _SKIP_TAG_KEYS: + continue + if value is None or value in ([], (), {}): + continue + if isinstance(value, (list, tuple)): + value = ",".join(str(v) for v in value) + elif isinstance(value, dict): + value = ",".join( + f"{k}={v}" for k, v in value.items() if v is not None + ) + sentry_sdk.set_tag(f"cli.{key}", str(value)[:200]) + + token = ctx.params.get("token") if hasattr(ctx, "params") else None + sentry_sdk.set_tag("cli.token_provided", str(bool(token)).lower()) + + ci_adapter = ( + ctx.obj.get("ci_adapter") if hasattr(ctx, "obj") and ctx.obj else None + ) + if ci_adapter is not None: + try: + sentry_sdk.set_tag("cli.ci_adapter", ci_adapter.get_service_name()) + except Exception: + pass + + def close_telem(): sentry_sdk.flush()