Skip to content

Commit 3f5a227

Browse files
authored
Merge branch 'main' into fix-batchlogprocessor-gc
2 parents 5f21d78 + 2450943 commit 3f5a227

File tree

20 files changed

+1039
-173
lines changed

20 files changed

+1039
-173
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.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ Meeting notes are available as a public [Google doc](https://docs.google.com/doc
9797

9898
Approvers ([@open-telemetry/python-approvers](https://github.com/orgs/open-telemetry/teams/python-approvers)):
9999

100-
- [Emídio Neto](https://github.com/emdneto), Zenvia
100+
- [Emídio Neto](https://github.com/emdneto), PicPay
101101
- [Jeremy Voss](https://github.com/jeremydvoss), Microsoft
102102
- [Owais Lone](https://github.com/owais), Splunk
103103
- [Pablo Collins](https://github.com/pmcollins), Splunk

exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/metrics_encoder/__init__.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
14+
from __future__ import annotations
15+
1416
import logging
1517
from os import environ
1618
from typing import Dict, List
@@ -66,8 +68,9 @@
6668
class OTLPMetricExporterMixin:
6769
def _common_configuration(
6870
self,
69-
preferred_temporality: Dict[type, AggregationTemporality] = None,
70-
preferred_aggregation: Dict[type, Aggregation] = None,
71+
preferred_temporality: dict[type, AggregationTemporality]
72+
| None = None,
73+
preferred_aggregation: dict[type, Aggregation] | None = None,
7174
) -> None:
7275
MetricExporter.__init__(
7376
self,

exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/metric_exporter/__init__.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
1313

14+
from __future__ import annotations
15+
1416
from dataclasses import replace
1517
from logging import getLogger
1618
from os import environ
17-
from typing import Dict, Iterable, List, Optional, Tuple, Union
19+
from typing import Iterable, List, Tuple, Union
1820
from typing import Sequence as TypingSequence
1921

2022
from grpc import ChannelCredentials, Compression
@@ -92,17 +94,17 @@ class OTLPMetricExporter(
9294

9395
def __init__(
9496
self,
95-
endpoint: Optional[str] = None,
96-
insecure: Optional[bool] = None,
97-
credentials: Optional[ChannelCredentials] = None,
98-
headers: Optional[
99-
Union[TypingSequence[Tuple[str, str]], Dict[str, str], str]
100-
] = None,
101-
timeout: Optional[int] = None,
102-
compression: Optional[Compression] = None,
103-
preferred_temporality: Dict[type, AggregationTemporality] = None,
104-
preferred_aggregation: Dict[type, Aggregation] = None,
105-
max_export_batch_size: Optional[int] = None,
97+
endpoint: str | None = None,
98+
insecure: bool | None = None,
99+
credentials: ChannelCredentials | None = None,
100+
headers: Union[TypingSequence[Tuple[str, str]], dict[str, str], str]
101+
| None = None,
102+
timeout: int | None = None,
103+
compression: Compression | None = None,
104+
preferred_temporality: dict[type, AggregationTemporality]
105+
| None = None,
106+
preferred_aggregation: dict[type, Aggregation] | None = None,
107+
max_export_batch_size: int | None = None,
106108
):
107109
if insecure is None:
108110
insecure = environ.get(OTEL_EXPORTER_OTLP_METRICS_INSECURE)
@@ -146,7 +148,7 @@ def __init__(
146148
compression=compression,
147149
)
148150

149-
self._max_export_batch_size: Optional[int] = max_export_batch_size
151+
self._max_export_batch_size: int | None = max_export_batch_size
150152

151153
def _translate_data(
152154
self, data: MetricsData

exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1111
# See the License for the specific language governing permissions and
1212
# limitations under the License.
13+
from __future__ import annotations
1314

1415
import gzip
1516
import logging
@@ -23,7 +24,6 @@
2324
Dict,
2425
List,
2526
Mapping,
26-
Optional,
2727
Sequence,
2828
)
2929

@@ -101,16 +101,17 @@ class OTLPMetricExporter(MetricExporter, OTLPMetricExporterMixin):
101101

102102
def __init__(
103103
self,
104-
endpoint: Optional[str] = None,
105-
certificate_file: Optional[str] = None,
106-
client_key_file: Optional[str] = None,
107-
client_certificate_file: Optional[str] = None,
108-
headers: Optional[Dict[str, str]] = None,
109-
timeout: Optional[int] = None,
110-
compression: Optional[Compression] = None,
111-
session: Optional[requests.Session] = None,
112-
preferred_temporality: Dict[type, AggregationTemporality] = None,
113-
preferred_aggregation: Dict[type, Aggregation] = None,
104+
endpoint: str | None = None,
105+
certificate_file: str | None = None,
106+
client_key_file: str | None = None,
107+
client_certificate_file: str | None = None,
108+
headers: dict[str, str] | None = None,
109+
timeout: int | None = None,
110+
compression: Compression | None = None,
111+
session: requests.Session | None = None,
112+
preferred_temporality: dict[type, AggregationTemporality]
113+
| None = None,
114+
preferred_aggregation: dict[type, Aggregation] | None = None,
114115
):
115116
self._endpoint = endpoint or environ.get(
116117
OTEL_EXPORTER_OTLP_METRICS_ENDPOINT,
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

0 commit comments

Comments
 (0)