You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
pg8000 comes with two APIs, the pg8000 native API and the DB-API 2.0 Standard API (PEP-0249) and the XRay SDK fails to capture SQL segments when using the pg8000 native API.
Explanation, code example and output
When working with the pg8000 native API, customers initialize a connection using pg8000.native.Connection and xray is unable to intercept and wrapper this because in this line it always considers pg8000.connect and not pg8000.native.Connection. Also, when using pg8000 native API the connection instance doesn't have cursor, all the queries are executed directly using run command.
This creates the json below and we see that there is no run subsegment in the query_db segment because XRAY cannot patch this driver when using native Connection.
I created a small PoC locally and made it work by adding a new method to wrap native.Connection and creating a new class called XRayTracedNative to intercept the run method and then be able to create the subsegment.
*the names are just suggestions, you can choose whatever name you want.
Please let me know if you are interested in a PR to implement this and I can work.
The text was updated successfully, but these errors were encountered:
leandrodamascena
changed the title
XRay SDK doesn't support pg8000 native driver
Bug: XRay SDK doesn't support pg8000 native driver
Jan 9, 2025
Summary
pg8000 comes with two APIs, the pg8000 native API and the DB-API 2.0 Standard API (PEP-0249) and the XRay SDK fails to capture SQL segments when using the pg8000 native API.
Explanation, code example and output
When working with the pg8000 native API, customers initialize a connection using
pg8000.native.Connection
and xray is unable to intercept and wrapper this because in this line it always considerspg8000.connect
and notpg8000.native.Connection
. Also, when using pg8000 native API the connection instance doesn't havecursor
, all the queries are executed directly usingrun
command.Check this code example:
This creates the json below and we see that there is no
run
subsegment in thequery_db
segment because XRAY cannot patch this driver when using native Connection.Solution
I created a small PoC locally and made it work by adding a new method to wrap
native.Connection
and creating a new class calledXRayTracedNative
to intercept the run method and then be able to create the subsegment.*the names are just suggestions, you can choose whatever name you want.
Please let me know if you are interested in a PR to implement this and I can work.
The text was updated successfully, but these errors were encountered: