open-telemetry / open-telemetry/opentelemetry-python-contrib

Create database client instrumentation docker-test

Open
#3,032 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature-request
Dominant language
Python
Stars
1.1k
Forks
1.1k
Avg merge
4d 15h
Merged PRs (30d)
16

Description

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

[EDIT Jan 2026] as well as
6. dbapi
7. mysql-connector
8. mysqlclient
9. PyMySQL

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the linked integration tests in instrumentation/opentelemetry-instrumentation-mysqlclient/tests/test_mysqlclient_integration.py and instrumentation/opentelemetry-instrumentation-psycopg2/tests/test_psycopg2_integration.py, then inspect existing docker-test conventions. Done means adding container-backed MySQL and PostgreSQL coverage for sqlcommenting, span context, db.statement, and configuration.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, mysql, postgresql, python
Domain
databases, testing-qa
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.