Skip to content

Commit 35c510f

Browse files
authored
Merge branch 'main' into bump-semantic-conv-1310
2 parents 331e24a + 2450943 commit 35c510f

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:
@@ -60,19 +60,36 @@ You can run `tox` with the following arguments:
6060
- `tox -e lint-some-package` to run lint checks on `some-package`
6161
- `tox -e generate-workflows` to run creation of new CI workflows if tox environments have been updated
6262
- `tox -e ruff` to run ruff linter and formatter checks against the entire codebase
63+
- `tox -e precommit` to run all `pre-commit` actions
6364

6465
`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:
6566

6667
```console
67-
$ pip install pre-commit -c dev-requirements.txt
68+
pip install pre-commit -c dev-requirements.txt
6869
```
6970

7071
and run this command inside the git repository:
7172

7273
```console
73-
$ pre-commit install
74+
pre-commit install
7475
```
7576

77+
### Virtual Environment
78+
79+
You can also create a single virtual environment to make it easier to run local tests.
80+
81+
For that, you'll need to install [`uv`](https://docs.astral.sh/uv/getting-started/installation/).
82+
83+
After installing `uv`, you can run the following command:
84+
85+
```sh
86+
uv sync
87+
```
88+
89+
This will create a virtual environment in the `.venv` directory and install all the necessary dependencies.
90+
91+
### Public Symbols
92+
7693
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.
7794
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.
7895

@@ -107,7 +124,7 @@ See
107124
[`tox.ini`](https://github.com/open-telemetry/opentelemetry-python/blob/main/tox.ini)
108125
for more detail on available tox commands.
109126

110-
#### Contrib repo
127+
### Contrib repo
111128

112129
Some of the `tox` targets install packages from the [OpenTelemetry Python Contrib Repository](https://github.com/open-telemetry/opentelemetry-python.git) via
113130
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
@@ -153,31 +170,45 @@ pull requests (PRs).
153170
To create a new PR, fork the project in GitHub and clone the upstream repo:
154171

155172
```console
156-
$ git clone https://github.com/open-telemetry/opentelemetry-python.git
157-
$ cd opentelemetry-python
173+
git clone https://github.com/open-telemetry/opentelemetry-python.git
174+
cd opentelemetry-python
158175
```
159176

160177
Add your fork as an origin:
161178

162179
```console
163-
$ git remote add fork https://github.com/YOUR_GITHUB_USERNAME/opentelemetry-python.git
180+
git remote add fork https://github.com/YOUR_GITHUB_USERNAME/opentelemetry-python.git
164181
```
165182

166-
Run tests:
183+
Make sure you have all supported versions of Python installed, install tox only for the first time:
167184

168185
```sh
169-
# make sure you have all supported versions of Python installed
170-
$ pip install tox # only first time.
171-
$ tox # execute in the root of the repository
186+
pip install tox
187+
```
188+
189+
Run tests in the root of the repository (this will run all tox environments and may take some time):
190+
191+
```sh
192+
tox
172193
```
173194

174195
Check out a new branch, make modifications and push the branch to your fork:
175196

176197
```sh
177-
$ git checkout -b feature
178-
# edit files
179-
$ git commit
180-
$ git push fork feature
198+
git checkout -b feature
199+
```
200+
201+
After you edit the files, stage changes in the current directory:
202+
203+
```sh
204+
git add .
205+
```
206+
207+
Then run the following to commit the changes:
208+
209+
```sh
210+
git commit
211+
git push fork feature
181212
```
182213

183214
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 =
@@ -358,7 +358,7 @@ commands =
358358
pyright --version
359359
pyright
360360

361-
[testenv:ruff]
361+
[testenv:{precommit,ruff}]
362362
basepython: python3
363363
deps =
364364
-c {toxinidir}/dev-requirements.txt

0 commit comments

Comments
 (0)