Skip to content

test(sqlite3): add uninstrument, error status, suppress, and no-op tests#4335

Open
archy-rock3t-cloud wants to merge 1 commit intoopen-telemetry:mainfrom
sophotechlabs:test/sqlite3-coverage-gaps
Open

test(sqlite3): add uninstrument, error status, suppress, and no-op tests#4335
archy-rock3t-cloud wants to merge 1 commit intoopen-telemetry:mainfrom
sophotechlabs:test/sqlite3-coverage-gaps

Conversation

@archy-rock3t-cloud
Copy link

Description

The sqlite3 instrumentation had only 3 tests covering basic execute/executemany/callproc. This adds the standard lifecycle tests that other dbapi-based instrumentations (psycopg2, mysql) already have: uninstrument, uninstrument_connection, error status on failed queries, suppress_instrumentation, and NoOpTracerProvider.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

tox -e py314-test-instrumentation-sqlite3 — all 8 tests pass (3 existing + 5 new).

Does This PR Require a Core Repo Change?

  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Signed-off-by: Artem Muterko <artem@sopho.tech>
Copy link

@JWinermaSplunk JWinermaSplunk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few comments, also missing a CHANGELOG entry whenever you have a moment.

spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 0)

def test_span_failed(self):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did we want to add something like this for consistency?

self.assertEqual(span.status.description, "Exception: Test Exception")

spans_list = self.memory_exporter.get_finished_spans()
self.assertEqual(len(spans_list), 1)

def test_uninstrument_connection(self):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like this method closely resembles this method from psycopg2. Did we want to use the same query after uninstrumenting like the previously existing test? Also, should we add with_instrument to the method name for consistency?

self.validate_spans("test")


class TestSQLite3Integration(TestBase):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are we sure we need a separate integration class? If so, I think we need to update tearDown to close cursor and connections as well?

cnx = sqlite3.connect(":memory:")
cursor = cnx.cursor()

with self.assertRaises(Exception):

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want with self.assertRaises(sqlite3.OperationalError):?

self.assertEqual(len(spans_list), 1)

cnx = SQLite3Instrumentor.uninstrument_connection(cnx)
cursor = cnx.cursor()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to self.memory_exporter.clear() here and assert the span count was 0 after uninstrumenting?

@herin049
Copy link
Contributor

LGTM, just needs a CHANGELOG.md entry.

@xrmx xrmx moved this to Approved PRs that need fixes in Python PR digest Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Approved PRs that need fixes

Development

Successfully merging this pull request may close these issues.

4 participants