Skip to content

Commit d700630

Browse files
feat: add telemetry (#584)
* feat: add telemetry * fix: bump to python 3.9-3.13 * fix: use wrapt at 1.16.* * fix: bump to wrapt==1.17.1 * fix: use the new wrapt * fix: try to do both archs * fix: try with macos-13 * fix: try universal2 now * fix: do some wrapt jiggery * fix: try it after * fix: use macos-latest * fix: move the comment
1 parent fd4347f commit d700630

19 files changed

Lines changed: 309 additions & 183 deletions

.github/workflows/build_assets.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
---
12
name: Build Compiled Assets
23

34
on:
@@ -18,8 +19,10 @@ jobs:
1819
include:
1920
- os: macos-latest
2021
TARGET: macos
22+
# currently, wrapt pulls the arm64 version instead of the universal one, so the below is a hack
2123
CMD_REQS: >
22-
mkdir -p pip-packages && cd pip-packages && pip wheel --no-cache-dir --no-binary tree_sitter,ijson,charset_normalizer,PyYAML .. && cd .. &&
24+
mkdir -p pip-packages && cd pip-packages && pip wheel --no-cache-dir --no-binary tree_sitter,ijson,charset_normalizer,PyYAML .. &&
25+
rm $(ls | grep wrapt) && pip download wrapt --platform=universal2 --only-binary=:all: && pip install $(ls | grep wrapt) --force-reinstall && cd .. &&
2326
pip install --no-deps --no-index --find-links=pip-packages pip-packages/*
2427
CMD_BUILD: >
2528
STATICCODECOV_LIB_PATH=$(find build/ -maxdepth 1 -type d -name 'lib.*' -print -quit | xargs -I {} sh -c "find {} -type f -name 'staticcodecov*' -print -quit | sed 's|^./||'") &&
@@ -94,7 +97,7 @@ jobs:
9497
- distro: "python:3.11-bullseye"
9598
arch: arm64
9699
distro_name: linux
97-
100+
98101
steps:
99102
- uses: actions/checkout@v4
100103
with:
@@ -127,6 +130,3 @@ jobs:
127130
asset_name: codecovcli_${{ matrix.distro_name }}_${{ matrix.arch }}
128131
tag: ${{ github.ref }}
129132
overwrite: true
130-
131-
132-

.github/workflows/build_for_pypi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ jobs:
3131
run: |
3232
pip install wheel
3333
python setup.py sdist bdist_wheel --plat-name=manylinux2014_x86_64
34-
python setup.py bdist_wheel --plat-name=macosx-12.6-x86_64
34+
python setup.py bdist_wheel --plat-name=macosx-12.6-universal2
3535
python setup.py bdist_wheel --plat-name=win_amd64
3636
- name: Publish package to PyPi
3737
if: inputs.publish == true

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,11 @@ jobs:
4848
fail-fast: false
4949
matrix:
5050
include:
51+
- python-version: "3.13"
5152
- python-version: "3.12"
5253
- python-version: "3.11"
5354
- python-version: "3.10"
5455
- python-version: "3.9"
55-
- python-version: "3.8"
5656
steps:
5757
- uses: actions/checkout@v4
5858
with:

codecov_cli/commands/upload_coverage.py

Lines changed: 110 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,19 @@
33
import typing
44

55
import click
6+
from opentelemetry import trace
67

78
from codecov_cli.commands.commit import create_commit
89
from codecov_cli.commands.report import create_report
910
from codecov_cli.commands.upload import do_upload, global_upload_options
1011
from codecov_cli.helpers.args import get_cli_args
1112
from codecov_cli.helpers.options import global_options
13+
from codecov_cli.opentelemetry import close_telem
1214
from codecov_cli.services.upload_coverage import upload_coverage_logic
1315
from codecov_cli.types import CommandContext
1416

1517
logger = logging.getLogger("codecovcli")
18+
tracer = trace.get_tracer(__name__)
1619

1720

1821
# These options are the combined options of commit, report and upload commands
@@ -60,116 +63,118 @@ def upload_coverage(
6063
token: typing.Optional[str],
6164
use_legacy_uploader: bool,
6265
):
63-
args = get_cli_args(ctx)
64-
logger.debug(
65-
"Starting upload coverage",
66-
extra=dict(
67-
extra_log_attributes=args,
68-
),
69-
)
70-
71-
if not use_legacy_uploader and report_type == "coverage":
72-
versioning_system = ctx.obj["versioning_system"]
73-
codecov_yaml = ctx.obj["codecov_yaml"] or {}
74-
cli_config = codecov_yaml.get("cli", {})
75-
ci_adapter = ctx.obj.get("ci_adapter")
76-
enterprise_url = ctx.obj.get("enterprise_url")
66+
with tracer.start_as_current_span("upload_coverage"):
7767
args = get_cli_args(ctx)
78-
ctx.invoke(
79-
upload_coverage_logic,
80-
cli_config,
81-
versioning_system,
82-
ci_adapter,
83-
branch=branch,
84-
build_code=build_code,
85-
build_url=build_url,
86-
commit_sha=commit_sha,
87-
disable_file_fixes=disable_file_fixes,
88-
disable_search=disable_search,
89-
dry_run=dry_run,
90-
enterprise_url=enterprise_url,
91-
env_vars=env_vars,
92-
fail_on_error=fail_on_error,
93-
files_search_exclude_folders=files_search_exclude_folders,
94-
files_search_explicitly_listed_files=files_search_explicitly_listed_files,
95-
files_search_root_folder=files_search_root_folder,
96-
flags=flags,
97-
gcov_args=gcov_args,
98-
gcov_executable=gcov_executable,
99-
gcov_ignore=gcov_ignore,
100-
gcov_include=gcov_include,
101-
git_service=git_service,
102-
handle_no_reports_found=handle_no_reports_found,
103-
job_code=job_code,
104-
name=name,
105-
network_filter=network_filter,
106-
network_prefix=network_prefix,
107-
network_root_folder=network_root_folder,
108-
parent_sha=parent_sha,
109-
plugin_names=plugin_names,
110-
pull_request_number=pull_request_number,
111-
report_code=report_code,
112-
slug=slug,
113-
swift_project=swift_project,
114-
token=token,
115-
upload_file_type=report_type,
116-
use_legacy_uploader=use_legacy_uploader,
117-
args=args,
118-
)
119-
else:
120-
ctx.invoke(
121-
create_commit,
122-
commit_sha=commit_sha,
123-
parent_sha=parent_sha,
124-
pull_request_number=pull_request_number,
125-
branch=branch,
126-
slug=slug,
127-
token=token,
128-
git_service=git_service,
129-
fail_on_error=True,
68+
logger.debug(
69+
"Starting upload coverage",
70+
extra=dict(
71+
extra_log_attributes=args,
72+
),
13073
)
131-
if report_type == "coverage":
74+
75+
if not use_legacy_uploader and report_type == "coverage":
76+
versioning_system = ctx.obj["versioning_system"]
77+
codecov_yaml = ctx.obj["codecov_yaml"] or {}
78+
cli_config = codecov_yaml.get("cli", {})
79+
ci_adapter = ctx.obj.get("ci_adapter")
80+
enterprise_url = ctx.obj.get("enterprise_url")
81+
args = get_cli_args(ctx)
13282
ctx.invoke(
133-
create_report,
83+
upload_coverage_logic,
84+
cli_config,
85+
versioning_system,
86+
ci_adapter,
87+
branch=branch,
88+
build_code=build_code,
89+
build_url=build_url,
90+
commit_sha=commit_sha,
91+
disable_file_fixes=disable_file_fixes,
92+
disable_search=disable_search,
93+
dry_run=dry_run,
94+
enterprise_url=enterprise_url,
95+
env_vars=env_vars,
96+
fail_on_error=fail_on_error,
97+
files_search_exclude_folders=files_search_exclude_folders,
98+
files_search_explicitly_listed_files=files_search_explicitly_listed_files,
99+
files_search_root_folder=files_search_root_folder,
100+
flags=flags,
101+
gcov_args=gcov_args,
102+
gcov_executable=gcov_executable,
103+
gcov_ignore=gcov_ignore,
104+
gcov_include=gcov_include,
105+
git_service=git_service,
106+
handle_no_reports_found=handle_no_reports_found,
107+
job_code=job_code,
108+
name=name,
109+
network_filter=network_filter,
110+
network_prefix=network_prefix,
111+
network_root_folder=network_root_folder,
112+
parent_sha=parent_sha,
113+
plugin_names=plugin_names,
114+
pull_request_number=pull_request_number,
115+
report_code=report_code,
116+
slug=slug,
117+
swift_project=swift_project,
134118
token=token,
135-
code=report_code,
136-
fail_on_error=True,
119+
upload_file_type=report_type,
120+
use_legacy_uploader=use_legacy_uploader,
121+
args=args,
122+
)
123+
else:
124+
ctx.invoke(
125+
create_commit,
137126
commit_sha=commit_sha,
127+
parent_sha=parent_sha,
128+
pull_request_number=pull_request_number,
129+
branch=branch,
138130
slug=slug,
131+
token=token,
139132
git_service=git_service,
133+
fail_on_error=True,
140134
)
141-
ctx.invoke(
142-
do_upload,
143-
branch=branch,
144-
build_code=build_code,
145-
build_url=build_url,
146-
commit_sha=commit_sha,
147-
disable_file_fixes=disable_file_fixes,
148-
disable_search=disable_search,
149-
dry_run=dry_run,
150-
env_vars=env_vars,
151-
fail_on_error=fail_on_error,
152-
files_search_exclude_folders=files_search_exclude_folders,
153-
files_search_explicitly_listed_files=files_search_explicitly_listed_files,
154-
files_search_root_folder=files_search_root_folder,
155-
flags=flags,
156-
gcov_args=gcov_args,
157-
gcov_executable=gcov_executable,
158-
gcov_ignore=gcov_ignore,
159-
gcov_include=gcov_include,
160-
git_service=git_service,
161-
handle_no_reports_found=handle_no_reports_found,
162-
job_code=job_code,
163-
name=name,
164-
network_filter=network_filter,
165-
network_prefix=network_prefix,
166-
network_root_folder=network_root_folder,
167-
plugin_names=plugin_names,
168-
pull_request_number=pull_request_number,
169-
report_code=report_code,
170-
report_type=report_type,
171-
slug=slug,
172-
swift_project=swift_project,
173-
token=token,
174-
use_legacy_uploader=use_legacy_uploader,
175-
)
135+
if report_type == "coverage":
136+
ctx.invoke(
137+
create_report,
138+
token=token,
139+
code=report_code,
140+
fail_on_error=True,
141+
commit_sha=commit_sha,
142+
slug=slug,
143+
git_service=git_service,
144+
)
145+
ctx.invoke(
146+
do_upload,
147+
branch=branch,
148+
build_code=build_code,
149+
build_url=build_url,
150+
commit_sha=commit_sha,
151+
disable_file_fixes=disable_file_fixes,
152+
disable_search=disable_search,
153+
dry_run=dry_run,
154+
env_vars=env_vars,
155+
fail_on_error=fail_on_error,
156+
files_search_exclude_folders=files_search_exclude_folders,
157+
files_search_explicitly_listed_files=files_search_explicitly_listed_files,
158+
files_search_root_folder=files_search_root_folder,
159+
flags=flags,
160+
gcov_args=gcov_args,
161+
gcov_executable=gcov_executable,
162+
gcov_ignore=gcov_ignore,
163+
gcov_include=gcov_include,
164+
git_service=git_service,
165+
handle_no_reports_found=handle_no_reports_found,
166+
job_code=job_code,
167+
name=name,
168+
network_filter=network_filter,
169+
network_prefix=network_prefix,
170+
network_root_folder=network_root_folder,
171+
plugin_names=plugin_names,
172+
pull_request_number=pull_request_number,
173+
report_code=report_code,
174+
report_type=report_type,
175+
slug=slug,
176+
swift_project=swift_project,
177+
token=token,
178+
use_legacy_uploader=use_legacy_uploader,
179+
)
180+
close_telem()

codecov_cli/helpers/ci_adapters/azure_pipelines.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def _get_commit_sha(self):
1616

1717
def _get_build_url(self):
1818
if os.getenv("SYSTEM_TEAMPROJECT") and os.getenv("BUILD_BUILDID"):
19-
return f'{os.getenv("SYSTEM_TEAMFOUNDATIONCOLLECTIONURI")}{os.getenv("SYSTEM_TEAMPROJECT")}/_build/results?buildId={os.getenv("BUILD_BUILDID")}'
19+
return f"{os.getenv('SYSTEM_TEAMFOUNDATIONCOLLECTIONURI')}{os.getenv('SYSTEM_TEAMPROJECT')}/_build/results?buildId={os.getenv('BUILD_BUILDID')}"
2020

2121
def _get_build_code(self):
2222
return os.getenv("BUILD_BUILDNUMBER")

codecov_cli/main.py

Lines changed: 8 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 init_telem
89
from codecov_cli.commands.base_picking import pr_base_picking
910
from codecov_cli.commands.commit import create_commit
1011
from codecov_cli.commands.create_report_result import create_report_results
@@ -43,6 +44,9 @@
4344
"--enterprise-url", "--url", "-u", help="Change the upload host (Enterprise use)"
4445
)
4546
@click.option("-v", "--verbose", "verbose", help="Use verbose logging", is_flag=True)
47+
@click.option(
48+
"--disable-telem", help="Disable sending telemetry data to Codecov", is_flag=True
49+
)
4650
@click.pass_context
4751
@click.version_option(__version__, prog_name="codecovcli")
4852
def cli(
@@ -51,6 +55,7 @@ def cli(
5155
codecov_yml_path: pathlib.Path,
5256
enterprise_url: str,
5357
verbose: bool = False,
58+
disable_telem: bool = False,
5459
):
5560
ctx.obj["cli_args"] = ctx.params
5661
ctx.obj["cli_args"]["version"] = f"cli-{__version__}"
@@ -65,6 +70,9 @@ def cli(
6570
ctx.default_map = {ctx.invoked_subcommand: {"token": token}}
6671
ctx.obj["enterprise_url"] = enterprise_url
6772

73+
if not disable_telem:
74+
init_telem(__version__, enterprise_url)
75+
6876

6977
cli.add_command(do_upload)
7078
cli.add_command(create_commit)

codecov_cli/opentelemetry.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import os
2+
import time
3+
4+
from opentelemetry import trace
5+
from opentelemetry.propagate import set_global_textmap
6+
from opentelemetry.sdk.trace import TracerProvider
7+
import sentry_sdk
8+
from sentry_sdk.integrations.opentelemetry import SentrySpanProcessor, SentryPropagator
9+
10+
11+
def init_telem(version, url):
12+
if url: # dont run on dedicated cloud
13+
return
14+
15+
if os.getenv("IS_CI", False):
16+
return
17+
18+
sentry_sdk.init(
19+
dsn="https://0bea75c61745c221a6ef1ac1709b1f4d@o26192.ingest.us.sentry.io/4508615876083713",
20+
enable_tracing=True,
21+
release=f"cli@{version}",
22+
instrumenter="otel",
23+
)
24+
25+
provider = TracerProvider()
26+
provider.add_span_processor(SentrySpanProcessor())
27+
trace.set_tracer_provider(provider)
28+
set_global_textmap(SentryPropagator())
29+
30+
31+
def close_telem():
32+
sentry_sdk.flush()

codecov_cli/plugins/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def _load_plugin_from_yaml(plugin_dict: typing.Dict):
5858

5959
except TypeError:
6060
click.secho(
61-
f"Unable to instantiate {class_obj} with provided parameters { plugin_dict.get('params', '') }",
61+
f"Unable to instantiate {class_obj} with provided parameters {plugin_dict.get('params', '')}",
6262
err=True,
6363
)
6464
return NoopPlugin()

0 commit comments

Comments
 (0)