Open-source Python library for AI browser agents, plus Browser Use Cloud: stealth browsers and a hosted agent API.
Python ai-agentsai-toolsbrowser-agentbrowser-automationbrowser-usecdpcloud-browsercomputer-useheadless-browserllmmcpplaywrightpythonremote-browserstealth-browserweb-automationweb-scraping
Expose Rust agent Laminar trace id
Magnus Müllerb48dae628240
diff --git a/browser_use/rust/service.py b/browser_use/rust/service.pyindex a7932065d..f4f2a63c1 100644--- a/browser_use/rust/service.py+++ b/browser_use/rust/service.py@@ -170,6 +170,16 @@ def _laminar_force_flush() -> None:logger.debug('Failed to flush Laminar via %s', method_name, exc_info=True)+def _laminar_current_trace_id() -> str | None:+ if not _laminar_ready():+ return None+ try:+ trace_id = Laminar.get_trace_id()+ except Exception:+ return None+ return str(trace_id) if trace_id else None++def find_browser_use_terminal_binary() -> str:"""Find the terminal binary used by the Rust-backed Browser Use Agent."""env_path = os.environ.get('BROWSER_USE_TERMINAL_BINARY')@@ -3732,6 +3742,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):self.browser_session.llm_screenshot_size = llm_screenshot_sizeself.session_id: str = uuid7str()self.terminal_session_id: str | None = None+ self.laminar_trace_id: str | None = Noneself.history: AgentHistoryList[AgentStructuredOutput] = AgentHistoryList(history=[], usage=None)self.result: AgentHistoryList[AgentStructuredOutput] | None = Noneself.last_events: list[dict[str, Any]] = []@@ -4229,6 +4240,7 @@ class Agent(Generic[Context, AgentStructuredOutput]):on_step_start: AgentHookFunc | None = None,on_step_end: AgentHookFunc | None = None,) -> AgentHistoryList[AgentStructuredOutput]:+ self.laminar_trace_id = _laminar_current_trace_id()self._register_run_signal_handler(max_steps)try:return await self._run_terminal(max_steps=max_steps, on_step_start=on_step_start, on_step_end=on_step_end)diff --git a/tests/ci/test_rust_agent.py b/tests/ci/test_rust_agent.pyindex 72367cd4c..5f675b164 100644--- a/tests/ci/test_rust_agent.py+++ b/tests/ci/test_rust_agent.py@@ -7467,6 +7467,32 @@ async def test_rust_agent_trace_and_cloud_auth_helpers():assert 'trace answer' in trace_object['trace_details']['complete_history']+async def test_rust_agent_run_exposes_laminar_trace_id_for_eval_links(monkeypatch):+ from browser_use.rust import Agent+ import browser_use.rust.service as rust_service++ class FakeLaminar:+ @staticmethod+ def is_initialized():+ return True++ @staticmethod+ def get_trace_id():+ return '01234567-89ab-cdef-0123-456789abcdef'++ async def fake_run_terminal(self, max_steps, on_step_start, on_step_end):+ return self.history++ monkeypatch.setattr(rust_service, 'Laminar', FakeLaminar)+ monkeypatch.setattr(rust_service.Agent, '_run_terminal', fake_run_terminal)++ agent = Agent(task='Trace link task.', llm=type('LLM', (), {'model': 'claude-sonnet-4-6'})())++ await agent.run(max_steps=3)++ assert agent.laminar_trace_id == '01234567-89ab-cdef-0123-456789abcdef'++def test_rust_agent_laminar_run_summary_populates_current_span(monkeypatch):from browser_use.rust import Agentimport browser_use.rust.service as rust_service