Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
Kludex committed Oct 9, 2024
1 parent f669653 commit 9098435
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 5 deletions.
7 changes: 4 additions & 3 deletions logfire-api/logfire_api/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
from __future__ import annotations

from contextlib import contextmanager
import importlib
import sys
from typing import TYPE_CHECKING, ContextManager, Literal
from contextlib import nullcontext
from contextlib import contextmanager, nullcontext
from typing import Any, ContextManager, Literal, TYPE_CHECKING
from unittest.mock import MagicMock

try:
Expand Down Expand Up @@ -166,6 +165,8 @@ def shutdown(self, *args, **kwargs) -> None: ...
instrument_system_metrics = DEFAULT_LOGFIRE_INSTANCE.instrument_system_metrics
shutdown = DEFAULT_LOGFIRE_INSTANCE.shutdown

def loguru_handler() -> dict[str, Any]: ...

def no_auto_trace(x):
return x

Expand Down
10 changes: 9 additions & 1 deletion logfire-api/logfire_api/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ from .integrations.logging import LogfireLoggingHandler as LogfireLoggingHandler
from .integrations.structlog import LogfireProcessor as StructlogProcessor
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_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', 'shutdown', 'load_spans_from_file', 'no_auto_trace', 'ScrubMatch', 'ScrubbingOptions', 'VERSION', 'suppress_instrumentation', 'StructlogProcessor', 'LogfireLoggingHandler', '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_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', '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
Expand Down Expand Up @@ -49,4 +50,11 @@ warn = DEFAULT_LOGFIRE_INSTANCE.warn
error = DEFAULT_LOGFIRE_INSTANCE.error
fatal = DEFAULT_LOGFIRE_INSTANCE.fatal
exception = DEFAULT_LOGFIRE_INSTANCE.exception

def loguru_handler() -> dict[str, Any]:
"""Create a **Logfire** handler for Loguru.
Returns:
A dictionary with the handler and format for Loguru.
"""
__version__ = VERSION
8 changes: 7 additions & 1 deletion logfire-api/logfire_api/_internal/config.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,11 @@ class MetricsOptions:

@dataclass
class CodeSource:
"""Settings for the source code of the project."""
"""Settings for the source code of the project.
!!! Warning
This setting is experimental, and may change in the future!
"""
repository: str
revision: str
root_path: str
Expand Down Expand Up @@ -111,6 +115,8 @@ def configure(*, send_to_logfire: bool | Literal['if-token-present'] | None = No
Defaults to `True` if and only if the Python version is at least 3.11.
sampling: Sampling options. See the [sampling guide](https://logfire.pydantic.dev/docs/guides/advanced/sampling/).
code_source: Settings for the source code of the project.
!!! Warning
This setting is experimental, and may change in the future!
advanced: Advanced options primarily used for testing by Logfire developers.
"""

Expand Down
4 changes: 4 additions & 0 deletions tests/test_logfire_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,10 @@ def func() -> None: ...
logfire_api.LogfireLoggingHandler()
logfire__all__.remove('LogfireLoggingHandler')

assert hasattr(logfire_api, 'loguru_handler')
logfire_api.loguru_handler()
logfire__all__.remove('loguru_handler')

assert hasattr(logfire_api, 'StructlogProcessor')
logfire_api.StructlogProcessor()
logfire__all__.remove('StructlogProcessor')
Expand Down

0 comments on commit 9098435

Please sign in to comment.