From 76523e844dbf9db99438e4bee0f7cdd9ab4088e7 Mon Sep 17 00:00:00 2001 From: Alex Hall Date: Fri, 24 Oct 2025 16:38:05 +0200 Subject: [PATCH] Preformat run graph/node span names for other OTel backends --- pydantic_graph/pydantic_graph/graph.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/pydantic_graph/pydantic_graph/graph.py b/pydantic_graph/pydantic_graph/graph.py index 64cd2aac60..4944f6d846 100644 --- a/pydantic_graph/pydantic_graph/graph.py +++ b/pydantic_graph/pydantic_graph/graph.py @@ -239,7 +239,11 @@ async def iter( entered_span: AbstractSpan | None = None if span is None: if self.auto_instrument: # pragma: no branch - entered_span = stack.enter_context(logfire_span('run graph {graph.name}', graph=self)) + # Separate variable because we actually don't want logfire's f-string magic here, + # we want the span_name to be preformatted for other backends + # as requested in https://github.com/pydantic/pydantic-ai/issues/3173. + span_name = f'run graph {self.name}' + entered_span = stack.enter_context(logfire_span(span_name, graph=self)) else: entered_span = stack.enter_context(span) traceparent = None if entered_span is None else get_traceparent(entered_span) @@ -724,7 +728,11 @@ async def main(): with ExitStack() as stack: if self.graph.auto_instrument: # pragma: no branch - stack.enter_context(logfire_span('run node {node_id}', node_id=node_id, node=node)) + # Separate variable because we actually don't want logfire's f-string magic here, + # we want the span_name to be preformatted for other backends + # as requested in https://github.com/pydantic/pydantic-ai/issues/3173. + span_name = f'run node {node_id}' + stack.enter_context(logfire_span(span_name, node_id=node_id, node=node)) async with self.persistence.record_run(node_snapshot_id): ctx = GraphRunContext(state=self.state, deps=self.deps)