Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/support for flask 3.0.0 #2013

Merged
merged 19 commits into from
Jan 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion instrumentation/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ dependencies = [

[project.optional-dependencies]
instruments = [
"flask >= 1.0, < 3.0",
"werkzeug < 3.0.0"
"werkzeug < 3.0.0",
ocelotl marked this conversation as resolved.
Show resolved Hide resolved
"flask >= 1.0",
]
test = [
"opentelemetry-instrumentation-flask[instruments]",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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())
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@
# limitations under the License.


_instruments = ("flask >= 1.0, < 3.0",)
_instruments = ("flask >= 1.0",)

_supports_metrics = True
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@
"instrumentation": "opentelemetry-instrumentation-fastapi==0.44b0.dev",
},
{
"library": "flask >= 1.0, < 3.0",
"library": "werkzeug < 3.0.0",
ocelotl marked this conversation as resolved.
Show resolved Hide resolved
"instrumentation": "opentelemetry-instrumentation-flask==0.44b0.dev",
},
{
"library": "werkzeug < 3.0.0",
"library": "flask >= 1.0",
"instrumentation": "opentelemetry-instrumentation-flask==0.44b0.dev",
},
{
Expand Down
15 changes: 10 additions & 5 deletions tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
bourbonkk marked this conversation as resolved.
Show resolved Hide resolved
grpc: pytest-asyncio
sqlalchemy11: sqlalchemy>=1.1,<1.2
sqlalchemy14: aiosqlite
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand All @@ -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]

Expand Down
Loading