2222from ._compat import LooseVersion
2323from ._internal import trace as libtmux_trace
2424
25+ try :
26+ from .otel import start_span
27+ except Exception : # pragma: no cover - optional dependency
28+ def start_span (name : str , ** fields ):
29+ return libtmux_trace .span (name , ** fields )
30+
2531if t .TYPE_CHECKING :
2632 from collections .abc import Callable
2733
4147
4248_RUST_BACKEND = os .getenv ("LIBTMUX_BACKEND" ) == "rust"
4349_RUST_SERVER_CACHE : dict [
44- tuple [str | None , str | None , int | None , str | None , str | None , bool | None ],
50+ tuple [
51+ str | None ,
52+ str | None ,
53+ int | None ,
54+ str | None ,
55+ str | None ,
56+ bool | None ,
57+ str | None ,
58+ ],
4559 t .Any ,
4660] = {}
4761_RUST_SERVER_CONFIG : dict [
48- tuple [str | None , str | None , int | None , str | None , str | None , bool | None ],
62+ tuple [
63+ str | None ,
64+ str | None ,
65+ int | None ,
66+ str | None ,
67+ str | None ,
68+ bool | None ,
69+ str | None ,
70+ ],
4971 set [str ],
5072] = {}
5173
@@ -88,7 +110,7 @@ def _rust_run_with_config(
88110 cmd_parts : list [str ],
89111 cmd_list : list [str ],
90112) -> tuple [list [str ], list [str ], int , list [str ]]:
91- with libtmux_trace . span (
113+ with start_span (
92114 "rust_run_with_config" ,
93115 layer = "tmux-bin" ,
94116 cmd = " " .join (cmd_parts ),
@@ -182,13 +204,17 @@ def _rust_server(
182204 connection_kind = os .getenv ("LIBTMUX_RUST_CONNECTION_KIND" )
183205 server_kind = os .getenv ("LIBTMUX_RUST_SERVER_KIND" )
184206 control_autostart = _env_bool ("LIBTMUX_RUST_CONTROL_AUTOSTART" )
207+ mux_server_bin = os .getenv ("LIBTMUX_RUST_MUX_SERVER_BIN" ) or os .getenv (
208+ "MUX_SERVER_BIN"
209+ )
185210 key = (
186211 socket_name ,
187212 socket_path ,
188213 colors ,
189214 connection_kind ,
190215 server_kind ,
191216 control_autostart ,
217+ mux_server_bin ,
192218 )
193219 server = _RUST_SERVER_CACHE .get (key )
194220 if server is None :
@@ -201,14 +227,17 @@ def _rust_server(
201227 kwargs ["server_kind" ] = server_kind
202228 if control_autostart is not None :
203229 kwargs ["control_autostart" ] = control_autostart
204- with libtmux_trace .span (
230+ if mux_server_bin :
231+ kwargs ["mux_server_bin" ] = mux_server_bin
232+ with start_span (
205233 "rust_server_init" ,
206234 layer = "python" ,
207235 socket_name = socket_name ,
208236 socket_path = socket_path ,
209237 connection_kind = connection_kind ,
210238 server_kind = server_kind ,
211239 control_autostart = control_autostart ,
240+ mux_server_bin = mux_server_bin ,
212241 ):
213242 server = rust_backend .Server (
214243 socket_path = socket_path ,
@@ -249,7 +278,10 @@ def _rust_cmd_result(
249278 connection_kind = os .getenv ("LIBTMUX_RUST_CONNECTION_KIND" )
250279 server_kind = os .getenv ("LIBTMUX_RUST_SERVER_KIND" )
251280 control_autostart = _env_bool ("LIBTMUX_RUST_CONTROL_AUTOSTART" )
252- with libtmux_trace .span (
281+ mux_server_bin = os .getenv ("LIBTMUX_RUST_MUX_SERVER_BIN" ) or os .getenv (
282+ "MUX_SERVER_BIN"
283+ )
284+ with start_span (
253285 "rust_cmd_result" ,
254286 layer = "python" ,
255287 cmd = " " .join (cmd_parts ),
@@ -259,6 +291,7 @@ def _rust_cmd_result(
259291 connection_kind = connection_kind ,
260292 server_kind = server_kind ,
261293 control_autostart = control_autostart ,
294+ mux_server_bin = mux_server_bin ,
262295 ):
263296 if connection_kind in {"bin" , "tmux-bin" } and config_file :
264297 cmd_parts = ["-f" , config_file , * cmd_parts ]
@@ -272,11 +305,12 @@ def _rust_cmd_result(
272305 connection_kind ,
273306 server_kind ,
274307 control_autostart ,
308+ mux_server_bin ,
275309 )
276310 if config_file :
277311 loaded = _RUST_SERVER_CONFIG .setdefault (key , set ())
278312 if config_file not in loaded :
279- with libtmux_trace . span ("rust_server_is_alive" , layer = "rust" ):
313+ with start_span ("rust_server_is_alive" , layer = "rust" ):
280314 server_alive = bool (server .is_alive ())
281315 if not server_alive :
282316 stdout_lines , stderr_lines , exit_code , cmd_args = (
@@ -293,7 +327,7 @@ def _rust_cmd_result(
293327 return stdout_lines , stderr_lines , exit_code , cmd_args
294328 quoted = shlex .quote (config_file )
295329 try :
296- with libtmux_trace . span (
330+ with start_span (
297331 "rust_server_source_file" ,
298332 layer = "rust" ,
299333 config_file = config_file ,
@@ -310,7 +344,7 @@ def _rust_cmd_result(
310344
311345 cmd_line = " " .join (shlex .quote (part ) for part in cmd_parts )
312346 try :
313- with libtmux_trace . span (
347+ with start_span (
314348 "rust_server_cmd" ,
315349 layer = "rust" ,
316350 cmd = cmd_line ,
@@ -557,7 +591,7 @@ class tmux_cmd:
557591
558592 def __init__ (self , * args : t .Any ) -> None :
559593 if _RUST_BACKEND :
560- with libtmux_trace . span ("tmux_cmd" , layer = "python" , backend = "rust" ):
594+ with start_span ("tmux_cmd" , layer = "python" , backend = "rust" ):
561595 stdout , stderr , returncode , cmd = _rust_cmd_result (args )
562596 self .cmd = cmd
563597 self .returncode = returncode
@@ -576,7 +610,7 @@ def __init__(self, *args: t.Any) -> None:
576610 self .cmd = cmd
577611
578612 try :
579- with libtmux_trace . span (
613+ with start_span (
580614 "tmux_cmd" ,
581615 layer = "tmux-bin" ,
582616 backend = "tmux-bin" ,
0 commit comments