diff --git a/codecov_cli/opentelemetry.py b/codecov_cli/opentelemetry.py index b902a433..b37526c3 100644 --- a/codecov_cli/opentelemetry.py +++ b/codecov_cli/opentelemetry.py @@ -1,3 +1,4 @@ +import logging import os import random @@ -5,6 +6,8 @@ from codecov_cli import __version__ +logger = logging.getLogger("codecovcli") + _SAMPLED_MESSAGES = [ "Token required", "No JUnit XML reports found", @@ -44,6 +47,14 @@ def init_telem(ctx): if os.getenv("CODECOV_ENV", "production") == "test": return + sdk_version = tuple(int(x) for x in sentry_sdk.VERSION.split(".")[:2]) + if sdk_version < (2, 0): + logger.warning( + "sentry-sdk %s is installed but codecov-cli requires >=2.0. " + "Some telemetry features may not work correctly.", + sentry_sdk.VERSION, + ) + sentry_sdk.init( dsn="https://0bea75c61745c221a6ef1ac1709b1f4d@o26192.ingest.us.sentry.io/4508615876083713", enable_tracing=True, diff --git a/codecov_cli/services/upload/upload_sender.py b/codecov_cli/services/upload/upload_sender.py index db8658d3..885d789f 100644 --- a/codecov_cli/services/upload/upload_sender.py +++ b/codecov_cli/services/upload/upload_sender.py @@ -50,7 +50,10 @@ def send_upload_data( upload_coverage: bool = False, args: dict = None, ) -> RequestResult: - current_transaction = sentry_sdk.get_current_scope().transaction + try: + current_transaction = sentry_sdk.get_current_scope().transaction + except AttributeError: + current_transaction = None if current_transaction: current_transaction.set_data("commit_sha", commit_sha) current_transaction.set_data("slug", slug)