@@ -1112,6 +1112,7 @@ def _log_events_to_app_insights(
11121112    otel_logger ,
11131113    events : List [Dict [str , Any ]],
11141114    log_attributes : Dict [str , Any ],
1115+     app_insights_config : AppInsightsConfig ,
11151116    data_source_item : Optional [Dict [str , Any ]] =  None ,
11161117    evaluator_config : Optional [Dict [str , EvaluatorConfig ]] =  None ,
11171118) ->  None :
@@ -1125,6 +1126,8 @@ def _log_events_to_app_insights(
11251126    :type events: List[Dict[str, Any]] 
11261127    :param log_attributes: Attributes dict to use for each event (already includes extra_attributes if present) 
11271128    :type log_attributes: Dict[str, Any] 
1129+     :param app_insights_config: App Insights configuration containing connection string 
1130+     :type app_insights_config: AppInsightsConfig 
11281131    :param data_source_item: Data source item containing trace, response, and agent information 
11291132    :type data_source_item: Optional[Dict[str, Any]] 
11301133    """ 
@@ -1133,15 +1136,17 @@ def _log_events_to_app_insights(
11331136    from  opentelemetry .trace  import  SpanContext , TraceFlags , NonRecordingSpan 
11341137
11351138    try :
1136-         # Get the trace_id and other context  from data source item  
1139+         # Initialize values  from AppInsights config as defaults  
11371140        trace_id  =  None 
11381141        span_id  =  None 
11391142        response_id  =  None 
11401143        conversation_id  =  None 
11411144        previous_response_id  =  None 
1142-         agent_id  =  None 
1143-         agent_version  =  None 
1144-         agent_name  =  None 
1145+         agent_id  =  app_insights_config .get ("agent_id" , None )
1146+         agent_version  =  app_insights_config .get ("agent_version" , None )
1147+         agent_name  =  app_insights_config .get ("agent_name" , None )
1148+ 
1149+         # Data source item values have higher priority and will override AppInsights config defaults 
11451150        if  data_source_item :
11461151            for  key , value  in  data_source_item .items ():
11471152                if  key .endswith ("trace_id" ) and  value  and  isinstance (value , str ):
@@ -1338,6 +1343,7 @@ def emit_eval_result_events_to_app_insights(
13381343                log_attributes = log_attributes ,
13391344                data_source_item = result ["datasource_item" ] if  "datasource_item"  in  result  else  None ,
13401345                evaluator_config = evaluator_config ,
1346+                 app_insights_config = app_insights_config ,
13411347            )
13421348        # Force flush to ensure events are sent 
13431349        logger_provider .force_flush ()
0 commit comments