diff --git a/instrumentation/opentelemetry-instrumentation-sqlite3/src/opentelemetry/instrumentation/sqlite3/__init__.py b/instrumentation/opentelemetry-instrumentation-sqlite3/src/opentelemetry/instrumentation/sqlite3/__init__.py index 9b3ae28a95..1ec4794e96 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlite3/src/opentelemetry/instrumentation/sqlite3/__init__.py +++ b/instrumentation/opentelemetry-instrumentation-sqlite3/src/opentelemetry/instrumentation/sqlite3/__init__.py @@ -39,20 +39,27 @@ --- """ +from __future__ import annotations + import sqlite3 from sqlite3 import dbapi2 -from typing import Collection +from typing import Any, Collection, TypeVar, Union from opentelemetry.instrumentation import dbapi from opentelemetry.instrumentation.instrumentor import BaseInstrumentor from opentelemetry.instrumentation.sqlite3.package import _instruments from opentelemetry.instrumentation.sqlite3.version import __version__ +from opentelemetry.trace import TracerProvider # No useful attributes of sqlite3 connection object _CONNECTION_ATTRIBUTES = {} _DATABASE_SYSTEM = "sqlite" +SQLite3Connection = TypeVar( # pylint: disable=invalid-name + "SQLite3Connection", bound=Union[sqlite3.Connection, None] +) + class SQLite3Instrumentor(BaseInstrumentor): _TO_WRAP = [sqlite3, dbapi2] @@ -60,7 +67,7 @@ class SQLite3Instrumentor(BaseInstrumentor): def instrumentation_dependencies(self) -> Collection[str]: return _instruments - def _instrument(self, **kwargs): + def _instrument(self, **kwargs: Any) -> None: """Integrate with SQLite3 Python library. https://docs.python.org/3/library/sqlite3.html """ @@ -77,13 +84,16 @@ def _instrument(self, **kwargs): tracer_provider=tracer_provider, ) - def _uninstrument(self, **kwargs): + def _uninstrument(self, **kwargs: Any) -> None: """ "Disable SQLite3 instrumentation""" for module in self._TO_WRAP: dbapi.unwrap_connect(module, "connect") @staticmethod - def instrument_connection(connection, tracer_provider=None): + def instrument_connection( + connection: SQLite3Connection, + tracer_provider: TracerProvider | None = None, + ) -> SQLite3Connection: """Enable instrumentation in a SQLite connection. Args: @@ -105,7 +115,9 @@ def instrument_connection(connection, tracer_provider=None): ) @staticmethod - def uninstrument_connection(connection): + def uninstrument_connection( + connection: SQLite3Connection, + ) -> SQLite3Connection: """Disable instrumentation in a SQLite connection. Args: diff --git a/instrumentation/opentelemetry-instrumentation-sqlite3/src/opentelemetry/instrumentation/sqlite3/package.py b/instrumentation/opentelemetry-instrumentation-sqlite3/src/opentelemetry/instrumentation/sqlite3/package.py index 7a66a17a93..0de6133b4a 100644 --- a/instrumentation/opentelemetry-instrumentation-sqlite3/src/opentelemetry/instrumentation/sqlite3/package.py +++ b/instrumentation/opentelemetry-instrumentation-sqlite3/src/opentelemetry/instrumentation/sqlite3/package.py @@ -11,6 +11,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations - -_instruments = tuple() +_instruments: tuple[str, ...] = tuple()