diff --git a/.pylintrc b/.pylintrc index 9f6c80faa9..39ea7b5d35 100644 --- a/.pylintrc +++ b/.pylintrc @@ -45,6 +45,9 @@ suggestion-mode=yes # active Python interpreter and may run arbitrary code. unsafe-load-any-extension=no +# Run python dependant checks considering the baseline version +py-version=3.8 + [MESSAGES CONTROL] diff --git a/CHANGELOG.md b/CHANGELOG.md index 32ccd766e5..aace8e7fc2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -20,6 +20,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ([#2573](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2573)) - `opentelemetry-instrumentation-confluent-kafka` Add support for version 2.4.0 of confluent_kafka ([#2616](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2616)) +- `opentelemetry-instrumentation-confluent-kafka` Add support for produce purge + ([#2638](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2638)) ### Breaking changes diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1cc77b184a..f5a4913440 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -60,13 +60,13 @@ $ pip install tox You can run `tox` with the following arguments: -- `tox` to run all existing tox commands, including unit tests for all packages +* `tox` to run all existing tox commands, including unit tests for all packages under multiple Python versions -- `tox -e docs` to regenerate the API docs -- `tox -e py312-test-instrumentation-aiopg` to e.g. run the aiopg instrumentation unit tests under a specific +* `tox -e docs` to regenerate the API docs +* `tox -e py312-test-instrumentation-aiopg` to e.g. run the aiopg instrumentation unit tests under a specific Python version -- `tox -e spellcheck` to run a spellcheck on all the code -- `tox -e lint-some-package` to run lint checks on `some-package` +* `tox -e spellcheck` to run a spellcheck on all the code +* `tox -e lint-some-package` to run lint checks on `some-package` `black` and `isort` are executed when `tox -e lint` is run. The reported errors can be tedious to fix manually. An easier way to do so is: @@ -84,6 +84,7 @@ You can also configure it to run lint tools automatically before committing with ```console $ pre-commit install +``` See [`tox.ini`](https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/tox.ini) @@ -161,6 +162,7 @@ Open a pull request against the main `opentelemetry-python-contrib` repo. * If the PR is not ready for review, please put `[WIP]` in the title, tag it as `work-in-progress`, or mark it as [`draft`](https://github.blog/2019-02-14-introducing-draft-pull-requests/). +* Make sure tests and lint are passing locally before requesting a review. * Make sure CLA is signed and CI is clear. ### How to Get PRs Reviewed @@ -216,13 +218,26 @@ For a deeper discussion, see: https://github.com/open-telemetry/opentelemetry-sp 2. Make sure you have `tox` installed. `pip install tox`. 3. Run `tox` without any arguments to run tests for all the packages. Read more about [tox](https://tox.readthedocs.io/en/latest/). +Some tests can be slow due to pre-steps that do dependencies installs. To help with that, you can run tox a first time, and after that run the tests using previous installed dependencies in toxdir as following: + +1. First time run (e.g., opentelemetry-instrumentation-aiopg) +```console +tox -e py312-test-instrumentation-aiopg +``` +2. Run tests again without pre-steps: +```console +.tox/py312-test-instrumentation-aiopg/bin/pytest instrumentation/opentelemetry-instrumentation-aiopg +``` + ### Testing against a different Core repo branch/commit Some of the tox targets install packages from the [OpenTelemetry Python Core Repository](https://github.com/open-telemetry/opentelemetry-python) via 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 with a specific git commit hash by setting an environment variable before running tox as per the following example: +```sh CORE_REPO_SHA=c49ad57bfe35cfc69bfa863d74058ca9bec55fc3 tox +``` -The continuation integration overrides that environment variable with as per the configuration [here](https://github.com/open-telemetry/opentelemetry-python-contrib/blob/2518a4ac07cb62ad6587dd8f6cbb5f8663a7e179/.github/workflows/test.yml#L9). +The continuous integration overrides that environment variable with as per the configuration [here](https://github.com/open-telemetry/opentelemetry-python-contrib/blob/main/.github/workflows/test.yml#L9). ## Style Guide @@ -260,3 +275,24 @@ Below is a checklist of things to be mindful of when implementing a new instrume ## Expectations from contributors OpenTelemetry is an open source community, and as such, greatly encourages contributions from anyone interested in the project. With that being said, there is a certain level of expectation from contributors even after a pull request is merged, specifically pertaining to instrumentations. The OpenTelemetry Python community expects contributors to maintain a level of support and interest in the instrumentations they contribute. This is to ensure that the instrumentation does not become stale and still functions the way the original contributor intended. Some instrumentations also pertain to libraries that the current members of the community are not so familiar with, so it is necessary to rely on the expertise of the original contributing parties. + +## Updating supported Python versions + +### Bumping the Python baseline + +When updating the minimum supported Python version remember to: + +- Remove the version in `pyproject.toml` trove classifiers +- Remove the version from `tox.ini` +- Search for `sys.version_info` usage and remove code for unsupported versions +- Bump `py-version` in `.pylintrc` for Python version dependent checks + +### Adding support for a new Python release + +When adding support for a new Python release remember to: + +- Add the version in `tox.ini` +- Add the version in `pyproject.toml` trove classifiers +- Update github workflows accordingly; lint and benchmarks use the latest supported version +- Update `.pre-commit-config.yaml` +- Update tox examples in the documentation diff --git a/README.md b/README.md index 133acf81f6..6c019239ae 100644 --- a/README.md +++ b/README.md @@ -46,7 +46,6 @@ The Python auto-instrumentation libraries for [OpenTelemetry](https://openteleme * [Releasing](#releasing) * [Releasing a package as `1.0` stable](#releasing-a-package-as-10-stable) * [Contributing](#contributing) -* [Running Tests Locally](#running-tests-locally) * [Thanks to all the people who already contributed](#thanks-to-all-the-people-who-already-contributed) ## Installation @@ -143,14 +142,6 @@ Emeritus Maintainers: *Find more about the maintainer role in [community repository](https://github.com/open-telemetry/community/blob/main/community-membership.md#maintainer).* -## Running Tests Locally - -1. Go to your Contrib repo directory. `cd ~/git/opentelemetry-python-contrib`. -2. Create a virtual env in your Contrib repo directory. `python3 -m venv my_test_venv`. -3. Activate your virtual env. `source my_test_venv/bin/activate`. -4. Make sure you have `tox` installed. `pip install tox`. -5. Run tests for a package. (e.g. `tox -e test-instrumentation-flask`.) - ### Thanks to all the people who already contributed diff --git a/instrumentation/opentelemetry-instrumentation-confluent-kafka/src/opentelemetry/instrumentation/confluent_kafka/__init__.py b/instrumentation/opentelemetry-instrumentation-confluent-kafka/src/opentelemetry/instrumentation/confluent_kafka/__init__.py index 30181d39c2..45d45ccb63 100644 --- a/instrumentation/opentelemetry-instrumentation-confluent-kafka/src/opentelemetry/instrumentation/confluent_kafka/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-confluent-kafka/src/opentelemetry/instrumentation/confluent_kafka/__init__.py @@ -156,6 +156,9 @@ def flush(self, timeout=-1): def poll(self, timeout=-1): return self._producer.poll(timeout) + def purge(self, in_queue=True, in_flight=True, blocking=True): + self._producer.purge(in_queue, in_flight, blocking) + def produce( self, topic, value=None, *args, **kwargs ): # pylint: disable=keyword-arg-before-vararg diff --git a/tox.ini b/tox.ini index 54d2354952..e18bdf6a6f 100644 --- a/tox.ini +++ b/tox.ini @@ -761,6 +761,11 @@ commands_pre = processor-baggage: pip install opentelemetry-sdk@{env:CORE_REPO}\#egg=opentelemetry-sdk&subdirectory=opentelemetry-sdk processor-baggage: pip install -r {toxinidir}/processor/opentelemetry-processor-baggage/test-requirements.txt + http: pip install opentelemetry-api@{env:CORE_REPO}\#egg=opentelemetry-api&subdirectory=opentelemetry-api + http: pip install opentelemetry-semantic-conventions@{env:CORE_REPO}\#egg=opentelemetry-semantic-conventions&subdirectory=opentelemetry-semantic-conventions + http: pip install opentelemetry-sdk@{env:CORE_REPO}\#egg=opentelemetry-sdk&subdirectory=opentelemetry-sdk + http: pip install opentelemetry-test-utils@{env:CORE_REPO}\#egg=opentelemetry-test-utils&subdirectory=tests/opentelemetry-test-utils + http: pip install -r {toxinidir}/util/opentelemetry-util-http/test-requirements.txt http: pip install {toxinidir}/util/opentelemetry-util-http ; In order to get a health coverage report, diff --git a/util/opentelemetry-util-http/test-requirements.txt b/util/opentelemetry-util-http/test-requirements.txt new file mode 100644 index 0000000000..0e28bbdd05 --- /dev/null +++ b/util/opentelemetry-util-http/test-requirements.txt @@ -0,0 +1,12 @@ +asgiref==3.7.2 +Deprecated==1.2.14 +importlib-metadata==6.11.0 +iniconfig==2.0.0 +packaging==24.0 +pluggy==1.5.0 +py-cpuinfo==9.0.0 +pytest==7.4.4 +pytest-benchmark==4.0.0 +tomli==2.0.1 +typing_extensions==4.10.0 +-e opentelemetry-instrumentation \ No newline at end of file diff --git a/util/opentelemetry-util-http/tests/test_sanitize_method.py b/util/opentelemetry-util-http/tests/test_sanitize_method.py index b4095324a6..bd14d88ee5 100644 --- a/util/opentelemetry-util-http/tests/test_sanitize_method.py +++ b/util/opentelemetry-util-http/tests/test_sanitize_method.py @@ -32,7 +32,7 @@ def test_standard_method_lowercase(self): def test_nonstandard_method(self): method = sanitize_method("UNKNOWN") - self.assertEqual(method, "NONSTANDARD") + self.assertEqual(method, "_OTHER") @patch.dict( "os.environ", @@ -42,4 +42,4 @@ def test_nonstandard_method(self): ) def test_nonstandard_method_allowed(self): method = sanitize_method("UNKNOWN") - self.assertEqual(method, "NONSTANDARD") + self.assertEqual(method, "UNKNOWN")