@@ -19,6 +19,16 @@ function GetDurableClientFromModulePrivateData {
1919 }
2020}
2121
22+ function GetInvocationIdFromModulePrivateData {
23+ $PrivateData = $PSCmdlet.MyInvocation.MyCommand.Module.PrivateData
24+ if ($null -eq $PrivateData -or $null -eq $PrivateData [' InvocationId' ]) {
25+ return $null
26+ }
27+ else {
28+ return $PrivateData [' InvocationId' ]
29+ }
30+ }
31+
2232function Get-DurableStatus {
2333 [CmdletBinding ()]
2434 param (
@@ -121,6 +131,9 @@ function Start-DurableOrchestration {
121131 $InstanceId = (New-Guid ).Guid
122132 }
123133
134+ $invocationId = GetInvocationIdFromModulePrivateData
135+ $headers = Get-TraceHeaders - InvocationId $invocationId
136+
124137 $Uri =
125138 if ($DurableClient.rpcBaseUrl ) {
126139 # Fast local RPC path
@@ -132,12 +145,50 @@ function Start-DurableOrchestration {
132145 }
133146
134147 $Body = $InputObject | ConvertTo-Json - Compress
135-
136- $null = Invoke-RestMethod - Uri $Uri - Method ' POST' - ContentType ' application/json' - Body $Body
137-
148+
149+ $null = Invoke-RestMethod - Uri $Uri - Method ' POST' - ContentType ' application/json' - Body $Body - Headers $headers
150+
138151 return $instanceId
139152}
140153
154+ function Get-TraceHeaders {
155+ param (
156+ [string ] $InvocationId
157+ )
158+
159+ if ($null -eq $InvocationId -or $InvocationId -eq " " ) {
160+ return @ {} # Return an empty headers object
161+ }
162+
163+ # Check if Get-CurrentActivityForInvocation is available
164+ if (-not (Get-Command - Name Get-CurrentActivityForInvocation - ErrorAction SilentlyContinue)) {
165+ Write-Warning " Get-CurrentActivityForInvocation is not available. Skipping call."
166+ return @ {} # Return an empty headers object
167+ }
168+
169+ $activityResponse = Get-CurrentActivityForInvocation - InvocationId $invocationId
170+ $activity = $activityResponse.activity
171+
172+ $traceId = $activity.TraceId
173+ $spanId = $activity.SpanId
174+ $traceFlags = $activity.TraceFlags
175+ $traceState = $activity.TraceStateString
176+
177+ $flag = " 00"
178+ if ($null -ne $traceFlags -and $traceFlags -eq " Recorded" ) {
179+ $flag = " 01"
180+ }
181+
182+ $traceparent = " 00-$traceId -$spanId -$flag "
183+
184+ $headers = @ {
185+ " traceparent" = $traceparent
186+ " tracestate" = $traceState
187+ }
188+
189+ return $headers
190+ }
191+
141192function Stop-DurableOrchestration {
142193 [CmdletBinding ()]
143194 param (
0 commit comments