Skip to content

Commit a0866e2

Browse files
authored
Add include_binary_content to instrument_pydantic_ai (#1090)
1 parent cbfeb75 commit a0866e2

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

logfire/_internal/main.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -962,6 +962,7 @@ def instrument_pydantic_ai(
962962
/,
963963
*,
964964
event_mode: Literal['attributes', 'logs'] = 'attributes',
965+
include_binary_content: bool | None = None,
965966
**kwargs: Any,
966967
) -> None: ...
967968

@@ -972,6 +973,7 @@ def instrument_pydantic_ai(
972973
/,
973974
*,
974975
event_mode: Literal['attributes', 'logs'] = 'attributes',
976+
include_binary_content: bool | None = None,
975977
**kwargs: Any,
976978
) -> pydantic_ai.models.Model: ...
977979

@@ -981,6 +983,7 @@ def instrument_pydantic_ai(
981983
/,
982984
*,
983985
event_mode: Literal['attributes', 'logs'] | None = None,
986+
include_binary_content: bool | None = None,
984987
**kwargs: Any,
985988
) -> pydantic_ai.models.Model | None:
986989
"""Instrument PydanticAI.
@@ -992,13 +995,19 @@ def instrument_pydantic_ai(
992995
If you pass a model, a new instrumented model will be returned.
993996
event_mode: See the [PydanticAI docs](https://ai.pydantic.dev/logfire/#data-format).
994997
The default is whatever the default is in your version of PydanticAI.
998+
include_binary_content: Whether to include base64 encoded binary content (e.g. images) in the events.
999+
On by default. Requires PydanticAI 0.2.5 or newer.
9951000
kwargs: Additional keyword arguments to pass to
9961001
[`InstrumentationSettings`](https://ai.pydantic.dev/api/models/instrumented/#pydantic_ai.models.instrumented.InstrumentationSettings)
9971002
for future compatibility.
9981003
"""
9991004
from .integrations.pydantic_ai import instrument_pydantic_ai
10001005

10011006
self._warn_if_not_initialized_for_instrumentation()
1007+
1008+
if include_binary_content is not None:
1009+
kwargs['include_binary_content'] = include_binary_content
1010+
10021011
return instrument_pydantic_ai(
10031012
self,
10041013
obj=obj,

tests/otel_integrations/test_pydantic_ai.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,17 @@ def get_model(a: Agent):
5555
assert m2 is model
5656

5757
# Now instrument all agents. Also use the (currently not default) event mode.
58-
logfire_inst.instrument_pydantic_ai(event_mode='logs')
58+
logfire_inst.instrument_pydantic_ai(event_mode='logs', include_binary_content=False)
5959
m = get_model(agent1)
6060
assert isinstance(m, InstrumentedModel)
6161
# agent1 still has its own instrumentation settings which override the global ones.
6262
assert m.settings.event_mode == InstrumentationSettings().event_mode == 'attributes'
63+
assert m.settings.include_binary_content == InstrumentationSettings().include_binary_content
6364
# agent2 uses the global settings.
6465
m2 = get_model(agent2)
6566
assert isinstance(m2, InstrumentedModel)
6667
assert m2.settings.event_mode == 'logs'
68+
assert not m2.settings.include_binary_content
6769

6870
# Remove the global instrumentation. agent1 remains instrumented.
6971
Agent.instrument_all(False)

0 commit comments

Comments
 (0)