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

Sqlite3 uninstrumentation does not work properly

Open
#1,586 4 comments 2 reactions 1 assignee View on GitHub

@shalevr is already working on this.

Since Feb 22, 2023.

bug help wanted
Dominant language
Python
Stars
1.1k
Forks
1.1k
Avg merge
4d 15h
Merged PRs (30d)
16

Description

Describe your environment
Python 3.9

Steps to reproduce
Spans keep being created after I call uninsturment:

       import sqlite3
        from opentelemetry.instrumentation.sqlite3 import SQLite3Instrumentor

        SQLite3Instrumentor().instrument()
        cnx = sqlite3.connect(":memory:")

        self.memory_exporter.clear()
        SQLite3Instrumentor().uninstrument()

        stmt = "CREATE TABLE IF NOT EXISTS test (id integer)"
        cursor = cnx.cursor()
        cursor.execute(stmt)
        spans = self.memory_exporter.get_finished_spans()
        self.assertEqual(len(spans), 0)

But if I move the sqlite3.connect after the uninsturment, like this:

        SQLite3Instrumentor().instrument()

        self.memory_exporter.clear()
        SQLite3Instrumentor().uninstrument()

        stmt = "CREATE TABLE IF NOT EXISTS test (id integer)"
        cnx = sqlite3.connect(":memory:")
        cursor = cnx.cursor()
        cursor.execute(stmt)
        spans = self.memory_exporter.get_finished_spans()
        self.assertEqual(len(spans), 0)

it works as expected.
The problem is when instrumented sqlite3.connect returns "get_traced_connection_proxy"
and after uninstument i still use the same connection that I opened before and the hooks still work

What is the expected behavior?
spans will not create after call uninstrument

What is the actual behavior?
still get spans after uninstument

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.