Skip to content

Commit beaa519

Browse files
authored
Merge branch 'main' into feature/asyncio-instrumentation
2 parents e85b9d5 + c9d709a commit beaa519

File tree

10 files changed

+182
-96
lines changed

10 files changed

+182
-96
lines changed
+95
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
name: Contrib Repo Tests
2+
3+
on:
4+
push:
5+
branches-ignore:
6+
- 'release/*'
7+
pull_request:
8+
env:
9+
CORE_REPO_SHA: 84c0e4f38d4fcdb8c13fd3988469fbb8cda28150
10+
11+
jobs:
12+
instrumentations-0:
13+
env:
14+
# We use these variables to convert between tox and GHA version literals
15+
py37: 3.7
16+
py38: 3.8
17+
py39: 3.9
18+
py310: "3.10"
19+
py311: "3.11"
20+
pypy3: pypy-3.7
21+
RUN_MATRIX_COMBINATION: ${{ matrix.python-version }}-${{ matrix.package }}-${{ matrix.os }}
22+
runs-on: ${{ matrix.os }}
23+
strategy:
24+
fail-fast: false # ensures the entire test matrix is run, even if one permutation fails
25+
matrix:
26+
python-version: [py37, py38, py39, py310, py311, pypy3]
27+
package:
28+
# Do not add more instrumentations here, add them in instrumentations_1.yml.
29+
# The reason for this separation of instrumentations into more than one YAML file is
30+
# the limit of jobs that can be run from a Github actions matrix:
31+
# https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs
32+
# "A matrix will generate a maximum of 256 jobs per workflow run. This limit applies
33+
# to both GitHub-hosted and self-hosted runners."
34+
- "aiohttp-client"
35+
- "aiohttp-server"
36+
- "aiopg"
37+
- "aio-pika"
38+
- "asgi"
39+
- "asyncpg"
40+
- "aws-lambda"
41+
- "boto"
42+
- "boto3sqs"
43+
- "botocore"
44+
- "cassandra"
45+
- "celery"
46+
- "confluent-kafka"
47+
- "dbapi"
48+
- "django"
49+
- "elasticsearch"
50+
- "falcon"
51+
- "fastapi"
52+
- "flask"
53+
- "grpc"
54+
- "httpx"
55+
- "jinja2"
56+
- "kafka-python"
57+
- "logging"
58+
- "mysql"
59+
- "mysqlclient"
60+
- "pika"
61+
- "psycopg2"
62+
- "pymemcache"
63+
- "pymongo"
64+
- "pymysql"
65+
- "pyramid"
66+
- "redis"
67+
- "remoulade"
68+
- "requests"
69+
- "sklearn"
70+
- "sqlalchemy"
71+
- "sqlite3"
72+
- "starlette"
73+
- "system-metrics"
74+
- "tornado"
75+
- "tortoiseorm"
76+
os: [ubuntu-20.04]
77+
steps:
78+
- name: Checkout Contrib Repo @ SHA - ${{ github.sha }}
79+
uses: actions/checkout@v2
80+
- name: Set up Python ${{ env[matrix.python-version] }}
81+
uses: actions/setup-python@v4
82+
with:
83+
python-version: ${{ env[matrix.python-version] }}
84+
- name: Install tox
85+
run: pip install tox==3.27.1 tox-factor
86+
- name: Cache tox environment
87+
# Preserves .tox directory between runs for faster installs
88+
uses: actions/cache@v1
89+
with:
90+
path: |
91+
.tox
92+
~/.cache/pip
93+
key: v7-build-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', 'gen-requirements.txt', 'dev-requirements.txt') }}
94+
- name: run tox
95+
run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} -- -ra --benchmark-json=${{ env.RUN_MATRIX_COMBINATION }}-benchmark.json
+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
name: Contrib Repo Tests
2+
3+
on:
4+
push:
5+
branches-ignore:
6+
- 'release/*'
7+
pull_request:
8+
env:
9+
CORE_REPO_SHA: 84c0e4f38d4fcdb8c13fd3988469fbb8cda28150
10+
11+
jobs:
12+
instrumentations-1:
13+
env:
14+
# We use these variables to convert between tox and GHA version literals
15+
py37: 3.7
16+
py38: 3.8
17+
py39: 3.9
18+
py310: "3.10"
19+
py311: "3.11"
20+
pypy3: pypy-3.7
21+
RUN_MATRIX_COMBINATION: ${{ matrix.python-version }}-${{ matrix.package }}-${{ matrix.os }}
22+
runs-on: ${{ matrix.os }}
23+
strategy:
24+
fail-fast: false # ensures the entire test matrix is run, even if one permutation fails
25+
matrix:
26+
python-version: [py37, py38, py39, py310, py311, pypy3]
27+
package:
28+
- "urllib"
29+
- "urllib3"
30+
- "wsgi"
31+
- "distro"
32+
- "richconsole"
33+
- "prometheus-remote-write"
34+
- "sdkextension-aws"
35+
- "propagator-aws-xray"
36+
- "propagator-ot-trace"
37+
- "resource-detector-container"
38+
os: [ubuntu-20.04]
39+
steps:
40+
- name: Checkout Contrib Repo @ SHA - ${{ github.sha }}
41+
uses: actions/checkout@v2
42+
- name: Set up Python ${{ env[matrix.python-version] }}
43+
uses: actions/setup-python@v4
44+
with:
45+
python-version: ${{ env[matrix.python-version] }}
46+
- name: Install tox
47+
run: pip install tox==3.27.1 tox-factor
48+
- name: Cache tox environment
49+
# Preserves .tox directory between runs for faster installs
50+
uses: actions/cache@v1
51+
with:
52+
path: |
53+
.tox
54+
~/.cache/pip
55+
key: v7-build-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', 'gen-requirements.txt', 'dev-requirements.txt') }}
56+
- name: run tox
57+
run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} -- -ra --benchmark-json=${{ env.RUN_MATRIX_COMBINATION }}-benchmark.json

.github/workflows/test.yml

-83
Original file line numberDiff line numberDiff line change
@@ -9,89 +9,6 @@ env:
99
CORE_REPO_SHA: 84c0e4f38d4fcdb8c13fd3988469fbb8cda28150
1010

1111
jobs:
12-
build:
13-
env:
14-
# We use these variables to convert between tox and GHA version literals
15-
py37: 3.7
16-
py38: 3.8
17-
py39: 3.9
18-
py310: "3.10"
19-
py311: "3.11"
20-
pypy3: "pypy3.7"
21-
RUN_MATRIX_COMBINATION: ${{ matrix.python-version }}-${{ matrix.package }}-${{ matrix.os }}
22-
runs-on: ${{ matrix.os }}
23-
strategy:
24-
fail-fast: false # ensures the entire test matrix is run, even if one permutation fails
25-
matrix:
26-
python-version: [ py37, py38, py39, py310, py311, pypy3 ]
27-
package: ["instrumentation", "distro", "exporter", "sdkextension", "propagator", "resource"]
28-
os: [ ubuntu-20.04 ]
29-
steps:
30-
- name: Checkout Contrib Repo @ SHA - ${{ github.sha }}
31-
uses: actions/checkout@v2
32-
- name: Set up Python ${{ env[matrix.python-version] }}
33-
uses: actions/setup-python@v4
34-
with:
35-
python-version: ${{ env[matrix.python-version] }}
36-
- name: Install tox
37-
run: pip install tox==3.27.1 tox-factor
38-
- name: Cache tox environment
39-
# Preserves .tox directory between runs for faster installs
40-
uses: actions/cache@v1
41-
with:
42-
path: |
43-
.tox
44-
~/.cache/pip
45-
key: v7-build-tox-cache-${{ env.RUN_MATRIX_COMBINATION }}-${{ hashFiles('tox.ini', 'gen-requirements.txt', 'dev-requirements.txt') }}
46-
- name: run tox
47-
run: tox -f ${{ matrix.python-version }}-${{ matrix.package }} -- -ra --benchmark-json=${{ env.RUN_MATRIX_COMBINATION }}-benchmark.json
48-
# - name: Find and merge ${{ matrix.package }} benchmarks
49-
# # TODO: Add at least one benchmark to every package type to remove this (#249)
50-
# if: matrix.package == 'sdkextension' || matrix.package == 'propagator'
51-
# run: >-
52-
# mkdir -p benchmarks;
53-
# jq -s '.[0].benchmarks = ([.[].benchmarks] | add)
54-
# | if .[0].benchmarks == null then null else .[0] end'
55-
# **/**/tests/*${{ matrix.package }}*-benchmark.json > benchmarks/output_${{ matrix.package }}.json
56-
# - name: Upload all benchmarks under same key as an artifact
57-
# if: ${{ success() }}
58-
# uses: actions/upload-artifact@v2
59-
# with:
60-
# name: benchmarks
61-
# path: benchmarks/output_${{ matrix.package }}.json
62-
# combine-benchmarks:
63-
# runs-on: ubuntu-latest
64-
# needs: build
65-
# if: ${{ always() }}
66-
# name: Combine benchmarks from previous build job
67-
# steps:
68-
# - name: Checkout Contrib Repo @ SHA - ${{ github.sha }}
69-
# uses: actions/checkout@v2
70-
# - name: Download all benchmarks as artifact using key
71-
# uses: actions/download-artifact@v2
72-
# with:
73-
# name: benchmarks
74-
# path: benchmarks
75-
# - name: Find and merge all benchmarks
76-
# run: >-
77-
# jq -s '.[0].benchmarks = ([.[].benchmarks] | add)
78-
# | if .[0].benchmarks == null then null else .[0] end'
79-
# benchmarks/output_*.json > output.json;
80-
# - name: Report on benchmark results
81-
# uses: benchmark-action/github-action-benchmark@v1
82-
# with:
83-
# name: OpenTelemetry Python Benchmarks - Python ${{ env[matrix.python-version ]}} - ${{ matrix.package }}
84-
# tool: pytest
85-
# output-file-path: output.json
86-
# github-token: ${{ secrets.GITHUB_TOKEN }}
87-
# max-items-in-chart: 100
88-
# # Alert with a commit comment on possible performance regression
89-
# alert-threshold: 200%
90-
# fail-on-alert: true
91-
# # Make a commit on `gh-pages` with benchmarks from previous step
92-
# auto-push: ${{ github.ref == 'refs/heads/main' }}
93-
# gh-pages-branch: gh-pages
94-
# benchmark-data-dir-path: benchmarks
9512
misc:
9613
strategy:
9714
fail-fast: false

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7373

7474
- `opentelemetry-resource-detector-azure` Add resource detectors for Azure App Service and VM
7575
([#1901](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1901))
76+
- `opentelemetry-instrumentation-flask` Add support for Flask 3.0.0
77+
([#152](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2013))
7678

7779
## Version 1.19.0/0.40b0 (2023-07-13)
7880
- `opentelemetry-instrumentation-asgi` Add `http.server.request.size` metric

instrumentation/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
| [opentelemetry-instrumentation-elasticsearch](./opentelemetry-instrumentation-elasticsearch) | elasticsearch >= 2.0 | No
2121
| [opentelemetry-instrumentation-falcon](./opentelemetry-instrumentation-falcon) | falcon >= 1.4.1, < 4.0.0 | Yes
2222
| [opentelemetry-instrumentation-fastapi](./opentelemetry-instrumentation-fastapi) | fastapi ~= 0.58 | Yes
23-
| [opentelemetry-instrumentation-flask](./opentelemetry-instrumentation-flask) | flask >= 1.0, < 3.0 | Yes
23+
| [opentelemetry-instrumentation-flask](./opentelemetry-instrumentation-flask) | flask >= 1.0 | Yes
2424
| [opentelemetry-instrumentation-grpc](./opentelemetry-instrumentation-grpc) | grpcio ~= 1.27 | No
2525
| [opentelemetry-instrumentation-httpx](./opentelemetry-instrumentation-httpx) | httpx >= 0.18.0 | No
2626
| [opentelemetry-instrumentation-jinja2](./opentelemetry-instrumentation-jinja2) | jinja2 >= 2.7, < 4.0 | No

instrumentation/opentelemetry-instrumentation-flask/pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ dependencies = [
3535

3636
[project.optional-dependencies]
3737
instruments = [
38-
"flask >= 1.0, < 3.0",
39-
"werkzeug < 3.0.0"
38+
"werkzeug < 3.0.0",
39+
"flask >= 1.0",
4040
]
4141
test = [
4242
"opentelemetry-instrumentation-flask[instruments]",

instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/__init__.py

+12-2
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,16 @@ def response_hook(span: Span, status: str, response_headers: List):
251251
from opentelemetry import context, trace
252252
from opentelemetry.instrumentation.flask.package import _instruments
253253
from opentelemetry.instrumentation.flask.version import __version__
254+
255+
try:
256+
flask_version = flask.__version__
257+
except AttributeError:
258+
try:
259+
from importlib import metadata
260+
except ImportError:
261+
import importlib_metadata as metadata
262+
flask_version = metadata.version("flask")
263+
254264
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
255265
from opentelemetry.instrumentation.propagators import (
256266
get_global_response_propagator,
@@ -271,7 +281,7 @@ def response_hook(span: Span, status: str, response_headers: List):
271281

272282
_excluded_urls_from_env = get_excluded_urls("FLASK")
273283

274-
if package_version.parse(flask.__version__) >= package_version.parse("2.2.0"):
284+
if package_version.parse(flask_version) >= package_version.parse("2.2.0"):
275285

276286
def _request_ctx_ref() -> weakref.ReferenceType:
277287
return weakref.ref(flask.globals.request_ctx._get_current_object())
@@ -420,7 +430,7 @@ def _before_request():
420430
# https://flask.palletsprojects.com/en/1.1.x/api/#flask.has_request_context
421431
if flask and flask.request:
422432
if commenter_options.get("framework", True):
423-
flask_info["framework"] = f"flask:{flask.__version__}"
433+
flask_info["framework"] = f"flask:{flask_version}"
424434
if (
425435
commenter_options.get("controller", True)
426436
and flask.request.endpoint

instrumentation/opentelemetry-instrumentation-flask/src/opentelemetry/instrumentation/flask/package.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313
# limitations under the License.
1414

1515

16-
_instruments = ("flask >= 1.0, < 3.0",)
16+
_instruments = ("flask >= 1.0",)
1717

1818
_supports_metrics = True

opentelemetry-instrumentation/src/opentelemetry/instrumentation/bootstrap_gen.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,11 @@
8585
"instrumentation": "opentelemetry-instrumentation-fastapi==0.44b0.dev",
8686
},
8787
{
88-
"library": "flask >= 1.0, < 3.0",
88+
"library": "werkzeug < 3.0.0",
8989
"instrumentation": "opentelemetry-instrumentation-flask==0.44b0.dev",
9090
},
9191
{
92-
"library": "werkzeug < 3.0.0",
92+
"library": "flask >= 1.0",
9393
"instrumentation": "opentelemetry-instrumentation-flask==0.44b0.dev",
9494
},
9595
{

tox.ini

+10-5
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ envlist =
8989

9090
; opentelemetry-instrumentation-flask
9191
py3{7,8,9,10,11}-test-instrumentation-flask{213,220}
92+
py3{8,9,10,11}-test-instrumentation-flask{300}
9293
pypy3-test-instrumentation-flask{213,220}
9394

9495
; opentelemetry-instrumentation-urllib
@@ -276,7 +277,11 @@ deps =
276277
falcon2: falcon >=2.0.0,<3.0.0
277278
falcon3: falcon >=3.0.0,<4.0.0
278279
flask213: Flask ==2.1.3
279-
flask220: Flask >=2.2.0
280+
flask213: Werkzeug <3.0.0
281+
flask220: Flask ==2.2.0
282+
flask220: Werkzeug <3.0.0
283+
flask300: Flask >=3.0.0
284+
flask300: Werkzeug >=3.0.0
280285
grpc: pytest-asyncio
281286
sqlalchemy11: sqlalchemy>=1.1,<1.2
282287
sqlalchemy14: aiosqlite
@@ -327,7 +332,7 @@ changedir =
327332
test-instrumentation-elasticsearch{2,5,6}: instrumentation/opentelemetry-instrumentation-elasticsearch/tests
328333
test-instrumentation-falcon{1,2,3}: instrumentation/opentelemetry-instrumentation-falcon/tests
329334
test-instrumentation-fastapi: instrumentation/opentelemetry-instrumentation-fastapi/tests
330-
test-instrumentation-flask{213,220}: instrumentation/opentelemetry-instrumentation-flask/tests
335+
test-instrumentation-flask{213,220,300}: instrumentation/opentelemetry-instrumentation-flask/tests
331336
test-instrumentation-urllib: instrumentation/opentelemetry-instrumentation-urllib/tests
332337
test-instrumentation-urllib3v{1,2}: instrumentation/opentelemetry-instrumentation-urllib3/tests
333338
test-instrumentation-grpc: instrumentation/opentelemetry-instrumentation-grpc/tests
@@ -390,8 +395,8 @@ commands_pre =
390395

391396
grpc: pip install {toxinidir}/instrumentation/opentelemetry-instrumentation-grpc[test]
392397

393-
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]
394-
wsgi,falcon{1,2,3},flask{213,220},django{1,2,3,4},pyramid: pip install {toxinidir}/instrumentation/opentelemetry-instrumentation-wsgi[test]
398+
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]
399+
wsgi,falcon{1,2,3},flask{213,220,300},django{1,2,3,4},pyramid: pip install {toxinidir}/instrumentation/opentelemetry-instrumentation-wsgi[test]
395400
asgi,django{3,4},starlette,fastapi: pip install {toxinidir}/instrumentation/opentelemetry-instrumentation-asgi[test]
396401

397402
asyncpg: pip install {toxinidir}/instrumentation/opentelemetry-instrumentation-asyncpg[test]
@@ -405,7 +410,7 @@ commands_pre =
405410

406411
falcon{1,2,3}: pip install {toxinidir}/instrumentation/opentelemetry-instrumentation-falcon[test]
407412

408-
flask{213,220}: pip install {toxinidir}/instrumentation/opentelemetry-instrumentation-flask[test]
413+
flask{213,220,300}: pip install {toxinidir}/instrumentation/opentelemetry-instrumentation-flask[test]
409414

410415
urllib: pip install {toxinidir}/instrumentation/opentelemetry-instrumentation-urllib[test]
411416

0 commit comments

Comments
 (0)