Skip to content

Commit e839b4a

Browse files
authored
Merge branch 'main' into mypy-to-pyright
2 parents 16962d8 + 2450943 commit e839b4a

File tree

7 files changed

+872
-29
lines changed

7 files changed

+872
-29
lines changed

.github/workflows/misc_0.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ jobs:
236236
- name: Check github workflows are up to date
237237
run: git diff --exit-code || (echo 'Generated workflows are out of date, run "tox -e generate-workflows" and commit the changes in this PR.' && exit 1)
238238

239-
ruff:
240-
name: ruff
239+
precommit:
240+
name: precommit
241241
runs-on: ubuntu-latest
242242
steps:
243243
- name: Checkout repo @ SHA - ${{ github.sha }}
@@ -252,4 +252,4 @@ jobs:
252252
run: pip install tox
253253

254254
- name: Run tests
255-
run: tox -e ruff
255+
run: tox -e precommit

.pre-commit-config.yaml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
repos:
2-
- repo: https://github.com/astral-sh/ruff-pre-commit
3-
# Ruff version.
4-
rev: v0.6.9
5-
hooks:
6-
# Run the linter.
7-
- id: ruff
8-
args: ["--fix", "--show-fixes"]
9-
# Run the formatter.
10-
- id: ruff-format
2+
- repo: https://github.com/astral-sh/ruff-pre-commit
3+
# Ruff version.
4+
rev: v0.6.9
5+
hooks:
6+
# Run the linter.
7+
- id: ruff
8+
args: ["--fix", "--show-fixes"]
9+
# Run the formatter.
10+
- id: ruff-format
11+
- repo: https://github.com/astral-sh/uv-pre-commit
12+
# uv version.
13+
rev: 0.6.0
14+
hooks:
15+
- id: uv-lock

CONTRIBUTING.md

Lines changed: 46 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ some aspects of development, including testing against multiple Python versions.
4545
To install `tox`, run:
4646

4747
```console
48-
$ pip install tox
48+
pip install tox
4949
```
5050

5151
You can run `tox` with the following arguments:
@@ -64,19 +64,36 @@ You can run `tox` with the following arguments:
6464
- `tox -e public-symbols-check` to run public_symbols_checker.py.
6565
- `tox -e docker-tests-{otlpexporter,opencensus}` to run tests in both or either one location.
6666
- `tox -e tracecontext` to run integration tests for tracecontext.
67+
- `tox -e precommit` to run all `pre-commit` actions
6768

6869
`ruff check` and `ruff format` are executed when `tox -e ruff` is run. We strongly recommend you to configure [pre-commit](https://pre-commit.com/) locally to run `ruff` automatically before each commit by installing it as git hooks. You just need to [install pre-commit](https://pre-commit.com/#install) in your environment:
6970

7071
```console
71-
$ pip install pre-commit -c dev-requirements.txt
72+
pip install pre-commit -c dev-requirements.txt
7273
```
7374

7475
and run this command inside the git repository:
7576

7677
```console
77-
$ pre-commit install
78+
pre-commit install
7879
```
7980

81+
### Virtual Environment
82+
83+
You can also create a single virtual environment to make it easier to run local tests.
84+
85+
For that, you'll need to install [`uv`](https://docs.astral.sh/uv/getting-started/installation/).
86+
87+
After installing `uv`, you can run the following command:
88+
89+
```sh
90+
uv sync
91+
```
92+
93+
This will create a virtual environment in the `.venv` directory and install all the necessary dependencies.
94+
95+
### Public Symbols
96+
8097
We try to keep the amount of _public symbols_ in our code minimal. A public symbol is any Python identifier that does not start with an underscore.
8198
Every public symbol is something that has to be kept in order to maintain backwards compatibility, so we try to have as few as possible.
8299

@@ -111,7 +128,7 @@ See
111128
[`tox.ini`](https://github.com/open-telemetry/opentelemetry-python/blob/main/tox.ini)
112129
for more detail on available tox commands.
113130

114-
#### Contrib repo
131+
### Contrib repo
115132

116133
Some of the `tox` targets install packages from the [OpenTelemetry Python Contrib Repository](https://github.com/open-telemetry/opentelemetry-python.git) via
117134
pip. The version of the packages installed defaults to the `main` branch in that repository when `tox` is run locally. It is possible to install packages tagged
@@ -157,31 +174,45 @@ pull requests (PRs).
157174
To create a new PR, fork the project in GitHub and clone the upstream repo:
158175

159176
```console
160-
$ git clone https://github.com/open-telemetry/opentelemetry-python.git
161-
$ cd opentelemetry-python
177+
git clone https://github.com/open-telemetry/opentelemetry-python.git
178+
cd opentelemetry-python
162179
```
163180

164181
Add your fork as an origin:
165182

166183
```console
167-
$ git remote add fork https://github.com/YOUR_GITHUB_USERNAME/opentelemetry-python.git
184+
git remote add fork https://github.com/YOUR_GITHUB_USERNAME/opentelemetry-python.git
168185
```
169186

170-
Run tests:
187+
Make sure you have all supported versions of Python installed, install tox only for the first time:
171188

172189
```sh
173-
# make sure you have all supported versions of Python installed
174-
$ pip install tox # only first time.
175-
$ tox # execute in the root of the repository
190+
pip install tox
191+
```
192+
193+
Run tests in the root of the repository (this will run all tox environments and may take some time):
194+
195+
```sh
196+
tox
176197
```
177198

178199
Check out a new branch, make modifications and push the branch to your fork:
179200

180201
```sh
181-
$ git checkout -b feature
182-
# edit files
183-
$ git commit
184-
$ git push fork feature
202+
git checkout -b feature
203+
```
204+
205+
After you edit the files, stage changes in the current directory:
206+
207+
```sh
208+
git add .
209+
```
210+
211+
Then run the following to commit the changes:
212+
213+
```sh
214+
git commit
215+
git push fork feature
185216
```
186217

187218
Open a pull request against the main `opentelemetry-python` repo.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# pylint: disable=redefined-outer-name, invalid-name
2+
import pytest
3+
4+
from opentelemetry import trace
5+
from opentelemetry.baggage import (
6+
clear,
7+
get_all,
8+
get_baggage,
9+
remove_baggage,
10+
set_baggage,
11+
)
12+
13+
tracer = trace.get_tracer(__name__)
14+
15+
16+
@pytest.fixture(params=[10, 100, 1000, 10000])
17+
def baggage_size(request):
18+
return request.param
19+
20+
21+
def set_baggage_operation(size=10):
22+
with tracer.start_span(name="root span"):
23+
ctx = get_all()
24+
for i in range(size):
25+
ctx = set_baggage(f"foo{i}", f"bar{i}", context=ctx)
26+
return ctx
27+
28+
29+
def test_set_baggage(benchmark, baggage_size):
30+
ctx = benchmark(set_baggage_operation, baggage_size)
31+
result = get_all(ctx)
32+
assert len(result) == baggage_size
33+
34+
35+
def test_get_baggage(benchmark, baggage_size):
36+
ctx = set_baggage_operation(baggage_size)
37+
38+
def get_baggage_operation():
39+
return [get_baggage(f"foo{i}", ctx) for i in range(baggage_size)]
40+
41+
result = benchmark(get_baggage_operation)
42+
assert result == [f"bar{i}" for i in range(baggage_size)]
43+
44+
45+
def test_remove_baggage(benchmark, baggage_size):
46+
ctx = set_baggage_operation(baggage_size)
47+
48+
def remove_operation():
49+
tmp_ctx = ctx
50+
for i in range(baggage_size):
51+
tmp_ctx = remove_baggage(f"foo{i}", tmp_ctx)
52+
return tmp_ctx
53+
54+
cleared_context = benchmark(remove_operation)
55+
result = get_all(cleared_context)
56+
# After removing all baggage items, it should be empty.
57+
assert len(result) == 0
58+
59+
60+
def test_clear_baggage(benchmark, baggage_size):
61+
ctx = set_baggage_operation(baggage_size)
62+
63+
def clear_operation():
64+
return clear(ctx)
65+
66+
cleared_context = benchmark(clear_operation)
67+
result = get_all(cleared_context)
68+
# After clearing the baggage should be empty.
69+
assert len(result) == 0

pyproject.toml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,58 @@
1+
[project]
2+
name = "opentelemetry-python"
3+
version = "0.0.0" # This is not used.
4+
requires-python = ">=3.8"
5+
dependencies = [
6+
"opentelemetry-api",
7+
"opentelemetry-sdk",
8+
"opentelemetry-semantic-conventions",
9+
"opentelemetry-proto",
10+
"opentelemetry-test-utils",
11+
"opentelemetry-exporter-otlp-proto-grpc",
12+
"opentelemetry-exporter-otlp-proto-http",
13+
"opentelemetry-exporter-otlp-proto-common",
14+
"opentelemetry-exporter-zipkin-json",
15+
"opentelemetry-exporter-prometheus",
16+
"opentelemetry-propagator-jaeger",
17+
"opentelemetry-propagator-b3",
18+
]
19+
20+
# https://docs.astral.sh/uv/reference/settings/
21+
[tool.uv]
22+
package = false # https://docs.astral.sh/uv/reference/settings/#package
23+
required-version = ">=0.6.0"
24+
25+
[tool.uv.sources]
26+
opentelemetry-api = { workspace = true}
27+
opentelemetry-sdk = { workspace = true }
28+
opentelemetry-proto = { workspace = true }
29+
opentelemetry-semantic-conventions = { workspace = true }
30+
opentelemetry-test-utils = { workspace = true }
31+
opentelemetry-exporter-otlp-proto-grpc = { workspace = true }
32+
opentelemetry-exporter-otlp-proto-http = { workspace = true }
33+
opentelemetry-exporter-otlp-proto-common = { workspace = true }
34+
opentelemetry-exporter-zipkin-json = { workspace = true }
35+
opentelemetry-exporter-prometheus = {workspace = true }
36+
opentelemetry-propagator-jaeger = { workspace = true }
37+
opentelemetry-propagator-b3 = { workspace = true }
38+
39+
[tool.uv.workspace]
40+
members = [
41+
"opentelemetry-api",
42+
"opentelemetry-sdk",
43+
"opentelemetry-semantic-conventions",
44+
"opentelemetry-proto",
45+
"exporter/*",
46+
"propagator/*",
47+
"tests/opentelemetry-test-utils",
48+
]
49+
50+
exclude = [
51+
"exporter/opentelemetry-exporter-opencensus",
52+
"exporter/opentelemetry-exporter-zipkin",
53+
"exporter/opentelemetry-exporter-zipkin-proto-http",
54+
]
55+
156
[tool.pytest.ini_options]
257
addopts = "-rs -v"
358
log_cli = true

tox.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ envlist =
9595
public-symbols-check
9696
shellcheck
9797
generate-workflows
98-
ruff
98+
precommit
9999

100100
[testenv]
101101
deps =
@@ -361,7 +361,7 @@ commands =
361361
pyright --version
362362
pyright
363363

364-
[testenv:ruff]
364+
[testenv:{precommit,ruff}]
365365
basepython: python3
366366
deps =
367367
-c {toxinidir}/dev-requirements.txt

0 commit comments

Comments
 (0)