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

OneAgent SDK causing breaking changes with DB cursors #76

Open alon-selfinc opened 1 year ago

alon-selfinc commented 1 year ago

Hi! We are trying to incorporate the OneAgent SDK into our codebase. Currently on oneagent-sdk~=1.5.0.20221221.150433, psycopg2==2.9.5 running on Python 3.7.2.

Our create_app() flask function essentially runs this:

import oneagent

init_result = oneagent.initialize()
sdk = oneagent.get_sdk()

After incorporating the SDK, all of our DAO objects/queries are behaving differently. We can no longer pull a field value by name out of a DB cursor:

odfi_uuid = None if dfi is None else dfi['uuid']
E       TypeError: tuple indices must be integers or slices, not str

We'd really appreciate any suggestions on tackling the issue. Please let me know if I can further clarify anything here. Thanks!

dlopes7 commented 1 year ago

I am having a hard time reproducing, would you mind sharing a piece of code that allows you to access the rows like that?

When I run

cur = conn.cursor()
cur.execute("SELECT tablename, tableowner FROM pg_catalog.pg_tables")
for row in cur:
    print(row['tablename'])

I get the same error as you, even without autodynatrace installed

dlopes7 commented 1 year ago

Are you per chance using

cursor_factory=RealDictCursor # or DictCursor

In the connection creation? I think I was able to reproduce by using that, and will look to implement a fix

alon-selfinc commented 1 year ago

@dlopes7 you are correct! we are using DictCursor. sorry I should have clarified in my initial post. thanks so much for investigating!

caseycoding commented 1 year ago

Hi @dlopes7! There might be a minor misspelling in this update: extras vs extra. Is it ok if we make MRs for you to review going forward? Don't want to toss it all your way. Thanks!

davetonkin-LC commented 1 year ago

@dlopes7 - Hi - just checking to see if you saw Casey's last comment. Are you able to reopen this and/or create a new issue to address the misspelling that he mentioned?