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
Recently upgraded to Django 4.2 and noticed that opentelemetry.instrumentation.psycopg2.client spans were not emitted. I am using Psycopg2 version 2.9.6.
The issue is that the connection's cursor_factory function is overridden by Django after otel attempts to override it on the connection. Here's the code that overrides the Psycopg2 cursor_factory function:
The below screenshot illustrates the problem. There are a few things going on but I drew arrows to try to highlight the problematic areas:
This method is when Django creates the new connection. You can see the big blue line is where the debugger is paused (L272). At this point, the cursor_factory is the one from otel. But immediately after this, on lines 272 and 285 Django overrides the cursor_factory to be its own, effectively neutering otel. No database spans are emitted.
This is somewhat related to #1751 as this might need to be considered for psycopg3 support.
Describe any aspect of your environment relevant to the problem, including your Python version, platform, version numbers of installed dependencies, information about your cloud hosting provider, etc. If you're reporting a problem with a specific version of a library in this repo, please check whether the problem has been fixed on main.
Steps to reproduce
Use Django 4.2 and Psycopg2. The instrumentation will run and instrument the connection/cursor_factory but Django will override it. All other Django versions < 4.2 (including 4.1) work fine.
What is the expected behavior?
Psycopg2 spans create
What is the actual behavior?
No spans created.
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered:
I went to link the regression in Django, turns out this has already been fixed at django/django@73cbb37 and will be apart of 4.2.1, due to be released May 3 2023 (1 week).
I'll leave this open until I verify everything working with Django 4.2.1.
phillipuniverse
changed the title
Psycopg2 instrumentation does not create spans in Django 4.2
Psycopg2 instrumentation does not create spans in Django 4.2.0
Apr 27, 2023
Describe your environment
Recently upgraded to Django 4.2 and noticed that
opentelemetry.instrumentation.psycopg2.client
spans were not emitted. I am using Psycopg2 version 2.9.6.The issue is that the connection's
cursor_factory
function is overridden by Django after otel attempts to override it on the connection. Here's the code that overrides the Psycopg2cursor_factory
function:opentelemetry-python-contrib/instrumentation/opentelemetry-instrumentation-psycopg2/src/opentelemetry/instrumentation/psycopg2/__init__.py
Lines 203 to 206 in 5117098
The below screenshot illustrates the problem. There are a few things going on but I drew arrows to try to highlight the problematic areas:
This method is when Django creates the new connection. You can see the big blue line is where the debugger is paused (L272). At this point, the
cursor_factory
is the one from otel. But immediately after this, on lines 272 and 285 Django overrides thecursor_factory
to be its own, effectively neutering otel. No database spans are emitted.This is somewhat related to #1751 as this might need to be considered for psycopg3 support.
Describe any aspect of your environment relevant to the problem, including your Python version, platform, version numbers of installed dependencies, information about your cloud hosting provider, etc. If you're reporting a problem with a specific version of a library in this repo, please check whether the problem has been fixed on main.
Steps to reproduce
Use Django 4.2 and Psycopg2. The instrumentation will run and instrument the connection/cursor_factory but Django will override it. All other Django versions < 4.2 (including 4.1) work fine.
What is the expected behavior?
Psycopg2 spans create
What is the actual behavior?
No spans created.
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: