Skip to content

Add workflow context propagation sample#1327

Merged
alicejgibbons merged 4 commits into
dapr:release-1.18from
atrauzzi:sdk-context-propagation-update
Jun 10, 2026
Merged

Add workflow context propagation sample#1327
alicejgibbons merged 4 commits into
dapr:release-1.18from
atrauzzi:sdk-context-propagation-update

Conversation

@atrauzzi

@atrauzzi atrauzzi commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Supercedes #1310

Summary

Scenario

Patient intake / e-prescribing pipeline. A compliance audit and a pharmacy dispense step refuse to act unless the propagated history proves the required upstream checks (insurance, allergies, drug interactions) actually ran.

PatientIntake (root)
  └─ VerifyInsurance         (activity, no propagation)
  └─ PrescribeMedication     (child wf, HistoryPropagationScope.Lineage)
        └─ CheckAllergies                 (activity, no propagation)
        └─ ScreenDrugInteractions         (activity, no propagation)
        └─ ComplianceAudit                (grandchild wf, HistoryPropagationScope.Lineage)
        |      reads PatientIntake + PrescribeMedication events
        └─ DispenseMedicationWorkflow     (grandchild wf, HistoryPropagationScope.OwnHistory)
               reads PrescribeMedication events only
               └─ DispenseMedication       (activity)

.NET API used (from dapr/dotnet-sdk#1802)

  • HistoryPropagationScope enum: None, OwnHistory, Lineage
  • ChildWorkflowTaskOptions(PropagationScope: HistoryPropagationScope.Lineage) — passed to CallChildWorkflowAsync
  • WorkflowContext.GetPropagatedHistory()PropagatedHistory?
  • PropagatedHistory.FilterByWorkflowName(name) → filtered PropagatedHistory
  • PropagatedHistoryEntry — has WorkflowName, AppId, InstanceId, Events
  • PropagatedHistoryEvent — has EventId, Kind (HistoryEventKind), Timestamp

Key difference from the Python/Go siblings

The Python SDK and Go SDK both support a propagation argument on bare activity calls, so they call DispenseMedication as a plain activity with OWN_HISTORY. The .NET SDK v1.18 scopes HistoryPropagationScope to ChildWorkflowTaskOptions only — activity calls do not carry a propagation scope. To demonstrate identical OwnHistory trust-boundary semantics, DispenseMedicationActivity is wrapped in DispenseMedicationWorkflow (a child workflow). This is the correct .NET idiom for the v1.18 API; it is not a gap in the sample.

Replay safety

All Console.WriteLine calls inside workflows are guarded by if (!ctx.IsReplaying) so they only fire on the live execution, not on each durable replay.

Status — DRAFT

  • 7 files added, dotnet build not validated locally (dotnet SDK not on path — CI will catch compile errors)
  • Smoke-test pending Dapr 1.18 RC sidecar + Dapr.Workflow 1.18.0-rc01 on NuGet
  • Will be marked ready once: (1) Go reference dapr/go-sdk#823 merges, (2) Python sibling #1309 lands, (3) docs PR #5174 lands

Test plan

  • dotnet build clean
  • dapr run -f . against Dapr 1.18 RC sidecar with Redis
  • ComplianceAudit receives 2 propagated segments (PatientIntake + PrescribeMedication) under Lineage
  • DispenseMedicationWorkflow receives 1 propagated segment (PrescribeMedication only) under OwnHistory
  • PatientIntake segment correctly absent from DispenseMedicationWorkflow's history
  • Older sidecar (pre-1.18): GetPropagatedHistory() returns null, sample exits gracefully
  • CI passes on the .NET quickstart matrix

References

Signed-off-by: Alexander Trauzzi <acj@trauzzi.me>
@atrauzzi
atrauzzi requested review from a team as code owners June 9, 2026 17:22

@alicejgibbons alicejgibbons left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mostly long comments but a couple things

Comment thread tutorials/workflow/csharp/history-propagation/README.md Outdated
Comment thread tutorials/workflow/csharp/history-propagation/README.md Outdated
Comment thread tutorials/workflow/csharp/history-propagation/README.md Outdated
Comment thread tutorials/workflow/csharp/history-propagation/README.md Outdated
Comment thread tutorials/workflow/csharp/history-propagation/README.md Outdated
Comment thread tutorials/workflow/csharp/history-propagation/order-processor/Models.cs Outdated
Comment thread tutorials/workflow/csharp/history-propagation/order-processor/Program.cs Outdated
Comment thread tutorials/workflow/csharp/history-propagation/order-processor/Program.cs Outdated
Comment thread tutorials/workflow/csharp/history-propagation/order-processor/Program.cs Outdated
Signed-off-by: Alexander Trauzzi <acj@trauzzi.me>
@atrauzzi
atrauzzi requested a review from alicejgibbons June 10, 2026 15:37

@alicejgibbons alicejgibbons left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

few more changes

Comment thread tutorials/workflow/csharp/history-propagation/order-processor/Workflows.cs Outdated
Comment thread tutorials/workflow/csharp/history-propagation/dapr.yaml Outdated
Comment thread tutorials/workflow/csharp/history-propagation/README.md Outdated
atrauzzi added 2 commits June 10, 2026 10:48
Signed-off-by: Alexander Trauzzi <acj@trauzzi.me>
…block.

Signed-off-by: Alexander Trauzzi <acj@trauzzi.me>
@alicejgibbons
alicejgibbons merged commit 1d0d47d into dapr:release-1.18 Jun 10, 2026
7 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants