Skip to content

Commit

Permalink
Release v2.0.0 (#555)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexmojaki authored Oct 30, 2024
1 parent 4c74a6d commit c1a70d3
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 27 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release Notes

## [v2.0.0] (2024-10-30)

* `@logfire.instrument()` no longer needs source code by @alexmojaki in [#543](https://github.com/pydantic/logfire/pull/543). **BREAKING CHANGES** caused by this:
* Functions decorated with `@logfire.instrument()` and functions nested within them can now be auto-traced unlike before. Use `@logfire.no_auto_trace` anywhere on functions you want to exclude, especially the instrumented function.
* Decorated async generator functions won't support the `.asend` method properly - the generator will only receive `None`. But `instrument` shouldn't be used on generators anyway unless the generator is being used as a context manager, so new warnings about this have been added. See https://logfire.pydantic.dev/docs/guides/advanced/generators/#using-logfireinstrument

## [v1.3.2] (2024-10-29)

* Handle NonRecordingSpans for fastapi arguments by @alexmojaki in [#551](https://github.com/pydantic/logfire/pull/551)
Expand Down Expand Up @@ -379,3 +385,4 @@ First release from new repo!
[v1.3.0]: https://github.com/pydantic/logfire/compare/v1.2.0...v1.3.0
[v1.3.1]: https://github.com/pydantic/logfire/compare/v1.3.0...v1.3.1
[v1.3.2]: https://github.com/pydantic/logfire/compare/v1.3.1...v1.3.2
[v2.0.0]: https://github.com/pydantic/logfire/compare/v1.3.2...v2.0.0
1 change: 0 additions & 1 deletion logfire-api/logfire_api/_internal/ast_utils.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ class LogfireArgs:
sample_rate: float | None
msg_template: str | None = ...
span_name: str | None = ...
extract_args: bool = ...

@dataclass
class BaseTransformer(ast.NodeTransformer):
Expand Down
29 changes: 13 additions & 16 deletions logfire-api/logfire_api/_internal/instrument.pyi
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import ast
from .ast_utils import BaseTransformer as BaseTransformer, LogfireArgs as LogfireArgs
from .constants import ATTRIBUTES_MESSAGE_TEMPLATE_KEY as ATTRIBUTES_MESSAGE_TEMPLATE_KEY, ATTRIBUTES_TAGS_KEY as ATTRIBUTES_TAGS_KEY
from .main import Logfire as Logfire
from dataclasses import dataclass
from types import CodeType
from typing import Callable, TypeVar
from typing_extensions import ParamSpec
from .stack_info import get_filepath_attribute as get_filepath_attribute
from .utils import safe_repr as safe_repr, uniquify_sequence as uniquify_sequence
from _typeshed import Incomplete
from collections.abc import Sequence
from opentelemetry.util import types as otel_types
from typing import Any, Callable, TypeVar
from typing_extensions import LiteralString, ParamSpec

P = ParamSpec('P')
R = TypeVar('R')
CONTEXTMANAGER_HELPER_CODE: Incomplete
ASYNCCONTEXTMANAGER_HELPER_CODE: Incomplete
GENERATOR_WARNING_MESSAGE: str

def instrument(logfire: Logfire, args: LogfireArgs) -> Callable[[Callable[P, R]], Callable[P, R]]: ...
def transform_code(func_code: CodeType, args: LogfireArgs): ...

@dataclass
class InstrumentTransformer(BaseTransformer):
"""Only modifies the function definition at the given line."""
code_lineno: int
def rewrite_function(self, node: ast.FunctionDef | ast.AsyncFunctionDef, qualname: str) -> ast.AST: ...
def logfire_method_call_node(self, node: ast.FunctionDef | ast.AsyncFunctionDef, qualname: str) -> ast.Call: ...
def logfire_method_arg_nodes(self, node: ast.FunctionDef | ast.AsyncFunctionDef, qualname: str) -> list[ast.expr]: ...
def instrument(logfire: Logfire, tags: Sequence[str], msg_template: LiteralString | None, span_name: str | None, extract_args: bool, allow_generator: bool) -> Callable[[Callable[P, R]], Callable[P, R]]: ...
def get_attributes(func: Any, msg_template: str | None, tags: Sequence[str] | None) -> dict[str, otel_types.AttributeValue]: ...
10 changes: 4 additions & 6 deletions logfire-api/logfire_api/_internal/main.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ from .config import GLOBAL_CONFIG as GLOBAL_CONFIG, LogfireConfig as LogfireConf
from .config_params import PydanticPluginRecordValues as PydanticPluginRecordValues
from .constants import ATTRIBUTES_JSON_SCHEMA_KEY as ATTRIBUTES_JSON_SCHEMA_KEY, ATTRIBUTES_LOG_LEVEL_NUM_KEY as ATTRIBUTES_LOG_LEVEL_NUM_KEY, ATTRIBUTES_MESSAGE_KEY as ATTRIBUTES_MESSAGE_KEY, ATTRIBUTES_MESSAGE_TEMPLATE_KEY as ATTRIBUTES_MESSAGE_TEMPLATE_KEY, ATTRIBUTES_SAMPLE_RATE_KEY as ATTRIBUTES_SAMPLE_RATE_KEY, ATTRIBUTES_SPAN_TYPE_KEY as ATTRIBUTES_SPAN_TYPE_KEY, ATTRIBUTES_TAGS_KEY as ATTRIBUTES_TAGS_KEY, ATTRIBUTES_VALIDATION_ERROR_KEY as ATTRIBUTES_VALIDATION_ERROR_KEY, DISABLE_CONSOLE_KEY as DISABLE_CONSOLE_KEY, LEVEL_NUMBERS as LEVEL_NUMBERS, LevelName as LevelName, NULL_ARGS_KEY as NULL_ARGS_KEY, OTLP_MAX_INT_SIZE as OTLP_MAX_INT_SIZE, log_level_attributes as log_level_attributes
from .formatter import logfire_format as logfire_format, logfire_format_with_magic as logfire_format_with_magic
from .instrument import LogfireArgs as LogfireArgs, instrument as instrument
from .instrument import instrument as instrument
from .integrations.asyncpg import AsyncPGInstrumentKwargs as AsyncPGInstrumentKwargs
from .integrations.celery import CeleryInstrumentKwargs as CeleryInstrumentKwargs
from .integrations.flask import FlaskInstrumentKwargs as FlaskInstrumentKwargs
Expand Down Expand Up @@ -218,7 +218,7 @@ class Logfire:
attributes: The arguments to include in the span and format the message template with.
Attributes starting with an underscore are not allowed.
"""
def instrument(self, msg_template: LiteralString | None = None, *, span_name: str | None = None, extract_args: bool = True) -> Callable[[Callable[P, R]], Callable[P, R]]:
def instrument(self, msg_template: LiteralString | None = None, *, span_name: str | None = None, extract_args: bool = True, allow_generator: bool = False) -> Callable[[Callable[P, R]], Callable[P, R]]:
"""Decorator for instrumenting a function as a span.
```py
Expand All @@ -232,14 +232,12 @@ class Logfire:
logfire.info('new log {a=}', a=a)
```
!!! note
- This decorator MUST be applied first, i.e. UNDER any other decorators.
- The source code of the function MUST be accessible.
Args:
msg_template: The template for the span message. If not provided, the module and function name will be used.
span_name: The span name. If not provided, the `msg_template` will be used.
extract_args: Whether to extract arguments from the function signature and log them as span attributes.
allow_generator: Set to `True` to prevent a warning when instrumenting a generator function.
Read https://logfire.pydantic.dev/docs/guides/advanced/generators/#using-logfireinstrument first.
"""
def log(self, level: LevelName | int, msg_template: str, attributes: dict[str, Any] | None = None, tags: Sequence[str] | None = None, exc_info: ExcInfo = False, console_log: bool | None = None) -> None:
"""Log a message.
Expand Down
2 changes: 1 addition & 1 deletion logfire-api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "logfire-api"
version = "1.3.2"
version = "2.0.0"
description = "Shim for the Logfire SDK which does nothing unless Logfire is installed"
authors = [
{ name = "Pydantic Team", email = "engineering@pydantic.dev" },
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "hatchling.build"

[project]
name = "logfire"
version = "1.3.2"
version = "2.0.0"
description = "The best Python observability tool! 🪵🔥"
requires-python = ">=3.8"
authors = [
Expand Down
4 changes: 2 additions & 2 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c1a70d3

Please sign in to comment.