Open vslavik opened 8 years ago
As a temporary workaround, agent-conf.json can specify a "libraries" option which you can use to disable psycopg2. There isn't a way to exclude a library yet, so you'll need to specify the ones you want. E.g. { ... "libraries": ["flask", "logging", ...] }
I have a related issue when using the psycopg2 instrumentation on Heroku.
I'm running Python 2.7 and psycopg2 2.6.1 (which is the latest version on PyPI and the version listed as "tested" in your readme). I'm using the librato-launch
integration.
[EXCEPTION] librato_python_web.instrumentor.bootstrap - Error instrumenting psycopg2
Traceback (most recent call last):
File "/app/.heroku/python/lib/python2.7/site-packages/librato_python_web/instrumentor/bootstrap.py", line 178, in import2
instrumentor.run()
File "/app/.heroku/python/lib/python2.7/site-packages/librato_python_web/instrumentor/data/psycopg2.py", line 55, in run
super(Psycopg2Instrumentor, self).run()
File "/app/.heroku/python/lib/python2.7/site-packages/librato_python_web/instrumentor/base_instrumentor.py", line 66, in run
override_classes(self.overridden_classes, self.wrapped)
File "/app/.heroku/python/lib/python2.7/site-packages/librato_python_web/instrumentor/instrument.py", line 108, in override_classes
wrap_methods(cls, targeted_methods, wrapped)
File "/app/.heroku/python/lib/python2.7/site-packages/librato_python_web/instrumentor/instrument.py", line 166, in wrap_methods
overrides[targeted_method] = wrapped_returned_instance(target, targeted_method, return_type, rules)
File "/app/.heroku/python/lib/python2.7/site-packages/librato_python_web/instrumentor/instrument.py", line 190, in wrapped_returned_instance
original_method = getattr(cls, targeted_method)
AttributeError: 'module' object has no attribute 'connect'
This is reproducible (occurs multiple times on every launch). Explicitly disabling the psycopg2 instrumentation with the libraries
option prevents it.
Thanks, Henrik. We'll investigate and provide a fix asap.
Hi Henrik. We've pushed version 0.40.2, which has a fix for this issue. Please let us know if that resolves the problem you're seeing. Thanks!
@vaidy4github Unfortunately, that didn't fix it. Using psycopg2==2.6.1
and librato-python-web==0.40.2
on Python 2.7, I'm getting the following (slighly different) stacktrace the first time I'm querying my Postgres DB:
ERROR [Web/django.request] Internal Server Error: /login/
Traceback (most recent call last):
File "/app/.heroku/python/lib/python2.7/site-packages/django/core/handlers/base.py", line 132, in get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
[... internal stack frames which lead to the first database call ...]
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/manager.py", line 127, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/app/.heroku/python/lib/python2.7/site-packages/librato_python_web/instrumentor/instrument.py", line 429, in wrapper
return f.__get__(self)(*args[1:], **keywords)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.py", line 328, in get
num = len(clone)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.py", line 144, in __len__
self._fetch_all()
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.py", line 965, in _fetch_all
self._result_cache = list(self.iterator())
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/query.py", line 238, in iterator
results = compiler.execute_sql()
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 840, in execute_sql
cursor.execute(sql, params)
File "/app/.heroku/python/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
return self.cursor.execute(sql, params)
File "/app/.heroku/python/lib/python2.7/site-packages/librato_python_web/instrumentor/instrument.py", line 435, in wrapper
return f(*args, **keywords)
TypeError: descriptor 'execute' requires a 'psycopg2.extensions.cursor' object but received a 'cursor'
+1 we're seeing this issue currently
Still getting this issue with librato-python-web==0.50 and psycopg2==2.7.1 on Heroku
I was able to work around by explicitly setting libraries without psycopg2 in agent-conf.json
My traceback:
TypeError: cursor() got an unexpected keyword argument 'cursor_factory'
File "django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
File "django/core/handlers/base.py", line 244, in _legacy_get_response
response = middleware_method(request)
File "temba/middleware.py", line 94, in process_request
if not user.is_anonymous():
File "django/utils/functional.py", line 238, in inner
self._setup()
File "django/utils/functional.py", line 386, in _setup
self._wrapped = self._setupfunc()
File "django/contrib/auth/middleware.py", line 24, in <lambda>
request.user = SimpleLazyObject(lambda: get_user(request))
File "django/contrib/auth/middleware.py", line 12, in get_user
request._cached_user = auth.get_user(request)
File "django/contrib/auth/__init__.py", line 217, in get_user
user = backend.get_user(user_id)
File "django/contrib/auth/backends.py", line 102, in get_user
user = UserModel._default_manager.get(pk=user_id)
File "django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(*args, **kwargs)
File "librato_python_web/instrumentor/instrument.py", line 161, in delegator
return wrapper_method(original_method, *args, **kwargs)
File "librato_python_web/instrumentor/instrument.py", line 109, in complex_wrapper
return func(*args, **keywords)
File "django/db/models/query.py", line 374, in get
num = len(clone)
File "django/db/models/query.py", line 232, in __len__
self._fetch_all()
File "django/db/models/query.py", line 1118, in _fetch_all
self._result_cache = list(self._iterable_class(self))
File "django/db/models/query.py", line 53, in __iter__
results = compiler.execute_sql(chunked_fetch=self.chunked_fetch)
File "django/db/models/sql/compiler.py", line 882, in execute_sql
cursor = self.connection.cursor()
File "django/db/backends/base/base.py", line 254, in cursor
return self._cursor()
File "django/db/backends/base/base.py", line 229, in _cursor
self.ensure_connection()
File "django/db/backends/base/base.py", line 213, in ensure_connection
self.connect()
File "django/db/backends/base/base.py", line 192, in connect
connection_created.send(sender=self.__class__, connection=self)
File "django/dispatch/dispatcher.py", line 193, in send
for receiver in self._live_receivers(sender)
File "django/contrib/postgres/signals.py", line 14, in register_type_handlers
register_hstore(connection.connection, globally=True, unicode=True)
File "psycopg2/extras.py", line 949, in register_hstore
oid = HstoreAdapter.get_oids(conn_or_curs)
File "psycopg2/extras.py", line 888, in get_oids
conn, curs = _solve_conn_curs(conn_or_curs)
File "psycopg2/extras.py", line 775, in _solve_conn_curs
curs = conn.cursor(cursor_factory=_cursor)
Using Python 3.4 and psycopg2 2.6.1, my application is getting exceptions pretty clearly related to proxy types used by the instrumentor:
They don't happen w/o Librato instrumentor enabled.
Details of relevant packages used: