open-telemetry / opentelemetry-python-contrib

OpenTelemetry instrumentation for Python modules
https://opentelemetry.io
Apache License 2.0
740 stars 614 forks source link

Django ORM auto-instrumentation support #856

Open ankitnayan opened 2 years ago

ankitnayan commented 2 years ago

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.

phillipuniverse commented 2 years ago

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.

owais commented 2 years ago

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.

ankitnayan commented 2 years ago

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.

ocelotl commented 2 years ago

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:

tylerstar commented 1 year ago

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

mlakewood commented 8 months ago

@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?