Skip to content

Commit 67d454b

Browse files
committed
Recommend disabling DBOS OTLP traces when using logfire
1 parent 7a61d2a commit 67d454b

File tree

4 files changed

+46
-38
lines changed

4 files changed

+46
-38
lines changed

docs/durable_execution/dbos.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,10 @@ You can customize DBOS's retry policy using [step configuration](#step-configura
140140

141141
## Observability with Logfire
142142

143-
DBOS emits OpenTelemetry traces and events for every workflow and step, and Pydantic AI generates events for each agent run, model request and tool call. These can be sent to [Pydantic Logfire](../logfire.md) to get a complete picture of what's happening in your application.
143+
DBOS emits OpenTelemetry traces and events for every workflow and step, and Pydantic AI generates events for each agent run, model request and tool call. Both can be sent to [Pydantic Logfire](../logfire.md) for observability.
144+
145+
⚠️ However, we **recommend disabling DBOS's built-in OpenTelemetry tracing** when using Logfire.
146+
Otherwise, you may see duplicate or conflicting traces, since both DBOS and Logfire emit overlapping information.
144147

145148
To disable DBOS traces and logs, you can set `disable_otlp=True` in `DBOSConfig`. For example:
146149

pydantic_ai_slim/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ retries = ["tenacity>=8.2.3"]
9595
# Temporal
9696
temporal = ["temporalio==1.16.0"]
9797
# DBOS (Update version before merge)
98-
dbos = ["dbos>=1.13.0a5"]
98+
dbos = ["dbos>=1.13.0"]
9999

100100

101101
[tool.hatch.metadata]

tests/test_dbos.py

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -82,16 +82,11 @@ async def close_cached_httpx_client(anyio_backend: str) -> AsyncIterator[None]:
8282
await http_client.aclose()
8383

8484

85-
# Our setup calls `logfire.instrument_pydantic_ai()`, so we need to make sure this doesn't bleed into other tests.
8685
@pytest.fixture(autouse=True, scope='module')
87-
def uninstrument_pydantic_ai() -> Iterator[None]:
88-
try:
89-
# Set up logfire for the tests.
90-
logfire.configure(metrics=False)
91-
logfire.instrument_pydantic_ai()
92-
yield
93-
finally:
94-
Agent.instrument_all(False)
86+
def setup_logfire_instrumentation() -> Iterator[None]:
87+
# Set up logfire for the tests.
88+
logfire.configure(metrics=False)
89+
yield
9590

9691

9792
@contextmanager
@@ -109,6 +104,7 @@ def workflow_raises(exc_type: type[Exception], exc_message: str) -> Iterator[Non
109104
'database_url': f'sqlite:///{DBOS_SQLITE_FILE}',
110105
'system_database_url': f'sqlite:///{DBOS_SQLITE_FILE}',
111106
'run_admin_server': False,
107+
'disable_otlp': True, # Disable DBOS OTLP to avoid conflicts with logfire
112108
}
113109

114110

@@ -217,6 +213,7 @@ class BasicSpan:
217213
],
218214
tools=[get_weather],
219215
event_stream_handler=event_stream_handler,
216+
instrument=True, # Enable instrumentation for testing
220217
name='complex_agent',
221218
)
222219
complex_dbos_agent = DBOSAgent(complex_agent)
@@ -262,11 +259,10 @@ async def test_complex_agent_run_in_workflow(allow_model_requests: None, dbos: D
262259
# Assert the root span and its structure matches expected hierarchy
263260
assert root_span == snapshot(
264261
BasicSpan(
265-
content='complex_agent.run',
262+
content='complex_agent run',
266263
children=[
267-
BasicSpan(content='complex_agent__mcp_server__mcp.get_tools'),
268264
BasicSpan(
269-
content='complex_agent__model.request_stream',
265+
content='chat gpt-4o',
270266
children=[
271267
BasicSpan(content='ctx.run_step=1'),
272268
BasicSpan(
@@ -281,30 +277,35 @@ async def test_complex_agent_run_in_workflow(allow_model_requests: None, dbos: D
281277
BasicSpan(
282278
content='{"index":1,"delta":{"tool_name_delta":null,"args_delta":"{}","tool_call_id":"call_Xw9XMKBJU48kAAd78WgIswDx","part_delta_kind":"tool_call"},"event_kind":"part_delta"}'
283279
),
280+
BasicSpan(content='ctx.run_step=1'),
284281
],
285282
),
286283
BasicSpan(content='ctx.run_step=1'),
287-
BasicSpan(content='ctx.run_step=1'),
288284
BasicSpan(
289285
content='{"part":{"tool_name":"get_country","args":"{}","tool_call_id":"call_3rqTYrA6H21AYUaRGP4F66oq","part_kind":"tool-call"},"event_kind":"function_tool_call"}'
290286
),
291287
BasicSpan(
292288
content='{"part":{"tool_name":"get_product_name","args":"{}","tool_call_id":"call_Xw9XMKBJU48kAAd78WgIswDx","part_kind":"tool-call"},"event_kind":"function_tool_call"}'
293289
),
294290
BasicSpan(
295-
content=IsStr(
296-
regex=r'{"result":{"tool_name":"get_country","content":"Mexico","tool_call_id":"call_3rqTYrA6H21AYUaRGP4F66oq","metadata":null,"timestamp":".+?","part_kind":"tool-return"},"event_kind":"function_tool_result"}'
297-
)
298-
),
299-
BasicSpan(content='complex_agent__mcp_server__mcp.call_tool'),
300-
BasicSpan(
301-
content=IsStr(
302-
regex=r'{"result":{"tool_name":"get_product_name","content":"Pydantic AI","tool_call_id":"call_Xw9XMKBJU48kAAd78WgIswDx","metadata":null,"timestamp":".+?","part_kind":"tool-return"},"event_kind":"function_tool_result"}'
303-
)
291+
content='running 2 tools',
292+
children=[
293+
BasicSpan(content='running tool: get_country'),
294+
BasicSpan(
295+
content=IsStr(
296+
regex=r'{"result":{"tool_name":"get_country","content":"Mexico","tool_call_id":"call_3rqTYrA6H21AYUaRGP4F66oq","metadata":null,"timestamp":".+?","part_kind":"tool-return"},"event_kind":"function_tool_result"}'
297+
)
298+
),
299+
BasicSpan(content='running tool: get_product_name'),
300+
BasicSpan(
301+
content=IsStr(
302+
regex=r'{"result":{"tool_name":"get_product_name","content":"Pydantic AI","tool_call_id":"call_Xw9XMKBJU48kAAd78WgIswDx","metadata":null,"timestamp":".+?","part_kind":"tool-return"},"event_kind":"function_tool_result"}'
303+
)
304+
),
305+
],
304306
),
305-
BasicSpan(content='complex_agent__mcp_server__mcp.get_tools'),
306307
BasicSpan(
307-
content='complex_agent__model.request_stream',
308+
content='chat gpt-4o',
308309
children=[
309310
BasicSpan(content='ctx.run_step=2'),
310311
BasicSpan(
@@ -328,22 +329,26 @@ async def test_complex_agent_run_in_workflow(allow_model_requests: None, dbos: D
328329
BasicSpan(
329330
content='{"index":0,"delta":{"tool_name_delta":null,"args_delta":"\\"}","tool_call_id":"call_Vz0Sie91Ap56nH0ThKGrZXT7","part_delta_kind":"tool_call"},"event_kind":"part_delta"}'
330331
),
332+
BasicSpan(content='ctx.run_step=2'),
331333
],
332334
),
333335
BasicSpan(content='ctx.run_step=2'),
334-
BasicSpan(content='ctx.run_step=2'),
335336
BasicSpan(
336337
content='{"part":{"tool_name":"get_weather","args":"{\\"city\\":\\"Mexico City\\"}","tool_call_id":"call_Vz0Sie91Ap56nH0ThKGrZXT7","part_kind":"tool-call"},"event_kind":"function_tool_call"}'
337338
),
338-
BasicSpan(content='get_weather'),
339339
BasicSpan(
340-
content=IsStr(
341-
regex=r'{"result":{"tool_name":"get_weather","content":"sunny","tool_call_id":"call_Vz0Sie91Ap56nH0ThKGrZXT7","metadata":null,"timestamp":".+?","part_kind":"tool-return"},"event_kind":"function_tool_result"}'
342-
)
340+
content='running 1 tool',
341+
children=[
342+
BasicSpan(content='running tool: get_weather'),
343+
BasicSpan(
344+
content=IsStr(
345+
regex=r'{"result":{"tool_name":"get_weather","content":"sunny","tool_call_id":"call_Vz0Sie91Ap56nH0ThKGrZXT7","metadata":null,"timestamp":".+?","part_kind":"tool-return"},"event_kind":"function_tool_result"}'
346+
)
347+
),
348+
],
343349
),
344-
BasicSpan(content='complex_agent__mcp_server__mcp.get_tools'),
345350
BasicSpan(
346-
content='complex_agent__model.request_stream',
351+
content='chat gpt-4o',
347352
children=[
348353
BasicSpan(content='ctx.run_step=3'),
349354
BasicSpan(
@@ -472,10 +477,10 @@ async def test_complex_agent_run_in_workflow(allow_model_requests: None, dbos: D
472477
BasicSpan(
473478
content='{"index":0,"delta":{"tool_name_delta":null,"args_delta":"]}","tool_call_id":"call_4kc6691zCzjPnOuEtbEGUvz2","part_delta_kind":"tool_call"},"event_kind":"part_delta"}'
474479
),
480+
BasicSpan(content='ctx.run_step=3'),
475481
],
476482
),
477483
BasicSpan(content='ctx.run_step=3'),
478-
BasicSpan(content='ctx.run_step=3'),
479484
],
480485
)
481486
)

uv.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)