open-telemetry / opentelemetry-python-contrib

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

Create database client instrumentation docker-test #3032

Open tammy-baylis-swi opened 5 days ago

tammy-baylis-swi commented 5 days ago

What problem do you want to solve?

Current unit and integration tests for instrumentors are using unittest mock objects in place of the real database driver frameworks, e.g. mysqlclient, psycopg2. These let us check how the drivers are being called, but not how the drivers are behaving while being instrumented. The latter is especially important for testing existing and future sqlcommenting functionality.

Describe the solution you'd like

Create a docker-test suite that will check existing db client instrumentor functionality such as:

  1. sqlcommenting of query statements made by driver
  2. span context matches sqlcomment content
  3. db.statement attribute matches sqlcomment
  4. configuration of above

This probably requires spinning up MySQL and PostgreSQL databases in containers that are queryable by instrumented database client services.

sqlcommenting is currently implemented for:

  1. Django ORM
  2. Flask 'ORM'
  3. SQLAlchemy
  4. psycopg2
  5. psycopg

Describe alternatives you've considered

Neither MySQL nor PostgreSQL drivers can query sqlite3, else we could write unit/integration tests that read from file.

There is a 3rd party package I saw called testing.mysqld but we're not currently using that dep and it's been a while since its last release so I'd hesitate in adding it.

Additional Context

Was discussed here: https://github.com/open-telemetry/opentelemetry-python-contrib/pull/2941/#discussion_r1850623119

Recent issue for implementing sqlcomment support for more instrumentors: https://github.com/open-telemetry/opentelemetry-python-contrib/issues/2902

Would you like to implement a fix?

None