DataDog / dd-trace-py

Datadog Python APM Client
https://ddtrace.readthedocs.io/
Other
552 stars 414 forks source link

Unable to instrument graphql (graphql-core 1.1, graphql-relay 0.5.0)? #7626

Closed wrkhenddher closed 1 year ago

wrkhenddher commented 1 year ago

Summary of problem

AttributeError: module 'graphql.graphql' has no attribute 'execute_graphql'

Which version of dd-trace-py are you using?

2.1.7

Which version of pip are you using?

22.0.4

Which libraries and their versions are you using?

aiosmtpd==1.4.4.post2 alabaster==0.7.13 atpublic==4.0 attrs==22.2.0 authutils==2.3.1 Babel==2.12.1 backports.tempfile==1.0 backports.weakref==1.0.post1 bamrest==2.2.0 boto==2.49.0 boto3==1.28.2 botocore==1.31.2 bytecode==0.15.1 cachetools==5.3.2 cattrs==23.1.2 cdiserrors==1.0.0 cdislogging==1.0.0 certifi==2023.7.22 cffi==1.15.1 chardet==5.2.0 charset-normalizer==3.3.1 click==7.1.2 colorama==0.4.6 coverage==7.2.7 cryptography==3.3.2 ddsketch==2.0.4 ddtrace==2.1.7 debtcollector==2.5.0 decorator==5.1.1 deepdiff==6.5.0 defusedcsv==2.0.0 Deprecated==1.2.14 dicttoxml==1.7.4 distlib==0.3.7 docutils==0.20.1 elasticsearch==7.6.0 Envelopes==0.4 envier==0.4.0 exceptiongroup==1.1.2 filelock==3.13.1 Flask==1.1.4 Flask-Cors==3.0.10 freezegun==1.2.2 ... gitdb==4.0.11 gitdb2==3.0.3.post1 GitPython==3.1.40 graphene==1.4.1 graphql-core==1.1 graphql-relay==0.5.0 graphviz==0.20.1 httmock==1.4.0 idna==3.4 imagesize==1.4.1 importlib-metadata==6.8.0 importlib-resources==5.13.0 ... iniconfig==2.0.0 iso8601==2.1.0 itsdangerous==1.1.0 Jinja2==2.11.3 jmespath==1.0.1 jsonschema==3.2.0 keystoneauth1==5.3.0 MarkupSafe==2.0.1 mergedeep==1.3.4 more-itertools==8.14.0 moto==4.1.12 msgpack==1.0.7 netaddr==0.9.0 netifaces==0.11.0 normalizer==4.0.2 numpy==1.24.4 opentelemetry-api==1.21.0 ordered-set==4.1.0 os-service-types==1.7.0 oslo.config==9.2.0 oslo.i18n==6.1.0 oslo.serialization==5.2.0 oslo.utils==6.2.1 packaging==23.2 pbr==5.11.1 pip==22.0.4 platformdirs==3.11.0 pluggy==1.3.0 promise==2.3 protobuf==4.24.4 ... psycopg2==2.9.9 pycparser==2.21 Pygments==2.15.1 PyJWT==2.8.0 pyparsing==3.1.1 pyproject-api==1.6.1 pyrsistent==0.20.0 pytest==7.4.0 pytest-cov==4.1.0 pytest-env==0.8.2 pytest-flask==1.2.0 pytest-localserver==0.7.1 python-dateutil==2.8.2 python-keystoneclient==5.2.0 pytz==2020.5 PyYAML==5.3.1 requests==2.31.0 responses==0.23.1 rfc3986==2.0.0 rstr==3.2.2 s3transfer==0.6.1 scipy==1.10.1 setuptools==56.0.0 simplejson==3.19.2 six==1.16.0 smmap==5.0.1 smmap2==2.0.5 snowballstemmer==2.2.0 Sphinx==3.0.4 sphinxcontrib-applehelp==1.0.4 sphinxcontrib-devhelp==1.0.2 sphinxcontrib-htmlhelp==2.0.1 sphinxcontrib-jsmath==1.0.1 sphinxcontrib-qthelp==1.0.3 sphinxcontrib-serializinghtml==1.1.5 SQLAlchemy==1.3.24 SQLAlchemy-Utils==0.41.1 stevedore==5.1.0 SurvivalPy==2.0.0 tenacity==8.2.3 tomli==2.0.1 tox==4.11.3 types-PyYAML==6.0.12.10 typing_extensions==4.8.0 tzdata==2023.3 urllib3==1.26.16 virtualenv==20.24.6 Werkzeug==0.16.0 wrapt==1.15.0 xlocal==0.5 xmltodict==0.13.0 zipp==3.17.0

How can we reproduce your problem?

NA - problem happens when we attempt to use latest ddtrace. ddtrace 1.7.5 works. The issue happens when we run pytest -vvv -l -p no:ddtrace -p no:ddtrace.pytest_bdd

What is the result that you get?

AttributeError: module 'graphql.graphql' has no attribute 'execute_graphql'

What is the result that you expected?

Tests run normally.

backtrace

(collected by appending --pdb -x to pytest ...)

(Pdb) bt                                                                                                    [71/93799]
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/_pytest/runner.py(341)from_call()
-> result: Optional[TResult] = func()                                                                                 
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/_pytest/runner.py(262)<lambda>() 
-> lambda: ihook(item=item, **kwds), when=when, reraise=reraise                                                       
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/pluggy/_hooks.py(493)__call__()  
-> return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)                                             
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/pluggy/_manager.py(115)_hookexec(
)                                                                                                                     
-> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)                                               
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/pluggy/_callers.py(152)_multicall
()                                                                                                                    
-> return outcome.get_result()                                                                                        
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/pluggy/_result.py(114)get_result(
)                                                                                                                     
-> raise exc.with_traceback(exc.__traceback__)                                                                        
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/pluggy/_callers.py(77)_multicall(
)                                                                                                                     
-> res = hook_impl.function(*args)                                                                                    
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/_pytest/runner.py(157)pytest_runt
est_setup()                                                                                                           
-> item.session._setupstate.setup(item)                                                                               
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/_pytest/runner.py(497)setup()    
-> raise exc                                                                                                          
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/_pytest/runner.py(494)setup()    
-> col.setup()                                                                                                        
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/_pytest/python.py(1791)setup()   
-> self._request._fillfixtures()                                                                                      
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/_pytest/fixtures.py(566)_fillfixt
ures()                                                                                                                
-> item.funcargs[argname] = self.getfixturevalue(argname)                                                             
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/_pytest/fixtures.py(585)getfixtur
evalue()                                                                                                              
-> fixturedef = self._get_active_fixturedef(argname)                                                                  
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/_pytest/fixtures.py(607)_get_acti
ve_fixturedef()                                                                                                       
-> self._compute_fixture_value(fixturedef)                                                                            
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/_pytest/fixtures.py(693)_compute_
fixture_value() 
-> fixturedef.execute(request=subrequest)                                                                             
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/_pytest/fixtures.py(1045)execute(
)                                                                                                                     -> fixturedef = request._get_active_fixturedef(argname)
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/_pytest/fixtures.py(607)_get_acti
ve_fixturedef()                                                                                                       
-> self._compute_fixture_value(fixturedef)
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/_pytest/fixtures.py(693)_compute_fixture_value()
-> fixturedef.execute(request=subrequest)
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/_pytest/fixtures.py(1069)execute()                    
-> result = ihook.pytest_fixture_setup(fixturedef=self, request=request)
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/pluggy/_hooks.py(493)__call__()  -> return self._hookexec(self.name, self._hookimpls, kwargs, firstresult)
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/pluggy/_manager.py(115)_hookexec(
)                                                                                                                     -> return self._inner_hookexec(hook_name, methods, kwargs, firstresult)
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/pluggy/_callers.py(152)_multicall
()                                                                                                                    -> return outcome.get_result()
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/pluggy/_result.py(114)get_result(
)                                                                                                                     -> raise exc.with_traceback(exc.__traceback__)
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/pluggy/_callers.py(77)_multicall(
)             
-> res = hook_impl.function(*args)                                                                                      /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/_pytest/fixtures.py(1123)pytest_fixture_setup()                                                                                                        
-> result = call_fixture_func(fixturefunc, request, kwargs) 
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/_pytest/fixtures.py(902)call_fixture_func()                                                                                                            -> fixture_result = fixturefunc(**kwargs)                                                                             
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/indexd_test_utils/__init__.py(157
)indexd_server()
-> app = get_app()
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/src/indexd/indexd/app.py(42)get_app()
-> app_init(app, settings)
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/src/indexd/indexd/app.py(18)app_init()
-> ddtrace.patch_all()
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/ddtrace/_monkey.py(211)patch_all()
-> patch(raise_errors=False, **modules)
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/ddtrace/_monkey.py(239)patch()
-> when_imported(module)(
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/ddtrace/vendor/wrapt/importer.py(284)register()
-> register_post_import_hook(hook, name)
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/ddtrace/vendor/wrapt/decorators.py(470)_synchronized()
-> return wrapped(*args, **kwargs)
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/ddtrace/vendor/wrapt/importer.py(82)register_post_import_hook()
-> hook(module)
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/ddtrace/_monkey.py(167)on_import()
-> imported_module.patch()
  /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/ddtrace/contrib/graphql/patch.py(81)patch()
-> _update_patching(wrap, module_str, func_name, wrapper)
> /Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/ddtrace/contrib/graphql/patch.py(112)_update_patching()
-> func = getattr(module, func_name)
(Pdb) locals()
{'operation': <function wrap at 0x16fcfcf70>, 'module_str': 'graphql.graphql', 'func_name': 'execute_graphql', 'wrapper': <function _traced_query at 0x16fd108b0>, 'module': <module 'graphql.graphql' from '/Users/henddher/Documents/github/gdcapi_gene_expr/venv/lib/python3.8/site-packages/graphql/graphql.py'>}
(Pdb) 
mabdinur commented 1 year ago

Hey @wrkhenddher,

This is expected (docs). ddtrace does not support graphql-core==1.1.0. GraphQL-core-next was deprecated 4 years ago. The graphql integration can be disabled by setting the following environment variable: DD_TRACE_GRAPHQL_ENABLED=False

To enable the graphql integration you will need to install graphql-core>=2.0