opentelemetry-python-contrib icon indicating copy to clipboard operation
opentelemetry-python-contrib copied to clipboard

Django ORM auto-instrumentation support

Open ankitnayan opened this issue 3 years ago • 6 comments
trafficstars

Does opentelemetry auto-instrument Django ORM database calls? Since, most of the Django users use the in-built ORM, it would be very useful to extend DB instrumentation to ORM. When I run opentelemetry-bootstrap , I can see opentelemetry-instrumentation-sqlite3 as one of the values, so opentelemetry should be auto-instrumenting DB calls made.

ankitnayan avatar Jan 11 '22 14:01 ankitnayan

This is available not as Django ORM instrumentation but for the particular underlying database driver. For instance opentelemetry-instrumentation-psycopg2 for Postgres, opentelemetry-instrumentation-pymysql for MySQL, the SQLite one you already mentioned, etc.

For postgres specifically you might run into https://github.com/open-telemetry/opentelemetry-python-contrib/issues/610 if you are using psycopg2-binary.

phillipuniverse avatar Jan 11 '22 20:01 phillipuniverse

We have instrumentation for individual DB drivers like @phillipuniverse said but I don't see why we the existing Django instrumentation cannot cover the ORM as well. Might be useful to have for additional insight or use with DB backends we don't have instrumentation for.

owais avatar Jan 11 '22 23:01 owais

We have instrumentation for individual DB drivers like @phillipuniverse said but I don't see why we the existing Django instrumentation cannot cover the ORM as well. Might be useful to have for additional insight or use with DB backends we don't have instrumentation for.

Right, and I think django ORM is heavily used by teams working on django. Not having db spans in trace will leave a huge gap on instrumentation.

ankitnayan avatar Jan 12 '22 06:01 ankitnayan

Is this an issue to track the addition of ORM auto-instrumentation support in Django? If so, please update the description and title, @ankitnayan :v:

ocelotl avatar Jan 18 '22 17:01 ocelotl

auto-instrumentation already supports django orm (django version == 4.2.2), at least works for me

tylerstar avatar Oct 10 '23 08:10 tylerstar

@tylerstar could you elaborate? Is there any other settings you needed to enable? Which version of the auto instumenter were you using etc? I can't see in the django instrumentor code where this would get hooked into the ORM. And im only seeing request level spans come through from my django 4.2 app.

Is it by enabling the sql_commentor flag? I wasnt super sure what that did?

mlakewood avatar Mar 30 '24 13:03 mlakewood