@@ -19,6 +19,16 @@ function GetDurableClientFromModulePrivateData {
19
19
}
20
20
}
21
21
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
+
22
32
function Get-DurableStatus {
23
33
[CmdletBinding ()]
24
34
param (
@@ -121,6 +131,9 @@ function Start-DurableOrchestration {
121
131
$InstanceId = (New-Guid ).Guid
122
132
}
123
133
134
+ $invocationId = GetInvocationIdFromModulePrivateData
135
+ $headers = Get-TraceHeaders - InvocationId $invocationId
136
+
124
137
$Uri =
125
138
if ($DurableClient.rpcBaseUrl ) {
126
139
# Fast local RPC path
@@ -132,12 +145,50 @@ function Start-DurableOrchestration {
132
145
}
133
146
134
147
$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
+
138
151
return $instanceId
139
152
}
140
153
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
+
141
192
function Stop-DurableOrchestration {
142
193
[CmdletBinding ()]
143
194
param (
0 commit comments