3737from msgflux .models .model import Model
3838from msgflux .models .response import ModelResponse , ModelStreamResponse
3939from msgflux .nn .parameter import Parameter
40- from msgflux .telemetry .span import spans
40+ from msgflux .telemetry import Spans
41+ from msgtrace .sdk import MsgTraceAttributes
4142from msgflux .utils .convert import convert_camel_snake_to_title
4243from msgflux .utils .encode import encode_data_to_base64
4344from msgflux .utils .hooks import RemovableHandle
@@ -401,7 +402,6 @@ def __init__(self, *args, **kwargs) -> None:
401402 super ().__setattr__ ("_load_state_dict_pre_hooks" , OrderedDict ())
402403 super ().__setattr__ ("_load_state_dict_post_hooks" , OrderedDict ())
403404 super ().__setattr__ ("_modules" , {})
404- super ().__setattr__ ("_spans" , spans )
405405
406406 if self .call_super_init :
407407 super ().__init__ (* args , ** kwargs )
@@ -1382,8 +1382,10 @@ def _execute_with_span(self, module_name_title: str, module_type: str, *args, **
13821382 Returns:
13831383 Module output from forward method
13841384 """
1385- with self . _spans .init_module (module_name_title , module_type ) as span :
1385+ with Spans .init_module (module_name_title , module_type ) as span :
13861386 try :
1387+ MsgTraceAttributes .set_module_name (module_name_title )
1388+ MsgTraceAttributes .set_module_type (module_type )
13871389 result = self .forward (* args , ** kwargs )
13881390 span .set_status (Status (StatusCode .OK ))
13891391 return result
@@ -1406,10 +1408,12 @@ def _call(self, *args, **kwargs):
14061408 current_span = trace .get_current_span ()
14071409 # If there is no active span or it is not recording, this is the root module
14081410 if current_span is None or not current_span .is_recording ():
1409- with self . _spans .init_flow (
1411+ with Spans .init_flow (
14101412 module_name_title , module_type , encoded_state_dict
14111413 ) as span :
14121414 try :
1415+ MsgTraceAttributes .set_module_name (module_name_title )
1416+ MsgTraceAttributes .set_module_type (module_type )
14131417 module_output = self .forward (* args , ** kwargs )
14141418 span .set_status (Status (StatusCode .OK ))
14151419 return module_output
@@ -1458,8 +1462,10 @@ async def _aexecute_with_span(self, module_name_title: str, module_type: str, *a
14581462 Returns:
14591463 Module output from aforward method
14601464 """
1461- async with self . _spans .ainit_module (module_name_title , module_type ) as span :
1465+ async with Spans .ainit_module (module_name_title , module_type ) as span :
14621466 try :
1467+ MsgTraceAttributes .set_module_name (module_name_title )
1468+ MsgTraceAttributes .set_module_type (module_type )
14631469 result = await self .aforward (* args , ** kwargs )
14641470 span .set_status (Status (StatusCode .OK ))
14651471 return result
@@ -1482,10 +1488,12 @@ async def _acall(self, *args, **kwargs):
14821488 current_span = trace .get_current_span ()
14831489 # If there is no active span or it is not recording, this is the root module
14841490 if current_span is None or not current_span .is_recording ():
1485- async with self . _spans .ainit_flow (
1491+ async with Spans .ainit_flow (
14861492 module_name_title , module_type , encoded_state_dict
14871493 ) as span :
14881494 try :
1495+ MsgTraceAttributes .set_module_name (module_name_title )
1496+ MsgTraceAttributes .set_module_type (module_type )
14891497 module_output = await self .aforward (* args , ** kwargs )
14901498 span .set_status (Status (StatusCode .OK ))
14911499 return module_output
0 commit comments