From 42faa1a34a711c35576833e56d0e28ea0cae4993 Mon Sep 17 00:00:00 2001 From: Diego Hurtado Date: Thu, 11 Jan 2024 13:03:28 -0600 Subject: [PATCH 1/2] Separate jobs per instrumentation (#2121) * Separate jobs per instrumentation Fixes #2036 * Separate in 2 workflows * Added explanation for separation --- .github/workflows/instrumentations_0.yml | 95 ++++++++++++++++++++++++ .github/workflows/instrumentations_1.yml | 57 ++++++++++++++ .github/workflows/test.yml | 83 --------------------- 3 files changed, 152 insertions(+), 83 deletions(-) create mode 100644 .github/workflows/instrumentations_0.yml create mode 100644 .github/workflows/instrumentations_1.yml diff --git a/.github/workflows/instrumentations_0.yml b/.github/workflows/instrumentations_0.yml new file mode 100644 index 0000000000..be5e3f7cb8 --- /dev/null +++ b/.github/workflows/instrumentations_0.yml @@ -0,0 +1,95 @@ +name: Contrib Repo Tests + +on: + push: + branches-ignore: + - 'release/*' + pull_request: +env: + CORE_REPO_SHA: 84c0e4f38d4fcdb8c13fd3988469fbb8cda28150 + +jobs: + instrumentations-0: + env: + # We use these variables to convert between tox and GHA version literals + py37: 3.7 + py38: 3.8 + py39: 3.9 + py310: "3.10" + py311: "3.11" + pypy3: pypy-3.7 + RUN_MATRIX_COMBINATION: ${{ matrix.python-version }}-${{ matrix.package }}-${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false # ensures the entire test matrix is run, even if one permutation fails + matrix: + python-version: [py37, py38, py39, py310, py311, pypy3] + package: + # Do not add more instrumentations here, add them in instrumentations_1.yml. + # The reason for this separation of instrumentations into more than one YAML file is + # the limit of jobs that can be run from a Github actions matrix: + # https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs + # "A matrix will generate a maximum of 256 jobs per workflow run. This limit applies + # to both GitHub-hosted and self-hosted runners." + - "aiohttp-client" + - "aiohttp-server" + - "aiopg" + - "aio-pika" + - "asgi" + - "asyncpg" + - "aws-lambda" + - "boto" + - "boto3sqs" + - "botocore" + - "cassandra" + - "celery" + - "confluent-kafka" + - "dbapi" + - "django" + - "elasticsearch" + - "falcon" + - "fastapi" + - "flask" + - "grpc" + - "httpx" + - "jinja2" + - "kafka-python" + - "logging" + - "mysql" + - "mysqlclient" + - "pika" + - "psycopg2" + - "pymemcache" + - "pymongo" + - "pymysql" + - "pyramid" + - "redis" + - "remoulade" + - "requests" + - "sklearn" + - "sqlalchemy" + - "sqlite3" + - "starlette" + - "system-metrics" + - "tornado" + - "tortoiseorm" + os: [ubuntu-20.04] + steps: + - name: Checkout Contrib Repo @ SHA - ${{ github.sha }} + uses: actions/checkout@v2 + - name: Set up Python ${{ env[matrix.python-version] }} + uses: actions/setup-python@v4 + with: + python-version: ${{ env[matrix.python-version] }} + - name: Install tox + run: pip install tox==3.27.1 tox-factor + - name: Cache tox environment + # Preserves .tox directory between runs for faster installs + uses: actions/cache@v1 + with: + path: | + .tox + ~/.cache/pip + key: v7-build-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', 'gen-requirements.txt', 'dev-requirements.txt') }} + - name: run tox + run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} -- -ra --benchmark-json=${{ env.RUN_MATRIX_COMBINATION }}-benchmark.json diff --git a/.github/workflows/instrumentations_1.yml b/.github/workflows/instrumentations_1.yml new file mode 100644 index 0000000000..d85897251b --- /dev/null +++ b/.github/workflows/instrumentations_1.yml @@ -0,0 +1,57 @@ +name: Contrib Repo Tests + +on: + push: + branches-ignore: + - 'release/*' + pull_request: +env: + CORE_REPO_SHA: 84c0e4f38d4fcdb8c13fd3988469fbb8cda28150 + +jobs: + instrumentations-1: + env: + # We use these variables to convert between tox and GHA version literals + py37: 3.7 + py38: 3.8 + py39: 3.9 + py310: "3.10" + py311: "3.11" + pypy3: pypy-3.7 + RUN_MATRIX_COMBINATION: ${{ matrix.python-version }}-${{ matrix.package }}-${{ matrix.os }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false # ensures the entire test matrix is run, even if one permutation fails + matrix: + python-version: [py37, py38, py39, py310, py311, pypy3] + package: + - "urllib" + - "urllib3" + - "wsgi" + - "distro" + - "richconsole" + - "prometheus-remote-write" + - "sdkextension-aws" + - "propagator-aws-xray" + - "propagator-ot-trace" + - "resource-detector-container" + os: [ubuntu-20.04] + steps: + - name: Checkout Contrib Repo @ SHA - ${{ github.sha }} + uses: actions/checkout@v2 + - name: Set up Python ${{ env[matrix.python-version] }} + uses: actions/setup-python@v4 + with: + python-version: ${{ env[matrix.python-version] }} + - name: Install tox + run: pip install tox==3.27.1 tox-factor + - name: Cache tox environment + # Preserves .tox directory between runs for faster installs + uses: actions/cache@v1 + with: + path: | + .tox + ~/.cache/pip + key: v7-build-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', 'gen-requirements.txt', 'dev-requirements.txt') }} + - name: run tox + run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} -- -ra --benchmark-json=${{ env.RUN_MATRIX_COMBINATION }}-benchmark.json diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3cf2e3c6b9..517e7e332d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,89 +9,6 @@ env: CORE_REPO_SHA: 84c0e4f38d4fcdb8c13fd3988469fbb8cda28150 jobs: - build: - env: - # We use these variables to convert between tox and GHA version literals - py37: 3.7 - py38: 3.8 - py39: 3.9 - py310: "3.10" - py311: "3.11" - pypy3: "pypy3.7" - RUN_MATRIX_COMBINATION: ${{ matrix.python-version }}-${{ matrix.package }}-${{ matrix.os }} - runs-on: ${{ matrix.os }} - strategy: - fail-fast: false # ensures the entire test matrix is run, even if one permutation fails - matrix: - python-version: [ py37, py38, py39, py310, py311, pypy3 ] - package: ["instrumentation", "distro", "exporter", "sdkextension", "propagator", "resource"] - os: [ ubuntu-20.04 ] - steps: - - name: Checkout Contrib Repo @ SHA - ${{ github.sha }} - uses: actions/checkout@v2 - - name: Set up Python ${{ env[matrix.python-version] }} - uses: actions/setup-python@v4 - with: - python-version: ${{ env[matrix.python-version] }} - - name: Install tox - run: pip install tox==3.27.1 tox-factor - - name: Cache tox environment - # Preserves .tox directory between runs for faster installs - uses: actions/cache@v1 - with: - path: | - .tox - ~/.cache/pip - key: v7-build-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', 'gen-requirements.txt', 'dev-requirements.txt') }} - - name: run tox - run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} -- -ra --benchmark-json=${{ env.RUN_MATRIX_COMBINATION }}-benchmark.json - # - name: Find and merge ${{ matrix.package }} benchmarks - # # TODO: Add at least one benchmark to every package type to remove this (#249) - # if: matrix.package == 'sdkextension' || matrix.package == 'propagator' - # run: >- - # mkdir -p benchmarks; - # jq -s '.[0].benchmarks = ([.[].benchmarks] | add) - # | if .[0].benchmarks == null then null else .[0] end' - # **/**/tests/*${{ matrix.package }}*-benchmark.json > benchmarks/output_${{ matrix.package }}.json - # - name: Upload all benchmarks under same key as an artifact - # if: ${{ success() }} - # uses: actions/upload-artifact@v2 - # with: - # name: benchmarks - # path: benchmarks/output_${{ matrix.package }}.json - # combine-benchmarks: - # runs-on: ubuntu-latest - # needs: build - # if: ${{ always() }} - # name: Combine benchmarks from previous build job - # steps: - # - name: Checkout Contrib Repo @ SHA - ${{ github.sha }} - # uses: actions/checkout@v2 - # - name: Download all benchmarks as artifact using key - # uses: actions/download-artifact@v2 - # with: - # name: benchmarks - # path: benchmarks - # - name: Find and merge all benchmarks - # run: >- - # jq -s '.[0].benchmarks = ([.[].benchmarks] | add) - # | if .[0].benchmarks == null then null else .[0] end' - # benchmarks/output_*.json > output.json; - # - name: Report on benchmark results - # uses: benchmark-action/github-action-benchmark@v1 - # with: - # name: OpenTelemetry Python Benchmarks - Python ${{ env[matrix.python-version ]}} - ${{ matrix.package }} - # tool: pytest - # output-file-path: output.json - # github-token: ${{ secrets.GITHUB_TOKEN }} - # max-items-in-chart: 100 - # # Alert with a commit comment on possible performance regression - # alert-threshold: 200% - # fail-on-alert: true - # # Make a commit on `gh-pages` with benchmarks from previous step - # auto-push: ${{ github.ref == 'refs/heads/main' }} - # gh-pages-branch: gh-pages - # benchmark-data-dir-path: benchmarks misc: strategy: fail-fast: false From c9d709a5c455e5c645a4dbe14af2d6a2af3ab41f Mon Sep 17 00:00:00 2001 From: Allen Kim Date: Wed, 17 Jan 2024 06:45:12 +0900 Subject: [PATCH 2/2] Feature/support for flask 3.0.0 (#2013) * support flask 3.0.0 * support flask 3.0.0 * support flask 3.0.0 * modify tox.ini * modify Werkzeug version * modify Werkzeug version * modify flask test version * modify flask version * modify flask version * modify CHANGELOG.md * include feedback * include feedback * Fix lint and generate --------- Co-authored-by: Diego Hurtado --- CHANGELOG.md | 2 ++ instrumentation/README.md | 2 +- .../pyproject.toml | 4 ++-- .../instrumentation/flask/__init__.py | 14 ++++++++++++-- .../instrumentation/flask/package.py | 2 +- .../instrumentation/bootstrap_gen.py | 4 ++-- tox.ini | 15 ++++++++++----- 7 files changed, 30 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 11363cc165..8ed9a4c205 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,6 +72,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `opentelemetry-resource-detector-azure` Add resource detectors for Azure App Service and VM ([#1901](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1901)) +- `opentelemetry-instrumentation-flask` Add support for Flask 3.0.0 + ([#152](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2013)) ## Version 1.19.0/0.40b0 (2023-07-13) - `opentelemetry-instrumentation-asgi` Add `http.server.request.size` metric diff --git a/instrumentation/README.md b/instrumentation/README.md index cc5ea02def..b3abf387bc 100644 --- a/instrumentation/README.md +++ b/instrumentation/README.md @@ -19,7 +19,7 @@ | [opentelemetry-instrumentation-elasticsearch](./opentelemetry-instrumentation-elasticsearch) | elasticsearch >= 2.0 | No | [opentelemetry-instrumentation-falcon](./opentelemetry-instrumentation-falcon) | falcon >= 1.4.1, < 4.0.0 | Yes | [opentelemetry-instrumentation-fastapi](./opentelemetry-instrumentation-fastapi) | fastapi ~= 0.58 | Yes -| [opentelemetry-instrumentation-flask](./opentelemetry-instrumentation-flask) | flask >= 1.0, < 3.0 | Yes +| [opentelemetry-instrumentation-flask](./opentelemetry-instrumentation-flask) | flask >= 1.0 | Yes | [opentelemetry-instrumentation-grpc](./opentelemetry-instrumentation-grpc) | grpcio ~= 1.27 | No | [opentelemetry-instrumentation-httpx](./opentelemetry-instrumentation-httpx) | httpx >= 0.18.0 | No | [opentelemetry-instrumentation-jinja2](./opentelemetry-instrumentation-jinja2) | jinja2 >= 2.7, < 4.0 | No diff --git a/instrumentation/opentelemetry-instrumentation-flask/pyproject.toml b/instrumentation/opentelemetry-instrumentation-flask/pyproject.toml index 015482c19c..528e08a313 100644 --- a/instrumentation/opentelemetry-instrumentation-flask/pyproject.toml +++ b/instrumentation/opentelemetry-instrumentation-flask/pyproject.toml @@ -35,8 +35,8 @@ dependencies = [ [project.optional-dependencies] instruments = [ - "flask >= 1.0, < 3.0", - "werkzeug < 3.0.0" + "werkzeug < 3.0.0", + "flask >= 1.0", ] test = [ "opentelemetry-instrumentation-flask[instruments]", diff --git a/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py b/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py index 5f16b14727..5e81cc5abe 100644 --- a/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py @@ -251,6 +251,16 @@ def response_hook(span: Span, status: str, response_headers: List): from opentelemetry import context, trace from opentelemetry.instrumentation.flask.package import _instruments from opentelemetry.instrumentation.flask.version import __version__ + +try: + flask_version = flask.__version__ +except AttributeError: + try: + from importlib import metadata + except ImportError: + import importlib_metadata as metadata + flask_version = metadata.version("flask") + from opentelemetry.instrumentation.instrumentor import BaseInstrumentor from opentelemetry.instrumentation.propagators import ( get_global_response_propagator, @@ -271,7 +281,7 @@ def response_hook(span: Span, status: str, response_headers: List): _excluded_urls_from_env = get_excluded_urls("FLASK") -if package_version.parse(flask.__version__) >= package_version.parse("2.2.0"): +if package_version.parse(flask_version) >= package_version.parse("2.2.0"): def _request_ctx_ref() -> weakref.ReferenceType: return weakref.ref(flask.globals.request_ctx._get_current_object()) @@ -420,7 +430,7 @@ def _before_request(): # https://flask.palletsprojects.com/en/1.1.x/api/#flask.has_request_context if flask and flask.request: if commenter_options.get("framework", True): - flask_info["framework"] = f"flask:{flask.__version__}" + flask_info["framework"] = f"flask:{flask_version}" if ( commenter_options.get("controller", True) and flask.request.endpoint diff --git a/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/package.py b/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/package.py index 33bfe4ccba..d83adbede0 100644 --- a/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/package.py +++ b/instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/package.py @@ -13,6 +13,6 @@ # limitations under the License. -_instruments = ("flask >= 1.0, < 3.0",) +_instruments = ("flask >= 1.0",) _supports_metrics = True diff --git a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py index 097ed49ef7..59c9c5e4df 100644 --- a/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py +++ b/opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py @@ -85,11 +85,11 @@ "instrumentation": "opentelemetry-instrumentation-fastapi==0.44b0.dev", }, { - "library": "flask >= 1.0, < 3.0", + "library": "werkzeug < 3.0.0", "instrumentation": "opentelemetry-instrumentation-flask==0.44b0.dev", }, { - "library": "werkzeug < 3.0.0", + "library": "flask >= 1.0", "instrumentation": "opentelemetry-instrumentation-flask==0.44b0.dev", }, { diff --git a/tox.ini b/tox.ini index 9541599f95..013b74e45d 100644 --- a/tox.ini +++ b/tox.ini @@ -89,6 +89,7 @@ envlist = ; opentelemetry-instrumentation-flask py3{7,8,9,10,11}-test-instrumentation-flask{213,220} + py3{8,9,10,11}-test-instrumentation-flask{300} pypy3-test-instrumentation-flask{213,220} ; opentelemetry-instrumentation-urllib @@ -273,7 +274,11 @@ deps = falcon2: falcon >=2.0.0,<3.0.0 falcon3: falcon >=3.0.0,<4.0.0 flask213: Flask ==2.1.3 - flask220: Flask >=2.2.0 + flask213: Werkzeug <3.0.0 + flask220: Flask ==2.2.0 + flask220: Werkzeug <3.0.0 + flask300: Flask >=3.0.0 + flask300: Werkzeug >=3.0.0 grpc: pytest-asyncio sqlalchemy11: sqlalchemy>=1.1,<1.2 sqlalchemy14: aiosqlite @@ -324,7 +329,7 @@ changedir = test-instrumentation-elasticsearch{2,5,6}: instrumentation/opentelemetry-instrumentation-elasticsearch/tests test-instrumentation-falcon{1,2,3}: instrumentation/opentelemetry-instrumentation-falcon/tests test-instrumentation-fastapi: instrumentation/opentelemetry-instrumentation-fastapi/tests - test-instrumentation-flask{213,220}: instrumentation/opentelemetry-instrumentation-flask/tests + test-instrumentation-flask{213,220,300}: instrumentation/opentelemetry-instrumentation-flask/tests test-instrumentation-urllib: instrumentation/opentelemetry-instrumentation-urllib/tests test-instrumentation-urllib3v{1,2}: instrumentation/opentelemetry-instrumentation-urllib3/tests test-instrumentation-grpc: instrumentation/opentelemetry-instrumentation-grpc/tests @@ -386,8 +391,8 @@ commands_pre = grpc: pip install {toxinidir}/instrumentation/opentelemetry-instrumentation-grpc[test] - falcon{1,2,3},flask{213,220},django{1,2,3,4},pyramid,tornado,starlette,fastapi,aiohttp,asgi,httpx{18,21},requests,urllib,urllib3v{1,2},wsgi: pip install {toxinidir}/util/opentelemetry-util-http[test] - wsgi,falcon{1,2,3},flask{213,220},django{1,2,3,4},pyramid: pip install {toxinidir}/instrumentation/opentelemetry-instrumentation-wsgi[test] + falcon{1,2,3},flask{213,220,300},django{1,2,3,4},pyramid,tornado,starlette,fastapi,aiohttp,asgi,httpx{18,21},requests,urllib,urllib3v{1,2},wsgi: pip install {toxinidir}/util/opentelemetry-util-http[test] + wsgi,falcon{1,2,3},flask{213,220,300},django{1,2,3,4},pyramid: pip install {toxinidir}/instrumentation/opentelemetry-instrumentation-wsgi[test] asgi,django{3,4},starlette,fastapi: pip install {toxinidir}/instrumentation/opentelemetry-instrumentation-asgi[test] asyncpg: pip install {toxinidir}/instrumentation/opentelemetry-instrumentation-asyncpg[test] @@ -401,7 +406,7 @@ commands_pre = falcon{1,2,3}: pip install {toxinidir}/instrumentation/opentelemetry-instrumentation-falcon[test] - flask{213,220}: pip install {toxinidir}/instrumentation/opentelemetry-instrumentation-flask[test] + flask{213,220,300}: pip install {toxinidir}/instrumentation/opentelemetry-instrumentation-flask[test] urllib: pip install {toxinidir}/instrumentation/opentelemetry-instrumentation-urllib[test]