Skip to content

Commit 0e4deef

Browse files
cgillumCopilot
andcommitted
Address PR feedback: LINQ Select, entity-not-found error status
- Replace foreach loop with LINQ Select/OfType/ToList for trace activities - Mark trace activities with Error status in entity-not-found path - Use non-nullable List<Activity> initialized via LINQ expression Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent f78f80b commit 0e4deef

1 file changed

Lines changed: 16 additions & 22 deletions

File tree

src/Worker/Grpc/GrpcDurableTaskWorker.Processor.cs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)