-
Notifications
You must be signed in to change notification settings - Fork 620
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
fastapi-slim support #2683
Comments
To anyone willing to tackle this, fixing it requires updating the package metadata in pyproject.toml |
Will open a PR for it |
|
Hi @gryevns, could you tell me how did you get this error? I would like to reproduce it in my laptop but failed. I run the small test with only installed fastapi-slim
didn't find the error |
Hey @xrmx, could you help have a look if this change looks good? from
to
and update the
to
|
@zhihali that looks correct, then you need to run |
@zhihali if you change $ python3 main.py
DependencyConflict: requested: "fastapi ~= 0.58" but found: "None"
INFO: Started server process [97435]
INFO: Waiting for application startup.
INFO: Application startup complete.
INFO: Uvicorn running on http://0.0.0.0:8001 (Press CTRL+C to quit) $ pip list
Package Version
------------------------------------- -------
annotated-types 0.7.0
anyio 4.4.0
asgiref 3.8.1
click 8.1.7
Deprecated 1.2.14
fastapi-slim 0.111.0
h11 0.14.0
idna 3.7
importlib_metadata 7.1.0
opentelemetry-api 1.25.0
opentelemetry-instrumentation 0.46b0
opentelemetry-instrumentation-asgi 0.46b0
opentelemetry-instrumentation-fastapi 0.46b0
opentelemetry-sdk 1.25.0
opentelemetry-semantic-conventions 0.46b0
opentelemetry-util-http 0.46b0
pip 23.1.2
pydantic 2.8.2
pydantic_core 2.20.1
setuptools 65.5.0
sniffio 1.3.1
starlette 0.37.2
typing_extensions 4.12.2
uvicorn 0.30.1
wrapt 1.16.0
zipp 3.19.2 |
I don't believe #2702 fixes this issue, given the latest release and the reproduction code above you will still see The issue seems to occur because the following resolves as true: Lines 288 to 289 in c45a620
However, the call when fetching the distrubution ( Line 50 in c45a620
|
@gryevns thanks for testing. Is |
Not sure I understand your question. This approach works for me: def instrumentation_dependencies(self) -> Collection[str]:
if find_spec("fastapi", package="fastapi-slim") is not None:
return (_fastapi_slim,)
if find_spec("fastapi") is not None:
return (_fastapi,)
return _instruments |
I thought you meant that the issue was in the |
After further debugging it seems we'd need to look at the distributions to work out if def instrumentation_dependencies(self) -> Collection[str]:
from pkg_resources import get_distribution
try:
get_distribution("fastapi-slim")
return (_fastapi_slim,)
except:
...
if find_spec("fastapi") is not None:
return (_fastapi,)
# If neither is installed, return both as potential dependencies
return _instruments |
I think it's because of how tox works:
tox -e py310-test-instrumentation-fastapi-slim:
And |
Implementation of this feature introduces bad bug that now when you have only So wrongly it now requires both Additionally it seems FastAPI are moving away from Here repository with reproduction https://github.com/smoke/fastapi-autoinstrumentation-fails |
@smoke I don't think such tragic tone is needed given the issue is closed with a pr fixing the issue already. Nice hint about the rename, if |
Because FastAPI has reverted this packaging decision maybe we can revert back to only supporting |
@xrmx The issue still exists with 0.47b0, here reproduction https://github.com/smoke/fastapi-autoinstrumentation-fails The thing is that _load_instrumentors uses So probably the next best and easy thing is to remove the |
@smoke This seems to be the best approach for me. Would you be willing to submit a PR for this? |
What problem do you want to solve?
FastAPI now includes a new CLI dependency by default. A new package
fastapi-slim
was created which excludes thefastapi-cli
dependency. We ideally want to use the newfastapi-slim
package and the existing open telemetry fastapi instrumentation.When trying to use this combination the open telemetry instrumentation fails to initialise because the expected package name is now different:
opentelemetry-python-contrib/instrumentation/opentelemetry-instrumentation-fastapi/src/opentelemetry/instrumentation/fastapi/package.py
Line 16 in eb8e456
Describe the solution you'd like
The open telemetry instrumentation for FastAPI should work with the
fastapi-slim
package and/or thefastapi
package.Describe alternatives you've considered
Can the FastAPI instrumentation be updated to work with either of the FastAPI packages or alternatively remove the check for the dependency completely?
Additional Context
No response
Would you like to implement a fix?
None
The text was updated successfully, but these errors were encountered: