fix: `fastapi` auto-instrumentation by removing `fastapi-slim` support (#2783)

This commit is contained in:
Radoslav Kirilov 2024-08-08 18:45:00 +03:00 committed by GitHub
parent fc1c8f0f3f
commit c238af5442
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 134 additions and 304 deletions

View File

@ -2194,8 +2194,8 @@ jobs:
- name: Run tests
run: tox -e pypy3-test-instrumentation-falcon-2 -- -ra
py38-test-instrumentation-fastapi-main_ubuntu-latest:
name: instrumentation-fastapi-main 3.8 Ubuntu
py38-test-instrumentation-fastapi_ubuntu-latest:
name: instrumentation-fastapi 3.8 Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
@ -2210,28 +2210,10 @@ jobs:
run: pip install tox
- name: Run tests
run: tox -e py38-test-instrumentation-fastapi-main -- -ra
run: tox -e py38-test-instrumentation-fastapi -- -ra
py38-test-instrumentation-fastapi-slim_ubuntu-latest:
name: instrumentation-fastapi-slim 3.8 Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4
- name: Set up Python 3.8
uses: actions/setup-python@v5
with:
python-version: "3.8"
- name: Install tox
run: pip install tox
- name: Run tests
run: tox -e py38-test-instrumentation-fastapi-slim -- -ra
py39-test-instrumentation-fastapi-main_ubuntu-latest:
name: instrumentation-fastapi-main 3.9 Ubuntu
py39-test-instrumentation-fastapi_ubuntu-latest:
name: instrumentation-fastapi 3.9 Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
@ -2246,28 +2228,10 @@ jobs:
run: pip install tox
- name: Run tests
run: tox -e py39-test-instrumentation-fastapi-main -- -ra
run: tox -e py39-test-instrumentation-fastapi -- -ra
py39-test-instrumentation-fastapi-slim_ubuntu-latest:
name: instrumentation-fastapi-slim 3.9 Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4
- name: Set up Python 3.9
uses: actions/setup-python@v5
with:
python-version: "3.9"
- name: Install tox
run: pip install tox
- name: Run tests
run: tox -e py39-test-instrumentation-fastapi-slim -- -ra
py310-test-instrumentation-fastapi-main_ubuntu-latest:
name: instrumentation-fastapi-main 3.10 Ubuntu
py310-test-instrumentation-fastapi_ubuntu-latest:
name: instrumentation-fastapi 3.10 Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
@ -2282,28 +2246,10 @@ jobs:
run: pip install tox
- name: Run tests
run: tox -e py310-test-instrumentation-fastapi-main -- -ra
run: tox -e py310-test-instrumentation-fastapi -- -ra
py310-test-instrumentation-fastapi-slim_ubuntu-latest:
name: instrumentation-fastapi-slim 3.10 Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"
- name: Install tox
run: pip install tox
- name: Run tests
run: tox -e py310-test-instrumentation-fastapi-slim -- -ra
py311-test-instrumentation-fastapi-main_ubuntu-latest:
name: instrumentation-fastapi-main 3.11 Ubuntu
py311-test-instrumentation-fastapi_ubuntu-latest:
name: instrumentation-fastapi 3.11 Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
@ -2318,28 +2264,10 @@ jobs:
run: pip install tox
- name: Run tests
run: tox -e py311-test-instrumentation-fastapi-main -- -ra
run: tox -e py311-test-instrumentation-fastapi -- -ra
py311-test-instrumentation-fastapi-slim_ubuntu-latest:
name: instrumentation-fastapi-slim 3.11 Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install tox
run: pip install tox
- name: Run tests
run: tox -e py311-test-instrumentation-fastapi-slim -- -ra
py312-test-instrumentation-fastapi-main_ubuntu-latest:
name: instrumentation-fastapi-main 3.12 Ubuntu
py312-test-instrumentation-fastapi_ubuntu-latest:
name: instrumentation-fastapi 3.12 Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
@ -2354,28 +2282,10 @@ jobs:
run: pip install tox
- name: Run tests
run: tox -e py312-test-instrumentation-fastapi-main -- -ra
run: tox -e py312-test-instrumentation-fastapi -- -ra
py312-test-instrumentation-fastapi-slim_ubuntu-latest:
name: instrumentation-fastapi-slim 3.12 Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install tox
run: pip install tox
- name: Run tests
run: tox -e py312-test-instrumentation-fastapi-slim -- -ra
pypy3-test-instrumentation-fastapi-main_ubuntu-latest:
name: instrumentation-fastapi-main pypy-3.8 Ubuntu
pypy3-test-instrumentation-fastapi_ubuntu-latest:
name: instrumentation-fastapi pypy-3.8 Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
@ -2390,25 +2300,7 @@ jobs:
run: pip install tox
- name: Run tests
run: tox -e pypy3-test-instrumentation-fastapi-main -- -ra
pypy3-test-instrumentation-fastapi-slim_ubuntu-latest:
name: instrumentation-fastapi-slim pypy-3.8 Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4
- name: Set up Python pypy-3.8
uses: actions/setup-python@v5
with:
python-version: "pypy-3.8"
- name: Install tox
run: pip install tox
- name: Run tests
run: tox -e pypy3-test-instrumentation-fastapi-slim -- -ra
run: tox -e pypy3-test-instrumentation-fastapi -- -ra
py38-test-instrumentation-flask-0_ubuntu-latest:
name: instrumentation-flask-0 3.8 Ubuntu
@ -4515,3 +4407,111 @@ jobs:
- name: Run tests
run: tox -e py311-test-instrumentation-pymemcache-2 -- -ra
py311-test-instrumentation-pymemcache-3_ubuntu-latest:
name: instrumentation-pymemcache-3 3.11 Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install tox
run: pip install tox
- name: Run tests
run: tox -e py311-test-instrumentation-pymemcache-3 -- -ra
py311-test-instrumentation-pymemcache-4_ubuntu-latest:
name: instrumentation-pymemcache-4 3.11 Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install tox
run: pip install tox
- name: Run tests
run: tox -e py311-test-instrumentation-pymemcache-4 -- -ra
py312-test-instrumentation-pymemcache-0_ubuntu-latest:
name: instrumentation-pymemcache-0 3.12 Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install tox
run: pip install tox
- name: Run tests
run: tox -e py312-test-instrumentation-pymemcache-0 -- -ra
py312-test-instrumentation-pymemcache-1_ubuntu-latest:
name: instrumentation-pymemcache-1 3.12 Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install tox
run: pip install tox
- name: Run tests
run: tox -e py312-test-instrumentation-pymemcache-1 -- -ra
py312-test-instrumentation-pymemcache-2_ubuntu-latest:
name: instrumentation-pymemcache-2 3.12 Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install tox
run: pip install tox
- name: Run tests
run: tox -e py312-test-instrumentation-pymemcache-2 -- -ra
py312-test-instrumentation-pymemcache-3_ubuntu-latest:
name: instrumentation-pymemcache-3 3.12 Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install tox
run: pip install tox
- name: Run tests
run: tox -e py312-test-instrumentation-pymemcache-3 -- -ra

View File

@ -16,114 +16,6 @@ env:
jobs:
py311-test-instrumentation-pymemcache-3_ubuntu-latest:
name: instrumentation-pymemcache-3 3.11 Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install tox
run: pip install tox
- name: Run tests
run: tox -e py311-test-instrumentation-pymemcache-3 -- -ra
py311-test-instrumentation-pymemcache-4_ubuntu-latest:
name: instrumentation-pymemcache-4 3.11 Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v5
with:
python-version: "3.11"
- name: Install tox
run: pip install tox
- name: Run tests
run: tox -e py311-test-instrumentation-pymemcache-4 -- -ra
py312-test-instrumentation-pymemcache-0_ubuntu-latest:
name: instrumentation-pymemcache-0 3.12 Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install tox
run: pip install tox
- name: Run tests
run: tox -e py312-test-instrumentation-pymemcache-0 -- -ra
py312-test-instrumentation-pymemcache-1_ubuntu-latest:
name: instrumentation-pymemcache-1 3.12 Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install tox
run: pip install tox
- name: Run tests
run: tox -e py312-test-instrumentation-pymemcache-1 -- -ra
py312-test-instrumentation-pymemcache-2_ubuntu-latest:
name: instrumentation-pymemcache-2 3.12 Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install tox
run: pip install tox
- name: Run tests
run: tox -e py312-test-instrumentation-pymemcache-2 -- -ra
py312-test-instrumentation-pymemcache-3_ubuntu-latest:
name: instrumentation-pymemcache-3 3.12 Ubuntu
runs-on: ubuntu-latest
steps:
- name: Checkout repo @ SHA - ${{ github.sha }}
uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.12"
- name: Install tox
run: pip install tox
- name: Run tests
run: tox -e py312-test-instrumentation-pymemcache-3 -- -ra
py312-test-instrumentation-pymemcache-4_ubuntu-latest:
name: instrumentation-pymemcache-4 3.12 Ubuntu
runs-on: ubuntu-latest

View File

@ -17,14 +17,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Fixed
- `opentelemetry-instrumentation-fastapi` fix `fastapi` auto-instrumentation by removing `fastapi-slim` support, `fastapi-slim` itself is discontinued from maintainers
([2783](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2783))
- `opentelemetry-instrumentation-aws-lambda` Avoid exception when a handler is not present.
([#2750](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2750))
- `opentelemetry-instrumentation-django` Fix regression - `http.target` re-added back to old semconv duration metrics
([#2746](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2746))
- `opentelemetry-instrumentation-grpc` Fixes the issue with the gRPC instrumentation not working with the 1.63.0 and higher version of gRPC
([#2483](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2484))
- `opentelemetry-instrumentation-fastapi` Fix fastapi-slim support
([#2756](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2756))
- `opentelemetry-instrumentation-aws-lambda` Fixing w3c baggage support
([#2589](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2589))
- `opentelemetry-instrumentation-celery` propagates baggage

View File

@ -19,7 +19,7 @@
| [opentelemetry-instrumentation-django](./opentelemetry-instrumentation-django) | django >= 1.10 | Yes | experimental
| [opentelemetry-instrumentation-elasticsearch](./opentelemetry-instrumentation-elasticsearch) | elasticsearch >= 6.0 | No | experimental
| [opentelemetry-instrumentation-falcon](./opentelemetry-instrumentation-falcon) | falcon >= 1.4.1, < 4.0.0 | Yes | experimental
| [opentelemetry-instrumentation-fastapi](./opentelemetry-instrumentation-fastapi) | fastapi ~= 0.58,fastapi-slim ~= 0.111 | Yes | migration
| [opentelemetry-instrumentation-fastapi](./opentelemetry-instrumentation-fastapi) | fastapi ~= 0.58 | Yes | migration
| [opentelemetry-instrumentation-flask](./opentelemetry-instrumentation-flask) | flask >= 1.0 | Yes | migration
| [opentelemetry-instrumentation-grpc](./opentelemetry-instrumentation-grpc) | grpcio ~= 1.27 | No | experimental
| [opentelemetry-instrumentation-httpx](./opentelemetry-instrumentation-httpx) | httpx >= 0.18.0 | No | migration

View File

@ -35,7 +35,6 @@ dependencies = [
[project.optional-dependencies]
instruments = [
"fastapi ~= 0.58",
"fastapi-slim ~= 0.111",
]
[project.entry-points.opentelemetry_instrumentor]

View File

@ -179,7 +179,6 @@ API
from __future__ import annotations
import logging
from importlib.metadata import PackageNotFoundError, distribution
from typing import Collection
import fastapi
@ -197,11 +196,7 @@ from opentelemetry.instrumentation.asgi.types import (
ClientResponseHook,
ServerRequestHook,
)
from opentelemetry.instrumentation.fastapi.package import (
_fastapi,
_fastapi_slim,
_instruments,
)
from opentelemetry.instrumentation.fastapi.package import _instruments
from opentelemetry.instrumentation.fastapi.version import __version__
from opentelemetry.instrumentation.instrumentor import BaseInstrumentor
from opentelemetry.metrics import get_meter
@ -298,21 +293,6 @@ class FastAPIInstrumentor(BaseInstrumentor):
app._is_instrumented_by_opentelemetry = False
def instrumentation_dependencies(self) -> Collection[str]:
# need to use distribution because find_spec("fastapi") will return
# something even with just fastapi-slim installed
try:
distribution("fastapi-slim")
return (_fastapi_slim,)
except PackageNotFoundError:
pass
try:
distribution("fastapi")
return (_fastapi,)
except PackageNotFoundError:
pass
# If neither is installed, return both as potential dependencies
return _instruments
def _instrument(self, **kwargs):

View File

@ -13,10 +13,7 @@
# limitations under the License.
_fastapi = "fastapi ~= 0.58"
_fastapi_slim = "fastapi-slim ~= 0.111"
_instruments = (_fastapi, _fastapi_slim)
_instruments = ("fastapi ~= 0.58",)
_supports_metrics = True

View File

@ -1,32 +0,0 @@
annotated-types==0.6.0
anyio==4.3.0
asgiref==3.7.2
certifi==2024.7.4
charset-normalizer==3.3.2
Deprecated==1.2.14
exceptiongroup==1.2.0
fastapi-slim==0.111.0
h11==0.14.0
httpcore==1.0.4
httpx==0.27.0
idna==3.7
importlib-metadata==6.11.0
iniconfig==2.0.0
packaging==24.0
pluggy==1.5.0
py-cpuinfo==9.0.0
pydantic==2.6.2
pydantic_core==2.16.3
pytest==7.4.4
requests==2.32.3
sniffio==1.3.0
starlette==0.37.2
tomli==2.0.1
typing_extensions==4.9.0
urllib3==2.2.2
wrapt==1.16.0
zipp==3.19.2
-e opentelemetry-instrumentation
-e instrumentation/opentelemetry-instrumentation-asgi
-e util/opentelemetry-util-http
-e instrumentation/opentelemetry-instrumentation-fastapi

View File

@ -84,10 +84,6 @@ libraries = [
"library": "fastapi ~= 0.58",
"instrumentation": "opentelemetry-instrumentation-fastapi==0.48b0.dev",
},
{
"library": "fastapi-slim ~= 0.111",
"instrumentation": "opentelemetry-instrumentation-fastapi==0.48b0.dev",
},
{
"library": "flask >= 1.0",
"instrumentation": "opentelemetry-instrumentation-flask==0.48b0.dev",

View File

@ -112,8 +112,8 @@ envlist =
lint-instrumentation-falcon
; opentelemetry-instrumentation-fastapi
py3{8,9,10,11,12}-test-instrumentation-fastapi-{main,slim}
pypy3-test-instrumentation-fastapi-{main,slim}
py3{8,9,10,11,12}-test-instrumentation-fastapi
pypy3-test-instrumentation-fastapi
lint-instrumentation-fastapi
; opentelemetry-instrumentation-flask
@ -556,9 +556,7 @@ commands_pre =
fastapi: pip install opentelemetry-semantic-conventions@{env:CORE_REPO}\#egg=opentelemetry-semantic-conventions&subdirectory=opentelemetry-semantic-conventions
fastapi: pip install opentelemetry-sdk@{env:CORE_REPO}\#egg=opentelemetry-sdk&subdirectory=opentelemetry-sdk
fastapi: pip install opentelemetry-test-utils@{env:CORE_REPO}\#egg=opentelemetry-test-utils&subdirectory=tests/opentelemetry-test-utils
fastapi-main: pip install -r {toxinidir}/instrumentation/opentelemetry-instrumentation-fastapi/test-requirements.txt
fastapi-slim: pip install -r {toxinidir}/instrumentation/opentelemetry-instrumentation-fastapi/test-requirements-slim.txt
lint-instrumentation-fastapi: pip install -r {toxinidir}/instrumentation/opentelemetry-instrumentation-fastapi/test-requirements.txt
fastapi: pip install -r {toxinidir}/instrumentation/opentelemetry-instrumentation-fastapi/test-requirements.txt
mysql: pip install opentelemetry-api@{env:CORE_REPO}\#egg=opentelemetry-api&subdirectory=opentelemetry-api
mysql: pip install opentelemetry-semantic-conventions@{env:CORE_REPO}\#egg=opentelemetry-semantic-conventions&subdirectory=opentelemetry-semantic-conventions