diff --git a/logfire/_internal/main.py b/logfire/_internal/main.py index ae6b49548..897a55ffb 100644 --- a/logfire/_internal/main.py +++ b/logfire/_internal/main.py @@ -962,6 +962,7 @@ def instrument_pydantic_ai( /, *, event_mode: Literal['attributes', 'logs'] = 'attributes', + include_binary_content: bool | None = None, **kwargs: Any, ) -> None: ... @@ -972,6 +973,7 @@ def instrument_pydantic_ai( /, *, event_mode: Literal['attributes', 'logs'] = 'attributes', + include_binary_content: bool | None = None, **kwargs: Any, ) -> pydantic_ai.models.Model: ... @@ -981,6 +983,7 @@ def instrument_pydantic_ai( /, *, event_mode: Literal['attributes', 'logs'] | None = None, + include_binary_content: bool | None = None, **kwargs: Any, ) -> pydantic_ai.models.Model | None: """Instrument PydanticAI. @@ -992,6 +995,8 @@ def instrument_pydantic_ai( If you pass a model, a new instrumented model will be returned. event_mode: See the [PydanticAI docs](https://ai.pydantic.dev/logfire/#data-format). The default is whatever the default is in your version of PydanticAI. + include_binary_content: Whether to include base64 encoded binary content (e.g. images) in the events. + On by default. Requires PydanticAI 0.2.5 or newer. kwargs: Additional keyword arguments to pass to [`InstrumentationSettings`](https://ai.pydantic.dev/api/models/instrumented/#pydantic_ai.models.instrumented.InstrumentationSettings) for future compatibility. @@ -999,6 +1004,10 @@ def instrument_pydantic_ai( from .integrations.pydantic_ai import instrument_pydantic_ai self._warn_if_not_initialized_for_instrumentation() + + if include_binary_content is not None: + kwargs['include_binary_content'] = include_binary_content + return instrument_pydantic_ai( self, obj=obj, diff --git a/tests/otel_integrations/test_pydantic_ai.py b/tests/otel_integrations/test_pydantic_ai.py index dc9f991f0..4cb3256d7 100644 --- a/tests/otel_integrations/test_pydantic_ai.py +++ b/tests/otel_integrations/test_pydantic_ai.py @@ -55,15 +55,17 @@ def get_model(a: Agent): assert m2 is model # Now instrument all agents. Also use the (currently not default) event mode. - logfire_inst.instrument_pydantic_ai(event_mode='logs') + logfire_inst.instrument_pydantic_ai(event_mode='logs', include_binary_content=False) m = get_model(agent1) assert isinstance(m, InstrumentedModel) # agent1 still has its own instrumentation settings which override the global ones. assert m.settings.event_mode == InstrumentationSettings().event_mode == 'attributes' + assert m.settings.include_binary_content == InstrumentationSettings().include_binary_content # agent2 uses the global settings. m2 = get_model(agent2) assert isinstance(m2, InstrumentedModel) assert m2.settings.event_mode == 'logs' + assert not m2.settings.include_binary_content # Remove the global instrumentation. agent1 remains instrumented. Agent.instrument_all(False)