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

FastAPI instrumentor import failure #1182

Closed
talboren opened this issue Jul 6, 2022 · 10 comments
Closed

FastAPI instrumentor import failure #1182

talboren opened this issue Jul 6, 2022 · 10 comments
Labels
bug Something isn't working

Comments

@talboren
Copy link

talboren commented Jul 6, 2022

Describe your environment
Python3.7
FastAPI
Opentelemtry v0.32b0

Steps to reproduce
When importing FastAPIInstrumentor
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
The exception below is being thrown

What is the actual behavior?
Exception is being thrown when importing FastAPI Instrumentor

Exception

Traceback (most recent call last):
  File "/home/anecdotes/.local/lib/python3.7/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
    worker.init_process()
  File "/home/anecdotes/.local/lib/python3.7/site-packages/uvicorn/workers.py", line 66, in init_process
    super(UvicornWorker, self).init_process()
  File "/home/anecdotes/.local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 119, in init_process
    self.load_wsgi()
  File "/home/anecdotes/.local/lib/python3.7/site-packages/gunicorn/workers/base.py", line 144, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/home/anecdotes/.local/lib/python3.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/home/anecdotes/.local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load
    return self.load_wsgiapp()
  File "/home/anecdotes/.local/lib/python3.7/site-packages/gunicorn/app/wsgiapp.py", line 39, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/home/anecdotes/.local/lib/python3.7/site-packages/gunicorn/util.py", line 358, in import_app
    mod = importlib.import_module(module)
  File "/usr/local/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/app/main.py", line 20, in <module>
    from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
  File "/home/anecdotes/.local/lib/python3.7/site-packages/opentelemetry/instrumentation/fastapi/__init__.py", line 138, in <module>
    from opentelemetry.instrumentation.asgi import OpenTelemetryMiddleware
  File "/home/anecdotes/.local/lib/python3.7/site-packages/opentelemetry/instrumentation/asgi/__init__.py", line 183, in <module>
    class ASGIGetter(Getter[dict]):
TypeError: 'ABCMeta' object is not subscriptable
@talboren talboren added the bug Something isn't working label Jul 6, 2022
@talboren
Copy link
Author

Can someone have a look on this one? 🙏🏼

@srikanthccv
Copy link
Member

This looks like a regression introduced in #1106 but I wonder how tests are passing?

@ocelotl
Copy link
Contributor

ocelotl commented Jul 13, 2022

@talboren I am having trouble reproducing this, please provide the output of pip freeze for a virtual environment where this happens and code that when run throws this exception.

@talboren
Copy link
Author

talboren commented Jul 13, 2022

@ocelotl

pip freeze:

aiohttp==3.8.1
aiosignal==1.2.0
alembic==1.8.1
anyio==3.6.1
asgiref==3.5.2
asn1crypto==1.4.0
async-timeout==4.0.2
asynctest==0.13.0
attrs==21.4.0
azure-common==1.1.27
azure-core==1.21.1
azure-storage-blob==12.9.0
backoff==1.10.0
beautifulsoup4==4.10.0
boto3==1.24.28
botocore==1.27.28
bytecode==0.13.0
CacheControl==0.12.10
cachetools==4.2.4
certifi==2020.12.5
cffi==1.15.0
chardet==3.0.4
charset-normalizer==2.0.10
click==8.1.3
clickclick==20.10.2
cloudflare==2.9.11
connexion==2.14.0
croniter==1.3.5
cryptography==3.2.1
ddsketch==2.0.3
ddtrace==1.2.2
Deprecated==1.2.13
elastic-apm==6.10.1
fastapi==0.78.0
firebase-admin==4.5.3
Flask==2.0.3
Flask-Injector==0.13.0
frozenlist==1.3.0
google-api-core==1.22.2
google-api-python-client==1.9.3
google-auth==1.35.0
google-auth-httplib2==0.1.0
google-cloud-core==1.7.2
google-cloud-datastore==2.3.0
google-cloud-firestore==2.1.3
google-cloud-iam==2.2.0
google-cloud-kms==1.4.0
google-cloud-pubsub==2.6.1
google-cloud-scheduler==2.2.0
google-cloud-secret-manager==1.0.0
google-cloud-storage==1.36.1
google-cloud-tasks==1.5.0
google-crc32c==1.3.0
google-resumable-media==1.3.3
googleapis-common-protos==1.54.0
greenlet==1.1.2
grpc-google-iam-v1==0.12.3
grpcio==1.43.0
gunicorn==20.0.4
h11==0.13.0
httplib2==0.20.2
httptools==0.4.0
idna==2.8
importlib-metadata==4.10.1
importlib-resources==5.4.0
inflection==0.5.1
injector==0.19.0
isodate==0.6.1
itsdangerous==2.0.1
Jinja2==3.0.3
jmespath==0.10.0
jsonlines==3.0.0
jsonpatch==1.32
jsonpointer==2.3
jsonschema==3.2.0
jwcrypto==1.0
libcst==0.4.0
Mako==1.1.6
MarkupSafe==2.0.1
msgpack==1.0.3
msrest==0.6.21
multidict==6.0.0
mypy-extensions==0.4.3
ndg-httpsclient==0.5.1
oauth2client==4.1.3
oauthlib==3.1.1
openapi-schema-validator==0.1.6
openapi-spec-validator==0.3.2
opentelemetry-api==1.11.1
opentelemetry-exporter-otlp==1.11.1
opentelemetry-exporter-otlp-proto-grpc==1.11.1
opentelemetry-exporter-otlp-proto-http==1.11.1
opentelemetry-instrumentation==0.30b1
opentelemetry-instrumentation-asgi==0.32b0
opentelemetry-instrumentation-fastapi==0.32b0
opentelemetry-instrumentation-flask==0.30b1
opentelemetry-instrumentation-logging==0.30b1
opentelemetry-instrumentation-requests==0.30b1
opentelemetry-instrumentation-sqlalchemy==0.30b1
opentelemetry-instrumentation-wsgi==0.30b1
opentelemetry-proto==1.11.1
opentelemetry-sdk==1.11.1
opentelemetry-semantic-conventions==0.30b1
opentelemetry-util-http==0.30b1
oscrypto==1.2.1
packaging==21.3
proto-plus==1.19.8
protobuf==3.20.1
pusher==3.2.0
pyasn1==0.4.8
pyasn1-modules==0.2.8
pycparser==2.21
pycryptodomex==3.12.0
pydantic==1.9.1
PyJWT==2.3.0
PyNaCl==1.5.0
pyOpenSSL==20.0.1
pyparsing==3.0.7
pyrsistent==0.16.1
python-dateutil==2.6.0
python-dotenv==0.20.0
python-json-logger==2.0.4
python-jwt==3.3.3
pytz==2021.3
PyYAML==5.4.1
requests==2.26.0
requests-oauthlib==1.3.0
rsa==4.8
s3transfer==0.6.0
six==1.16.0
sniffio==1.2.0
snowflake-connector-python==2.7.9
snowflake-sqlalchemy==1.3.4
soupsieve==2.3.1
SQLAlchemy==1.4.39
SQLAlchemy-Utils==0.38.3
starlette==0.19.1
starlette-context==0.3.4
tenacity==8.0.1
typing-extensions==4.0.1
typing-inspect==0.7.1
uritemplate==3.0.1
urllib3==1.26.5
uvicorn==0.18.2
uvloop==0.16.0
watchfiles==0.15.0
websockets==10.3
Werkzeug==2.0.3
wrapt==1.13.3
yarl==1.7.2
zipp==3.7.0

the code is basically just this:
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor

python version:
Python 3.7.12

Traceback (most recent call last):
File "main.py", line 20, in
from opentelemetry.instrumentation.fastapi import FastAPIInstrumentor
File "/home/anecdotes/.local/lib/python3.7/site-packages/opentelemetry/instrumentation/fastapi/init.py", line 138, in
from opentelemetry.instrumentation.asgi import OpenTelemetryMiddleware
File "/home/anecdotes/.local/lib/python3.7/site-packages/opentelemetry/instrumentation/asgi/init.py", line 183, in
class ASGIGetter(Getter[dict]):
TypeError: 'ABCMeta' object is not subscriptable

@alec-deason
Copy link

I'm seeing what appears to be the same exception on python 3.10.5 and this pip freeze:

aiofiles==0.7.0
alembic==1.7.5
anyio==3.6.1
asgiref==3.5.2
astroid==2.5.6
attrs==21.4.0
black==22.3.0
certifi==2022.6.15
cfgv==3.3.1
chardet==4.0.0
click==8.1.3
debugpy==1.5.1
Deprecated==1.2.13
distlib==0.3.4
expiringdict==1.1.4
fastapi==0.78.0
filelock==3.7.1
greenlet==1.1.2
gunicorn==20.1.0
h11==0.12.0
httpcore==0.13.7
httptools==0.3.0
httpx==0.18.2
identify==2.5.1
idna==2.10
iniconfig==1.1.1
isort==5.10.1
launchdarkly-server-sdk==7.4.0
lazy-object-proxy==1.7.1
lemminflect==0.2.2
Mako==1.2.1
MarkupSafe==2.1.1
mccabe==0.6.1
mypy==0.910
mypy-extensions==0.4.3
nodeenv==1.7.0
numpy==1.23.1
opentelemetry-api==1.11.1
opentelemetry-instrumentation==0.32b0
opentelemetry-instrumentation-asgi==0.32b0
opentelemetry-instrumentation-fastapi==0.32b0
opentelemetry-semantic-conventions==0.32b0
opentelemetry-util-http==0.32b0
packaging==21.3
pathspec==0.9.0
platformdirs==2.5.2
pluggy==0.13.1
pre-commit==2.18.1
psycopg2==2.9.1
py==1.11.0
pydantic==1.9.1
pylint==2.8.3
pyparsing==3.0.9
pyRFC3339==1.1
pytest==6.2.4
python-dotenv==0.20.0
pytz==2022.1
PyYAML==6.0
regex==2022.4.24
requests==2.25.1
rfc3986==1.5.0
semver==2.13.0
six==1.16.0
sniffio==1.2.0
SQLAlchemy==1.4.37
SQLAlchemy-Utils==0.38.2
starlette==0.19.1
toml==0.10.2
tomli==2.0.1
typing_extensions==4.3.0
urllib3==1.26.10
uvicorn==0.17.5
uvloop==0.16.0
virtualenv==20.15.1
watchgod==0.8.2
websockets==10.3
wrapt==1.12.1

@alec-deason
Copy link

I solved this by moving forward to 1.12.0rc2 for the various opentelemetry packages. Everything seems to work fine with that version.

@engelnico
Copy link

Thank you so much, that seems to have fixed the problem momentarily. Still very unfortunate that this happened

@talboren
Copy link
Author

@ocelotl doesn't make sense to me that a release candidate is the solution - shouldn't it be solved somehow?

@alec-deason
Copy link

If I'm understanding what's going on correctly it is actually a versioning problem. opentelemetry-instrumentation-fastapi==0.32b0 assumes that Getter is generic but in opentelemetry-sdk==1.11.1 it actually isn't yet, that doesn't get added until 1.12. So maybe there's actually a problem with version bounds somewhere that lead us both to have that broken combination installed.

@srikanthccv
Copy link
Member

There was a problem with version synchronization b/w core and contrib. This shouldn't be a problem with the latest stable release of the core reop. Please upgrade to the latest version. Re-open if the issue still exists.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants