dynatrace-oss / OneAgent-SDK-Python-AutoInstrumentation

autodynatrace, a python library that implements automatic instrumentation using the OneAgent SDK for Python
Other
62 stars 28 forks source link

Could not instrument psycopg2 #96

Open lorenzoBrugnera opened 8 months ago

lorenzoBrugnera commented 8 months ago

Hi,

I'm trying to use the autodynatrace to instrument some python code which have psycopg2 as imported library. During the instrumentation, both with the environment variable and by importing autodynatrace in the code, it results in a failure and autodynatrace cannot instrument psycopg2. Below you can find the logs:

[root@jobs-prod testdyna]# export AUTOWRAPT_BOOTSTRAP=autodynatrace;export AUTODYNATRACE_LOG_LEVEL=DEBUG;export AUTODYNATRACE_FORKABLE=True ; /home/airflow/kits/36env/bin/python /tmp/testdyna/MainProcess.py -d ApplicationData/AppData/db_prod.yaml -s ApplicationData/AppData/config_prod.yaml
2023-12-19 15:40:04,406: 10839 DEBUG autodynatrace - init: Initialized autodynatrace with AgentState: 1
2023-12-19 15:40:04,407: 10839 WARNING autodynatrace - init: Could not initialize the OneAgent SDK, AgentState: 1
2023-12-19 15:40:04,409: 10839 DEBUG autodynatrace - instrument_lib: Attempting to instrument urllib
2023-12-19 15:40:04,427: 10839 DEBUG autodynatrace - instrument_lib: Attempting to instrument subprocess
2023-12-19 15:40:04,428: 10839 INFO autodynatrace - instrument: Instrumented 2/23 libraries (subprocess, urllib). Will instrument when imported: (aiohttp, bottle, celery, confluent_kafka, cx_Oracle, django, fastapi, flask, grpc, paramiko, pika, psycopg2, pymongo, pysnmp, redis, ruxit, sqlalchemy, starlette, suds, tornado)
The Zen of Python, by Tim Peters

Beautiful is better than ugly.
Explicit is better than implicit.
Simple is better than complex.
Complex is better than complicated.
Flat is better than nested.
Sparse is better than dense.
Readability counts.
Special cases aren't special enough to break the rules.
Although practicality beats purity.
Errors should never pass silently.
Unless explicitly silenced.
In the face of ambiguity, refuse the temptation to guess.
There should be one-- and preferably only one --obvious way to do it.
Although that way may not be obvious at first unless you're Dutch.
Now is better than never.
Although never is often better than *right* now.
If the implementation is hard to explain, it's a bad idea.
If the implementation is easy to explain, it may be a good idea.
Namespaces are one honking great idea -- let's do more of those!
2023-12-19 15:40:04,974: 10839 DEBUG autodynatrace - dynatrace_trace: Tracing subprocess.Popen
2023-12-19 15:40:05,009: 10839 DEBUG autodynatrace - dynatrace_trace: Tracing subprocess.Popen
2023-12-19 15:40:05,042: 10839 DEBUG autodynatrace - dynatrace_trace: Tracing subprocess.Popen
2023-12-19 15:40:05,126: 10839 DEBUG autodynatrace - on_import: Instrumenting imported lib 'psycopg2'
2023-12-19 15:40:05,126: 10839 DEBUG autodynatrace - on_import: Could not instrument psycopg2
Traceback (most recent call last):
  File "/home/airflow/kits/36env/lib/python3.6/site-packages/autodynatrace/__init__.py", line 87, in on_import
    imported_module.instrument()
  File "/home/airflow/kits/36env/lib/python3.6/site-packages/autodynatrace/wrappers/psycopg2/wrapper.py", line 14, in instrument
    class DynatraceCursor(psycopg2.extra.DictCursorBase):
AttributeError: module 'psycopg2' has no attribute 'extra'
/home/airflow/kits/36env/lib/python3.6/site-packages/OpenSSL/_util.py:6: CryptographyDeprecationWarning: Python 3.6 is no longer supported by the Python core team. Therefore, support for it is deprecated in cryptography. The next release of cryptography will remove support for Python 3.6.
  from cryptography.hazmat.bindings.openssl.binding import Binding
['/tmp/testdyna/', 'ApplicationData/AppData/db_prod.yaml', 'ApplicationData/AppData/config_prod.yaml', 'log/', 'Output/']
{'endpoint': 'https://hkm95197.live.dynatrace.com/api/v2/metrics/ingest', 'mainName': 'timCityPoint', 'scriptName': 'meteoprovider', 'database': {'positive': 0, 'error': 1, 'funName': 'checkDB'}, 'api': {'positive': 0, 'error': 1, 'funName': 'checkAPI'}, 'script': {'positive': 0, 'error': 1, 'funName': 'checkProvider'}, 'token': 'xxxx'}
/home/airflow/kits/36env/lib/python3.6/site-packages/geopandas/geodataframe.py:1322: SettingWithCopyWarning:
A value is trying to be set on a copy of a slice from a DataFrame.
Try using .loc[row_indexer,col_indexer] = value instead

The autodynatrace used is: autodynatrace==2.0.0 and I tried to use the environment variable: AUTODYNATRACE_FORKABLE=True ## Tried changing it to True / False, but with limited success.

Thanks in advance for your help.

geppoz-it commented 7 months ago

Hi, I wonder if there is any news on this issue, I'm very interested too. Thanks, Giuseppe

dlopes7 commented 3 months ago

Published 2.0.2 with a fix