Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

psycopg connection context manager drops X-Ray tracing wrapper, so cursor execute calls are not traced

オープン
#490 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
68/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
aws, python
領域
observability

調査の方向性

patch() と XRayTracedConn 周りの psycopg 統合から始め、その後、issue に記載されている with conn as c: のフローを再現します。入力された接続がラップされたまま維持され、そのカーソルがトレースされ、execute() が手動計装なしでネイティブのデータベースサブセグメントを生成すれば完了です。

索引モデルが issue の本文から書いたものです。

説明

I am seeing a gap in the psycopg integration for aws-xray-sdk.

When patching psycopg succeeds, psycopg.connect() returns an XRayTracedConn proxy as expected. However, if the connection is used as a context manager with with conn as c:, the object returned from enter is the raw psycopg Connection, not the X-Ray wrapper. As a result, c.cursor(...) returns a raw psycopg Cursor, and execute() calls do not produce X-Ray subsegments.

Observed behavior

patch(("psycopg",), raise_errors=True) succeeds
psycopg.connect() returns aws_xray_sdk.ext.dbapi2.XRayTracedConn
entering the connection context manager unwraps the proxy
cursor() on that entered object returns psycopg.Cursor
execute() on the cursor is not traced
if I create an explicit subsegment manually, that subsegment appears in X-Ray, which confirms the request has a valid segment and the DB code path is running

Expected behavior

The psycopg X-Ray wrapper should preserve tracing across the connection context manager
with conn as c: should still return a wrapped connection, or otherwise ensure cursors created from the entered object are still traced
execute() should generate the native DB subsegment without needing manual instrumentation

Reproduction

Install aws-xray-sdk 2.15.0
Install psycopg 3.3.4 and psycopg-pool 3.2.7
Call patch(("psycopg",), raise_errors=True)
Call psycopg.connect(...)
Use the connection in a with block
Create a cursor and execute a query
Observe that the cursor is raw psycopg.Cursor and no DB subsegment is emitted

Environment details

aws-xray-sdk 2.15.0
psycopg 3.3.4
psycopg-pool 3.2.7
Python 3.12
Running in AWS Lambda

主要言語
Python
スター
339
フォーク
147
PR マージ指標
30日以内にマージされた PR はありません

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

aws/aws-xray-sdk-python のほかの issue

aws/aws-xray-sdk-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。