From 09634b0f16b99fe612edb3017d2dac51cd979882 Mon Sep 17 00:00:00 2001 From: Marcelo Trylesinski Date: Mon, 5 Aug 2024 21:55:44 +0200 Subject: [PATCH] Add `logfire.exception()` to `logfire-api` (#358) --- logfire-api/logfire_api/__init__.py | 3 +++ logfire-api/logfire_api/__init__.pyi | 3 ++- logfire/__init__.py | 1 + tests/test_logfire_api.py | 2 +- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/logfire-api/logfire_api/__init__.py b/logfire-api/logfire_api/__init__.py index 882c5adb9..396c1ea8f 100644 --- a/logfire-api/logfire_api/__init__.py +++ b/logfire-api/logfire_api/__init__.py @@ -69,6 +69,8 @@ def warn(self, *args, **kwargs) -> None: ... def error(self, *args, **kwargs) -> None: ... + def exception(self, *args, **kwargs) -> None: ... + def fatal(self, *args, **kwargs) -> None: ... def with_tags(self, *args, **kwargs) -> Logfire: @@ -132,6 +134,7 @@ def shutdown(self, *args, **kwargs) -> None: ... info = DEFAULT_LOGFIRE_INSTANCE.info warn = DEFAULT_LOGFIRE_INSTANCE.warn error = DEFAULT_LOGFIRE_INSTANCE.error + exception = DEFAULT_LOGFIRE_INSTANCE.exception fatal = DEFAULT_LOGFIRE_INSTANCE.fatal with_tags = DEFAULT_LOGFIRE_INSTANCE.with_tags with_settings = DEFAULT_LOGFIRE_INSTANCE.with_settings diff --git a/logfire-api/logfire_api/__init__.pyi b/logfire-api/logfire_api/__init__.pyi index bd1b1f313..fd1c038c6 100644 --- a/logfire-api/logfire_api/__init__.pyi +++ b/logfire-api/logfire_api/__init__.pyi @@ -11,7 +11,7 @@ from .integrations.logging import LogfireLoggingHandler as LogfireLoggingHandler from .integrations.structlog import LogfireProcessor as StructlogProcessor from .version import VERSION as VERSION -__all__ = ['Logfire', 'LogfireSpan', 'LevelName', 'ConsoleOptions', 'PydanticPlugin', 'configure', 'span', 'instrument', 'log', 'trace', 'debug', 'notice', 'info', 'warn', 'error', 'fatal', 'force_flush', 'log_slow_async_callbacks', 'install_auto_tracing', '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', 'AutoTraceModule', 'with_tags', 'with_settings', 'shutdown', 'load_spans_from_file', 'no_auto_trace', 'METRICS_PREFERRED_TEMPORALITY', 'ScrubMatch', 'ScrubbingOptions', 'VERSION', 'suppress_instrumentation', 'StructlogProcessor', 'LogfireLoggingHandler', 'TailSamplingOptions'] +__all__ = ['Logfire', 'LogfireSpan', 'LevelName', 'ConsoleOptions', 'PydanticPlugin', 'configure', 'span', 'instrument', 'log', 'trace', 'debug', 'notice', 'info', 'warn', 'error', 'exception', 'fatal', 'force_flush', 'log_slow_async_callbacks', 'install_auto_tracing', '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', 'AutoTraceModule', 'with_tags', 'with_settings', 'shutdown', 'load_spans_from_file', 'no_auto_trace', 'METRICS_PREFERRED_TEMPORALITY', 'ScrubMatch', 'ScrubbingOptions', 'VERSION', 'suppress_instrumentation', 'StructlogProcessor', 'LogfireLoggingHandler', 'TailSamplingOptions'] DEFAULT_LOGFIRE_INSTANCE = Logfire() span = DEFAULT_LOGFIRE_INSTANCE.span @@ -46,4 +46,5 @@ notice = DEFAULT_LOGFIRE_INSTANCE.notice warn = DEFAULT_LOGFIRE_INSTANCE.warn error = DEFAULT_LOGFIRE_INSTANCE.error fatal = DEFAULT_LOGFIRE_INSTANCE.fatal +exception = DEFAULT_LOGFIRE_INSTANCE.exception __version__ = VERSION diff --git a/logfire/__init__.py b/logfire/__init__.py index 58fe21ab0..47c18b0f3 100644 --- a/logfire/__init__.py +++ b/logfire/__init__.py @@ -94,6 +94,7 @@ def loguru_handler() -> dict[str, Any]: 'info', 'warn', 'error', + 'exception', 'fatal', 'force_flush', 'log_slow_async_callbacks', diff --git a/tests/test_logfire_api.py b/tests/test_logfire_api.py index da0cfd9c3..36a23d3ff 100644 --- a/tests/test_logfire_api.py +++ b/tests/test_logfire_api.py @@ -70,7 +70,7 @@ def test_runtime(logfire_api_factory: Callable[[], ModuleType], module_name: str logfire_api.log('info', 'test log') logfire__all__.remove('log') - for log_method in ['trace', 'debug', 'info', 'notice', 'warn', 'error', 'fatal']: + for log_method in ['trace', 'debug', 'info', 'notice', 'warn', 'error', 'exception', 'fatal']: assert hasattr(logfire_api, log_method) getattr(logfire_api, log_method)('test log') logfire__all__.remove(log_method)