File tree Expand file tree Collapse file tree
instrumentation-loongsuite/loongsuite-instrumentation-microsoft-agent-framework
src/opentelemetry/instrumentation/microsoft_agent_framework Expand file tree Collapse file tree Original file line number Diff line number Diff line change 9494_EDGE_GROUP_PROCESS = "edge_group.process"
9595_LIVE_SPAN_MAX_AGE_NS = 60 * 1_000_000_000
9696_GEN_AI_TOOL_NAME = "gen_ai.tool.name"
97+ _FRAMEWORK_PROVIDER_NAME = "microsoft.agent_framework"
9798
9899
99100def _attr_value (span : Any , key : str ) -> Any :
@@ -876,6 +877,16 @@ def _apply_semantic_attributes(
876877 normalized = _normalize_provider (provider )
877878 if normalized is not None and normalized != provider :
878879 _set_attr (live , GEN_AI_PROVIDER_NAME , normalized )
880+ elif (
881+ normalized is None
882+ and span_kind == GenAISpanKind .AGENT
883+ and op_name
884+ in {
885+ GenAIOperation .CREATE_AGENT ,
886+ GenAIOperation .INVOKE_AGENT ,
887+ }
888+ ):
889+ _set_attr (live , GEN_AI_PROVIDER_NAME , _FRAMEWORK_PROVIDER_NAME )
879890
880891 # 5) Normalize finish reasons written by MAF as a JSON string.
881892 _normalize_finish_reasons (live , readable )
Original file line number Diff line number Diff line change 7676 GenAISpanKind ,
7777)
7878from .span_processor import (
79+ _FRAMEWORK_PROVIDER_NAME ,
7980 _attr_value ,
8081 _classify_span ,
8182 _is_exception_event ,
@@ -598,6 +599,11 @@ def _set_common_live_attributes(
598599 provider = _normalize_provider (_attr_value (span , GEN_AI_PROVIDER_NAME ))
599600 if provider is not None :
600601 span .set_attribute (GEN_AI_PROVIDER_NAME , provider )
602+ elif span_kind == GenAISpanKind .AGENT and op_name in {
603+ GenAIOperation .CREATE_AGENT ,
604+ GenAIOperation .INVOKE_AGENT ,
605+ }:
606+ span .set_attribute (GEN_AI_PROVIDER_NAME , _FRAMEWORK_PROVIDER_NAME )
601607 finish_reasons = _finish_reasons (span )
602608 if finish_reasons :
603609 span .set_attribute (GEN_AI_RESPONSE_FINISH_REASONS , finish_reasons )
Original file line number Diff line number Diff line change @@ -207,6 +207,9 @@ def test_executor_process_agent_executor_becomes_agent():
207207 assert (
208208 s .attributes .get (GEN_AI_OPERATION_NAME ) == GenAIOperation .INVOKE_AGENT
209209 )
210+ assert (
211+ s .attributes .get (GEN_AI_PROVIDER_NAME ) == "microsoft.agent_framework"
212+ )
210213
211214
212215def test_executor_process_unknown_executor_stays_workflow_operation ():
Original file line number Diff line number Diff line change @@ -303,6 +303,28 @@ def test_agent_span_is_finalized_by_util_genai_before_export(monkeypatch):
303303 assert span .attributes .get ("gen_ai.agent.id" ) == "agent-1"
304304
305305
306+ def test_agent_span_gets_framework_provider_when_missing (monkeypatch ):
307+ obs_mod , exporter = _install_fake_observability (monkeypatch )
308+ util_genai_bridge .apply_util_genai_bridge ()
309+ try :
310+ with obs_mod ._get_span (
311+ {
312+ GEN_AI_OPERATION_NAME : GenAIOperation .INVOKE_AGENT ,
313+ "gen_ai.agent.name" : "planner" ,
314+ },
315+ "gen_ai.agent.name" ,
316+ ):
317+ pass
318+ finally :
319+ util_genai_bridge .revert_util_genai_bridge ()
320+
321+ span = exporter .get_finished_spans ()[0 ]
322+ assert (
323+ span .attributes .get (GEN_AI_PROVIDER_NAME )
324+ == "microsoft.agent_framework"
325+ )
326+
327+
306328def test_mcp_span_is_seeded_before_export (monkeypatch ):
307329 obs_mod , exporter = _install_fake_observability (monkeypatch )
308330 util_genai_bridge .apply_util_genai_bridge ()
You can’t perform that action at this time.
0 commit comments