Bug: XRay SDK doesn't support pg8000 native driver
@leandrodamascena đang làm issue này rồi.
Từ ngày 20/1/2025.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
Bắt đầu bằng cách đọc aws_xray_sdk/ext/pg8000/patch.py, đặc biệt là cách xử lý pg8000.connect hiện có, sau đó so sánh với pg8000.native.Connection và điểm vào run của nó được mô tả trong issue. Hoàn thành có nghĩa là các kết nối native và các lệnh gọi run tạo ra các subsegment SQL X-Ray được ghi nhận giống như đường đi của Standard API.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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 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.
Check this code example:
from urllib.parse import quote_plus
import pg8000.native
from aws_xray_sdk.core import xray_recorder
from aws_xray_sdk.core import patch_all
# Initialize X-Ray
xray_recorder.configure(service='MyPostgresApp')
patch_all()
@xray_recorder.capture('connect_to_db')
def connect_to_db():
try:
host = "MYHOST"
user = "MYUSER"
database = "MYDATABASE"
password = "MYPASSWORD"
conn = pg8000.native.Connection(
database=database,
user=user,
password=password,
host=host,
port=5432,
ssl_context=True
)
return conn
except Exception as e:
print(f"Error connecting to database: {e}")
return None
@xray_recorder.capture('query_db')
def query_db(conn):
try:
results = conn.run("SELECT * FROM public.todos LIMIT 5")
return results
except Exception as e:
print(f"Error querying database: {e}")
return None
def main():
with xray_recorder.in_segment('main_function'):
conn = connect_to_db()
if conn:
results = query_db(conn)
if results:
print("Query results:", results)
conn.close()
if __name__ == "__main__":
main()
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.
{
"id":"caeb26df6fe242ed",
"name":"main_function",
"start_time":1736462563.884077,
"in_progress":false,
"aws":{
"xray":{
"sdk":"X-Ray for Python",
"sdk_version":"2.14.0"
}
},
"subsegments":[
{
"id":"981eb724c5369158",
"name":"connect_to_db",
"start_time":1736462563.884105,
"parent_id":"caeb26df6fe242ed",
"in_progress":false,
"trace_id":"1-678050e3-fbec3813f4280021b9069ff5",
"type":"subsegment",
"namespace":"local",
"end_time":1736462564.930994
},
{
"id":"eb5a8872a770eacd",
"name":"query_db",
"start_time":1736462564.931169,
"parent_id":"caeb26df6fe242ed",
"in_progress":false,
"trace_id":"1-678050e3-fbec3813f4280021b9069ff5",
"type":"subsegment",
"namespace":"local",
"end_time":1736462565.3793
}
],
"trace_id":"1-678050e3-fbec3813f4280021b9069ff5",
"service":{
"runtime":"CPython",
"runtime_version":"3.12.8"
},
"end_time":1736462565.3813171
}
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 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.
- Ngôn ngữ chính
- Python
- Star
- 340
- Fork
- 148
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của aws/aws-xray-sdk-python
-
psycopg connection context manager drops X-Ray tracing wrapper, so cursor execute calls are not tracedCó thể đã có người làm @reginaldalfret đã nhận 21 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
aws/aws-xray-sdk-python#490 · 1 bình luận ·
-
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 1/100
aws/aws-xray-sdk-python#460 ·
-
Next releaseĐang mở
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 20/100
aws/aws-xray-sdk-python#457 · 1 reaction ·
-
mysql-connector 9.2.0 - TypeError: 'MySQLConnection' object is not iterableCó thể đã có người làm @reginaldalfret đã nhận 21 ngày trước. Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
aws/aws-xray-sdk-python#453 ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
aws/aws-xray-sdk-python#452 · 1 reaction ·
Tất cả issue của aws/aws-xray-sdk-python
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
huggingface/sentence-transformers#4186 ·
Maintainer thường phản hồi trong vòng 5 ngày
-
documentation
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
QuantEcon/QuantEcon.py#988 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
fabriziosalmi/certmate#1247 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation good first issue
Độ khó 2/5 Nửa ngày Mức phù hợp với người mới 72/100
sujithputta02/Esapay#13 ·