@@ -22,6 +22,16 @@ function GetDurableClientFromModulePrivateData {
2222 }
2323}
2424
25+ function GetInvocationIdFromModulePrivateData {
26+ $PrivateData = $PSCmdlet.MyInvocation.MyCommand.Module.PrivateData
27+ if ($null -eq $PrivateData -or $null -eq $PrivateData [' InvocationId' ]) {
28+ return $null
29+ }
30+ else {
31+ return $PrivateData [' InvocationId' ]
32+ }
33+ }
34+
2535function Get-DurableStatus {
2636 [CmdletBinding ()]
2737 param (
@@ -103,6 +113,9 @@ function Start-DurableOrchestration {
103113 $InstanceId = (New-Guid ).Guid
104114 }
105115
116+ $invocationId = GetInvocationIdFromModulePrivateData
117+ $headers = Get-TraceHeaders - InvocationId $invocationId
118+
106119 $Uri =
107120 if ($DurableClient.rpcBaseUrl ) {
108121 # Fast local RPC path
@@ -115,11 +128,49 @@ function Start-DurableOrchestration {
115128
116129 $Body = $InputObject | ConvertTo-Json - Compress - Depth 100
117130
118- $null = Invoke-RestMethod - Uri $Uri - Method ' POST' - ContentType ' application/json' - Body $Body
131+ $null = Invoke-RestMethod - Uri $Uri - Method ' POST' - ContentType ' application/json' - Body $Body - Headers $headers
119132
120133 return $instanceId
121134}
122135
136+ function Get-TraceHeaders {
137+ param (
138+ [string ] $InvocationId
139+ )
140+
141+ if ($null -eq $InvocationId -or $InvocationId -eq " " ) {
142+ return @ {} # Return an empty headers object
143+ }
144+
145+ # Check if Get-CurrentActivityForInvocation is available
146+ if (-not (Get-Command - Name Get-CurrentActivityForInvocation - ErrorAction SilentlyContinue)) {
147+ Write-Warning " Get-CurrentActivityForInvocation is not available. Skipping call."
148+ return @ {} # Return an empty headers object
149+ }
150+
151+ $activityResponse = Get-CurrentActivityForInvocation - InvocationId $invocationId
152+ $activity = $activityResponse.activity
153+
154+ $traceId = $activity.TraceId
155+ $spanId = $activity.SpanId
156+ $traceFlags = $activity.TraceFlags
157+ $traceState = $activity.TraceStateString
158+
159+ $flag = " 00"
160+ if ($null -ne $traceFlags -and $traceFlags -eq " Recorded" ) {
161+ $flag = " 01"
162+ }
163+
164+ $traceparent = " 00-$traceId -$spanId -$flag "
165+
166+ $headers = @ {
167+ " traceparent" = $traceparent
168+ " tracestate" = $traceState
169+ }
170+
171+ return $headers
172+ }
173+
123174function Stop-DurableOrchestration {
124175 [CmdletBinding ()]
125176 param (
0 commit comments