Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Psycopg2Instrumentor().instrument_connection raises AttributeError: 'psycopg2.extensions.connection' object has no attribute '_is_instrumented_by_opentelemetry' #2522

Open
alexmojaki opened this issue May 13, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@alexmojaki
Copy link

alexmojaki commented May 13, 2024

Describe your environment

opentelemetry-instrumentation-psycopg2==0.45b0
psycopg2-binary==2.9.9

Steps to reproduce

Use Psycopg2Instrumentor().instrument_connection. For example:

import psycopg2
from opentelemetry.instrumentation.psycopg2 import Psycopg2Instrumentor

connection = psycopg2.connect(database='database', user='user', password='secret', host='0.0.0.0', port=5432)

Psycopg2Instrumentor().instrument_connection(connection)

and run a database with:

docker run --name postgres \
    -e POSTGRES_USER=user \
    -e POSTGRES_PASSWORD=secret \
    -e POSTGRES_DB=database \
    -p 5432:5432 -d postgres

What is the actual behavior?

Traceback (most recent call last):
  File "test.py", line 6, in <module>
    Psycopg2Instrumentor().instrument_connection(connection)
  File "/home/alex/work/logfire/.venv/lib/python3.12/site-packages/opentelemetry/instrumentation/psycopg2/__init__.py", line 164, in instrument_connection
    connection._is_instrumented_by_opentelemetry = False
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'psycopg2.extensions.connection' object has no attribute '_is_instrumented_by_opentelemetry'

Additional context

Here's where the error happens:

The code seems tested here:

but it doesn't get the error because it's a mock connection.

@xrmx
Copy link
Contributor

xrmx commented May 13, 2024

@alexmojaki would be great if you can open a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants