From 22b3794f95fb79ade00bf601be2e1a7bbd87fddc Mon Sep 17 00:00:00 2001 From: Marcelo Trylesinski Date: Fri, 27 Dec 2024 14:45:44 +0100 Subject: [PATCH 1/3] Remove `Unpack` from `instrument_sqilte3` --- logfire/_internal/integrations/sqlite3.py | 17 +++++------------ logfire/_internal/main.py | 14 +++----------- 2 files changed, 8 insertions(+), 23 deletions(-) diff --git a/logfire/_internal/integrations/sqlite3.py b/logfire/_internal/integrations/sqlite3.py index 3b14785fb..3584306b4 100644 --- a/logfire/_internal/integrations/sqlite3.py +++ b/logfire/_internal/integrations/sqlite3.py @@ -1,7 +1,9 @@ from __future__ import annotations import sqlite3 -from typing import TYPE_CHECKING +from typing import Any, TypeVar + +from opentelemetry.trace import TracerProvider try: from opentelemetry.instrumentation.sqlite3 import SQLite3Instrumentor @@ -12,20 +14,11 @@ " pip install 'logfire[sqlite3]'" ) -if TYPE_CHECKING: - from typing import TypedDict, TypeVar, Unpack - - from opentelemetry.trace import TracerProvider - - SQLite3Connection = TypeVar('SQLite3Connection', bound=sqlite3.Connection | None) - class SQLite3InstrumentKwargs(TypedDict, total=False): - skip_dep_check: bool +SQLite3Connection = TypeVar('SQLite3Connection', bound=sqlite3.Connection | None) -def instrument_sqlite3( - *, conn: SQLite3Connection, tracer_provider: TracerProvider, **kwargs: Unpack[SQLite3InstrumentKwargs] -) -> SQLite3Connection: +def instrument_sqlite3(*, conn: SQLite3Connection, tracer_provider: TracerProvider, **kwargs: Any) -> SQLite3Connection: """Instrument the `sqlite3` module so that spans are automatically created for each query. See the `Logfire.instrument_sqlite3` method for details. diff --git a/logfire/_internal/main.py b/logfire/_internal/main.py index fad9edccd..82dcfadd3 100644 --- a/logfire/_internal/main.py +++ b/logfire/_internal/main.py @@ -95,7 +95,7 @@ from .integrations.pymongo import PymongoInstrumentKwargs from .integrations.redis import RedisInstrumentKwargs from .integrations.sqlalchemy import SQLAlchemyInstrumentKwargs - from .integrations.sqlite3 import SQLite3Connection, SQLite3InstrumentKwargs + from .integrations.sqlite3 import SQLite3Connection from .integrations.starlette import StarletteInstrumentKwargs from .integrations.system_metrics import Base as SystemMetricsBase, Config as SystemMetricsConfig from .integrations.wsgi import WSGIInstrumentKwargs @@ -1583,9 +1583,7 @@ def instrument_sqlalchemy( }, ) - def instrument_sqlite3( - self, conn: SQLite3Connection = None, **kwargs: Unpack[SQLite3InstrumentKwargs] - ) -> SQLite3Connection: + def instrument_sqlite3(self, conn: SQLite3Connection = None, **kwargs: Any) -> SQLite3Connection: """Instrument the `sqlite3` module or a specific connection so that spans are automatically created for each operation. Uses the @@ -1602,13 +1600,7 @@ def instrument_sqlite3( from .integrations.sqlite3 import instrument_sqlite3 self._warn_if_not_initialized_for_instrumentation() - return instrument_sqlite3( - conn=conn, - **{ # type: ignore - 'tracer_provider': self._config.get_tracer_provider(), - **kwargs, - }, - ) + return instrument_sqlite3(conn=conn, **{'tracer_provider': self._config.get_tracer_provider(), **kwargs}) def instrument_aws_lambda( self, From 0f354db1c22a208413f62df17841f49bef215652 Mon Sep 17 00:00:00 2001 From: Marcelo Trylesinski Date: Fri, 27 Dec 2024 14:47:35 +0100 Subject: [PATCH 2/3] Add string type --- logfire/_internal/integrations/sqlite3.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logfire/_internal/integrations/sqlite3.py b/logfire/_internal/integrations/sqlite3.py index 3584306b4..270a9f284 100644 --- a/logfire/_internal/integrations/sqlite3.py +++ b/logfire/_internal/integrations/sqlite3.py @@ -15,7 +15,7 @@ ) -SQLite3Connection = TypeVar('SQLite3Connection', bound=sqlite3.Connection | None) +SQLite3Connection = TypeVar('SQLite3Connection', bound='sqlite3.Connection | None') def instrument_sqlite3(*, conn: SQLite3Connection, tracer_provider: TracerProvider, **kwargs: Any) -> SQLite3Connection: From 920d3b776dcd174f2857775c618b69c5913194ad Mon Sep 17 00:00:00 2001 From: Marcelo Trylesinski Date: Fri, 27 Dec 2024 14:50:23 +0100 Subject: [PATCH 3/3] fix typevar --- logfire/_internal/integrations/sqlite3.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logfire/_internal/integrations/sqlite3.py b/logfire/_internal/integrations/sqlite3.py index 270a9f284..ad51e8265 100644 --- a/logfire/_internal/integrations/sqlite3.py +++ b/logfire/_internal/integrations/sqlite3.py @@ -15,7 +15,7 @@ ) -SQLite3Connection = TypeVar('SQLite3Connection', bound='sqlite3.Connection | None') +SQLite3Connection = TypeVar('SQLite3Connection', sqlite3.Connection, None) def instrument_sqlite3(*, conn: SQLite3Connection, tracer_provider: TracerProvider, **kwargs: Any) -> SQLite3Connection: