Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix patching of ProcessPoolExecutor #690

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions logfire/_internal/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -578,6 +578,9 @@ def _load_configuration(
if isinstance(advanced, dict):
# This is particularly for deserializing from a dict as in executors.py
advanced = AdvancedOptions(**advanced) # type: ignore
id_generator = advanced.id_generator
if isinstance(id_generator, dict) and list(id_generator.keys()) == ['seed']: # type: ignore # pragma: no branch
advanced.id_generator = SeededRandomIdGenerator(**id_generator) # type: ignore
elif advanced is None:
advanced = AdvancedOptions(base_url=param_manager.load_param('base_url'))
self.advanced = advanced
Expand Down
5 changes: 3 additions & 2 deletions logfire/_internal/integrations/executors.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ def serialize_config() -> dict[str, Any]:


def deserialize_config(config: dict[str, Any]) -> None:
from ..config import configure
from ..config import GLOBAL_CONFIG, configure

configure(**config)
if not GLOBAL_CONFIG._initialized: # type: ignore
configure(**config)
6 changes: 3 additions & 3 deletions tests/test_configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
from logfire._internal.exporters.wrapper import WrapperSpanExporter
from logfire._internal.integrations.executors import deserialize_config, serialize_config
from logfire._internal.tracer import PendingSpanProcessor
from logfire._internal.utils import get_version
from logfire._internal.utils import SeededRandomIdGenerator, get_version
from logfire.exceptions import LogfireConfigError
from logfire.integrations.pydantic import get_pydantic_plugin_config
from logfire.testing import TestExporter
Expand Down Expand Up @@ -848,14 +848,13 @@ def test_config_serializable():
)

serialized = serialize_config()
GLOBAL_CONFIG._initialized = False # type: ignore # ensure deserialize_config actually configures
deserialize_config(serialized)
serialized2 = serialize_config()

def normalize(s: dict[str, Any]) -> dict[str, Any]:
for value in s.values():
assert not dataclasses.is_dataclass(value)
# This gets deepcopied by dataclasses.asdict, so we can't compare them directly
del s['advanced']['id_generator']
return s

assert normalize(serialized) == normalize(serialized2)
Expand All @@ -864,6 +863,7 @@ def normalize(s: dict[str, Any]) -> dict[str, Any]:
assert isinstance(GLOBAL_CONFIG.sampling, logfire.SamplingOptions)
assert isinstance(GLOBAL_CONFIG.scrubbing, logfire.ScrubbingOptions)
assert isinstance(GLOBAL_CONFIG.advanced, logfire.AdvancedOptions)
assert isinstance(GLOBAL_CONFIG.advanced.id_generator, SeededRandomIdGenerator)


def test_config_serializable_console_false():
Expand Down
Loading