From 06ed7cbfa7c84066516ceffaf1faceeea11786d7 Mon Sep 17 00:00:00 2001 From: Marcelo Trylesinski Date: Mon, 2 Dec 2024 15:10:29 +0100 Subject: [PATCH 1/2] Bump version to v2.6.0 --- CHANGELOG.md | 8 ++++++++ logfire-api/logfire_api/__init__.pyi | 3 ++- .../_internal/integrations/sqlite3.pyi | 14 ++++++++++++++ logfire-api/logfire_api/_internal/main.pyi | 16 +++++++++++++++- logfire-api/pyproject.toml | 2 +- pyproject.toml | 2 +- uv.lock | 4 ++-- 7 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 logfire-api/logfire_api/_internal/integrations/sqlite3.pyi diff --git a/CHANGELOG.md b/CHANGELOG.md index 209880716..b1b3b4c42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,12 @@ # Release Notes +## [v2.6.0] (2024-12-02) + +* Add note about Django ASGI into the documentation by @Kludex in [#630](https://github.com/pydantic/logfire/pull/630) +* Add note about `suppress_scopes` to BigQuery by @Kludex in [#631](https://github.com/pydantic/logfire/pull/631) +* Add OpenTelemetry classifiers by @Kludex in [#637](https://github.com/pydantic/logfire/pull/637) +* Add `instrument_sqlite3` by @Kludex in [#634](https://github.com/pydantic/logfire/pull/634) + ## [v2.5.0] (2024-11-27) * Add `logfire.suppress_scopes` method by @alexmojaki in [#628](https://github.com/pydantic/logfire/pull/628) @@ -445,3 +452,4 @@ First release from new repo! [v2.4.0]: https://github.com/pydantic/logfire/compare/v2.3.0...v2.4.0 [v2.4.1]: https://github.com/pydantic/logfire/compare/v2.4.0...v2.4.1 [v2.5.0]: https://github.com/pydantic/logfire/compare/v2.4.1...v2.5.0 +[v2.6.0]: https://github.com/pydantic/logfire/compare/v2.5.0...v2.6.0 diff --git a/logfire-api/logfire_api/__init__.pyi b/logfire-api/logfire_api/__init__.pyi index 0a814f2e8..ca72b5bfd 100644 --- a/logfire-api/logfire_api/__init__.pyi +++ b/logfire-api/logfire_api/__init__.pyi @@ -12,7 +12,7 @@ from .version import VERSION as VERSION from logfire.sampling import SamplingOptions as SamplingOptions from typing import Any -__all__ = ['Logfire', 'LogfireSpan', 'LevelName', 'AdvancedOptions', 'ConsoleOptions', 'CodeSource', 'PydanticPlugin', 'configure', 'span', 'instrument', 'log', 'trace', 'debug', 'notice', 'info', 'warn', 'error', 'exception', 'fatal', 'force_flush', 'log_slow_async_callbacks', 'install_auto_tracing', 'instrument_asgi', 'instrument_wsgi', 'instrument_pydantic', 'instrument_fastapi', 'instrument_openai', 'instrument_anthropic', 'instrument_asyncpg', 'instrument_httpx', 'instrument_celery', 'instrument_requests', 'instrument_psycopg', 'instrument_django', 'instrument_flask', 'instrument_starlette', 'instrument_aiohttp_client', 'instrument_sqlalchemy', 'instrument_redis', 'instrument_pymongo', 'instrument_mysql', 'instrument_system_metrics', 'AutoTraceModule', 'with_tags', 'with_settings', 'suppress_scopes', 'shutdown', 'load_spans_from_file', 'no_auto_trace', 'ScrubMatch', 'ScrubbingOptions', 'VERSION', 'suppress_instrumentation', 'StructlogProcessor', 'LogfireLoggingHandler', 'loguru_handler', 'SamplingOptions', 'MetricsOptions'] +__all__ = ['Logfire', 'LogfireSpan', 'LevelName', 'AdvancedOptions', 'ConsoleOptions', 'CodeSource', 'PydanticPlugin', 'configure', 'span', 'instrument', 'log', 'trace', 'debug', 'notice', 'info', 'warn', 'error', 'exception', 'fatal', 'force_flush', 'log_slow_async_callbacks', 'install_auto_tracing', 'instrument_asgi', 'instrument_wsgi', 'instrument_pydantic', 'instrument_fastapi', 'instrument_openai', 'instrument_anthropic', 'instrument_asyncpg', 'instrument_httpx', 'instrument_celery', 'instrument_requests', 'instrument_psycopg', 'instrument_django', 'instrument_flask', 'instrument_starlette', 'instrument_aiohttp_client', 'instrument_sqlalchemy', 'instrument_sqlite3', 'instrument_redis', 'instrument_pymongo', 'instrument_mysql', 'instrument_system_metrics', 'AutoTraceModule', 'with_tags', 'with_settings', 'suppress_scopes', 'shutdown', 'load_spans_from_file', 'no_auto_trace', 'ScrubMatch', 'ScrubbingOptions', 'VERSION', 'suppress_instrumentation', 'StructlogProcessor', 'LogfireLoggingHandler', 'loguru_handler', 'SamplingOptions', 'MetricsOptions'] DEFAULT_LOGFIRE_INSTANCE = Logfire() span = DEFAULT_LOGFIRE_INSTANCE.span @@ -36,6 +36,7 @@ instrument_flask = DEFAULT_LOGFIRE_INSTANCE.instrument_flask instrument_starlette = DEFAULT_LOGFIRE_INSTANCE.instrument_starlette instrument_aiohttp_client = DEFAULT_LOGFIRE_INSTANCE.instrument_aiohttp_client instrument_sqlalchemy = DEFAULT_LOGFIRE_INSTANCE.instrument_sqlalchemy +instrument_sqlite3 = DEFAULT_LOGFIRE_INSTANCE.instrument_sqlite3 instrument_redis = DEFAULT_LOGFIRE_INSTANCE.instrument_redis instrument_pymongo = DEFAULT_LOGFIRE_INSTANCE.instrument_pymongo instrument_mysql = DEFAULT_LOGFIRE_INSTANCE.instrument_mysql diff --git a/logfire-api/logfire_api/_internal/integrations/sqlite3.pyi b/logfire-api/logfire_api/_internal/integrations/sqlite3.pyi new file mode 100644 index 000000000..33f823e11 --- /dev/null +++ b/logfire-api/logfire_api/_internal/integrations/sqlite3.pyi @@ -0,0 +1,14 @@ +import sqlite3 +from opentelemetry.trace import TracerProvider +from typing import TypeVar, TypedDict, Unpack + +SQLite3Connection = TypeVar('SQLite3Connection', bound=sqlite3.Connection | None) + +class SQLite3InstrumentKwargs(TypedDict, total=False): + skip_dep_check: bool + +def instrument_sqlite3(*, conn: SQLite3Connection, tracer_provider: TracerProvider, **kwargs: Unpack[SQLite3InstrumentKwargs]) -> 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-api/logfire_api/_internal/main.pyi b/logfire-api/logfire_api/_internal/main.pyi index 0ed0427e3..5cd077b06 100644 --- a/logfire-api/logfire_api/_internal/main.pyi +++ b/logfire-api/logfire_api/_internal/main.pyi @@ -20,6 +20,7 @@ from .integrations.psycopg import PsycopgInstrumentKwargs as PsycopgInstrumentKw from .integrations.pymongo import PymongoInstrumentKwargs as PymongoInstrumentKwargs from .integrations.redis import RedisInstrumentKwargs as RedisInstrumentKwargs from .integrations.sqlalchemy import SQLAlchemyInstrumentKwargs as SQLAlchemyInstrumentKwargs +from .integrations.sqlite3 import SQLite3Connection as SQLite3Connection, SQLite3InstrumentKwargs as SQLite3InstrumentKwargs from .integrations.starlette import StarletteInstrumentKwargs as StarletteInstrumentKwargs from .integrations.system_metrics import Base as SystemMetricsBase, Config as SystemMetricsConfig from .integrations.wsgi import WSGIInstrumentKwargs as WSGIInstrumentKwargs @@ -704,6 +705,20 @@ class Logfire: [OpenTelemetry SQLAlchemy Instrumentation](https://opentelemetry-python-contrib.readthedocs.io/en/latest/instrumentation/sqlalchemy/sqlalchemy.html) library, specifically `SQLAlchemyInstrumentor().instrument()`, to which it passes `**kwargs`. """ + def instrument_sqlite3(self, conn: SQLite3Connection = None, **kwargs: Unpack[SQLite3InstrumentKwargs]) -> SQLite3Connection: + """Instrument the `sqlite3` module or a specific connection so that spans are automatically created for each operation. + + Uses the + [OpenTelemetry SQLite3 Instrumentation](https://opentelemetry-python-contrib.readthedocs.io/en/latest/instrumentation/sqlite3/sqlite3.html) + library. + + Args: + conn: The `sqlite3` connection to instrument, or `None` to instrument all connections. + **kwargs: Additional keyword arguments to pass to the OpenTelemetry `instrument` methods. + + Returns: + If a connection is provided, returns the instrumented connection. If no connection is provided, returns `None`. + """ def instrument_pymongo(self, **kwargs: Unpack[PymongoInstrumentKwargs]) -> None: """Instrument the `pymongo` module so that spans are automatically created for each operation. @@ -735,7 +750,6 @@ class Logfire: Returns: If a connection is provided, returns the instrumented connection. If no connection is provided, returns None. - """ def instrument_system_metrics(self, config: SystemMetricsConfig | None = None, base: SystemMetricsBase = 'basic') -> None: """Collect system metrics. diff --git a/logfire-api/pyproject.toml b/logfire-api/pyproject.toml index e2ee32518..d25704a12 100644 --- a/logfire-api/pyproject.toml +++ b/logfire-api/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "logfire-api" -version = "2.5.0" +version = "2.6.0" description = "Shim for the Logfire SDK which does nothing unless Logfire is installed" authors = [ { name = "Pydantic Team", email = "engineering@pydantic.dev" }, diff --git a/pyproject.toml b/pyproject.toml index 19a36d550..e05236005 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "logfire" -version = "2.5.0" +version = "2.6.0" description = "The best Python observability tool! 🪵🔥" requires-python = ">=3.8" authors = [ diff --git a/uv.lock b/uv.lock index 5d35e8699..2893a2ab0 100644 --- a/uv.lock +++ b/uv.lock @@ -1387,7 +1387,7 @@ wheels = [ [[package]] name = "logfire" -version = "2.5.0" +version = "2.6.0" source = { editable = "." } dependencies = [ { name = "executing" }, @@ -1656,7 +1656,7 @@ docs = [ [[package]] name = "logfire-api" -version = "2.5.0" +version = "2.6.0" source = { editable = "logfire-api" } [package.metadata] From 8b15f32c670407adb272dba218956a77fa0ea6a1 Mon Sep 17 00:00:00 2001 From: Marcelo Trylesinski Date: Mon, 2 Dec 2024 15:13:02 +0100 Subject: [PATCH 2/2] Update CHANGELOG.md --- CHANGELOG.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b1b3b4c42..0fb045b6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,6 @@ ## [v2.6.0] (2024-12-02) -* Add note about Django ASGI into the documentation by @Kludex in [#630](https://github.com/pydantic/logfire/pull/630) -* Add note about `suppress_scopes` to BigQuery by @Kludex in [#631](https://github.com/pydantic/logfire/pull/631) -* Add OpenTelemetry classifiers by @Kludex in [#637](https://github.com/pydantic/logfire/pull/637) * Add `instrument_sqlite3` by @Kludex in [#634](https://github.com/pydantic/logfire/pull/634) ## [v2.5.0] (2024-11-27)