@@ -903,25 +903,16 @@ async Task OnRunEntityBatchAsync(
903903 // Start a Server trace span for each entity operation in the batch.
904904 // Each operation may come from a different orchestration with its own trace context,
905905 // so we create individual spans to preserve correct parent-child relationships.
906- List < Activity > ? traceActivities = null ;
907- if ( batchRequest . Operations is { Count : > 0 } )
908- {
909- foreach ( OperationRequest op in batchRequest . Operations )
910- {
911- Activity ? activity = TraceHelper . StartTraceActivityForEntityOperation (
912- entityId . Name ,
913- op . Operation ,
914- batchRequest . InstanceId ! ,
915- op . TraceContext ? . TraceParent ,
916- op . TraceContext ? . TraceState ) ;
917-
918- if ( activity != null )
919- {
920- traceActivities ??= [ ] ;
921- traceActivities . Add ( activity ) ;
922- }
923- }
924- }
906+ List < Activity > traceActivities = batchRequest . Operations ?
907+ . Select ( op => TraceHelper . StartTraceActivityForEntityOperation (
908+ entityId . Name ,
909+ op . Operation ,
910+ batchRequest . InstanceId ! ,
911+ op . TraceContext ? . TraceParent ,
912+ op . TraceContext ? . TraceState ) )
913+ . OfType < Activity > ( )
914+ . ToList ( )
915+ ?? [ ] ;
925916
926917 TaskName name = new ( entityId . Name ) ;
927918
@@ -943,6 +934,9 @@ async Task OnRunEntityBatchAsync(
943934 {
944935 // we could not find the entity. This is considered an application error,
945936 // so we return a non-retriable error-OperationResult for each operation in the batch.
937+ string errorMessage = $ "No entity task named '{ name } ' was found.";
938+ traceActivities . ForEach ( a => a . SetStatus ( ActivityStatusCode . Error , errorMessage ) ) ;
939+
946940 batchResult = new EntityBatchResult ( )
947941 {
948942 Actions = [ ] , // no actions
@@ -952,7 +946,7 @@ async Task OnRunEntityBatchAsync(
952946 {
953947 FailureDetails = new FailureDetails (
954948 errorType : "EntityTaskNotFound" ,
955- errorMessage : $ "No entity task named ' { name } ' was found." ,
949+ errorMessage : errorMessage ,
956950 stackTrace : null ,
957951 innerFailure : null ,
958952 isNonRetriable : true ) ,
@@ -972,11 +966,11 @@ async Task OnRunEntityBatchAsync(
972966 FailureDetails = new FailureDetails ( frameworkException ) ,
973967 } ;
974968
975- traceActivities ? . ForEach ( a => a . SetStatus ( ActivityStatusCode . Error , frameworkException . Message ) ) ;
969+ traceActivities . ForEach ( a => a . SetStatus ( ActivityStatusCode . Error , frameworkException . Message ) ) ;
976970 }
977971 finally
978972 {
979- traceActivities ? . ForEach ( a => a . Dispose ( ) ) ;
973+ traceActivities . ForEach ( a => a . Dispose ( ) ) ;
980974 }
981975
982976 P . EntityBatchResult response = batchResult . ToEntityBatchResult (
0 commit comments