Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions codecov_cli/opentelemetry.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,25 @@
import logging
import os
import random

import sentry_sdk

from codecov_cli import __version__

logger = logging.getLogger(__name__)

_SENTRY_SDK_MIN_VERSION = (2, 0, 0)


def _sentry_sdk_version_ok() -> bool:
"""Return True if the installed sentry-sdk meets the minimum required version."""
try:
version_str = sentry_sdk.VERSION
parts = tuple(int(x) for x in version_str.split(".")[:3])
return parts >= _SENTRY_SDK_MIN_VERSION
except Exception:
return False

_SAMPLED_MESSAGES = [
"Token required",
"No JUnit XML reports found",
Expand Down Expand Up @@ -43,6 +58,13 @@ def init_telem(ctx):
return
if os.getenv("CODECOV_ENV", "production") == "test":
return
if not _sentry_sdk_version_ok():
logger.warning(
"sentry-sdk version %s is too old (requires >= %s); telemetry disabled.",
sentry_sdk.VERSION,
".".join(str(v) for v in _SENTRY_SDK_MIN_VERSION),
)
return

sentry_sdk.init(
dsn="https://0bea75c61745c221a6ef1ac1709b1f4d@o26192.ingest.us.sentry.io/4508615876083713",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ dependencies = [
"ijson==3.*",
"PyYAML==6.*",
"requests>=2.25.0",
"sentry-sdk==2.*",
"sentry-sdk>=2.0.0,<3.0.0",
"test-results-parser==0.6.1",
]

Expand Down
Loading