diff --git a/logfire/_internal/config.py b/logfire/_internal/config.py index a560b2f19..753b8b70b 100644 --- a/logfire/_internal/config.py +++ b/logfire/_internal/config.py @@ -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 diff --git a/logfire/_internal/integrations/executors.py b/logfire/_internal/integrations/executors.py index e4a7c31f1..5176593e9 100644 --- a/logfire/_internal/integrations/executors.py +++ b/logfire/_internal/integrations/executors.py @@ -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) diff --git a/tests/test_configure.py b/tests/test_configure.py index ee4484b0e..40e6276a2 100644 --- a/tests/test_configure.py +++ b/tests/test_configure.py @@ -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 @@ -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) @@ -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():