open-telemetry / open-telemetry/opentelemetry-python-contrib

Psycopg2Instrumentor doesn't work for cursors with non-default cursor_factory

Open
#578 5 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug help wanted instrumentation triaged
Dominant language
Python
Stars
1.1k
Forks
1.1k
Avg merge
4d 15h
Merged PRs (30d)
16

Description

https://github.com/open-telemetry/opentelemetry-python-contrib/blob/2ee2cf3cb54c7e9704567894636bcc1cfff702e6/instrumentation/opentelemetry-instrumentation-psycopg2/src/opentelemetry/instrumentation/psycopg2/__init__.py#L126-L141

When wrapping the connection, the default cursor_factory is set for the connection, but the connection is returned as is rather than a proxy. Therefore, when a cursor is created with the connection_factory argument passed, the instrumentation does not happen.

Steps to reproduce
Set up the Psycopg2Instrumentor, create a cursor passing the cursor_factory argument, and run a query.

What is the expected behavior?
Spans produced/exported

What is the actual behavior?
No spans produced/exported

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Inspect the linked psycopg2 instrumentation code in instrumentation/opentelemetry-instrumentation-psycopg2/src/opentelemetry/instrumentation/psycopg2/init.py, especially lines 126-141, and reproduce the case using a cursor_factory argument. Done means queries made through that cursor produce and export spans, matching the expected behavior described in the issue.

Written by the indexing model from the issue text.

Assessment

Tech stack
postgresql, python
Domain
databases
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.