@@ -22,6 +22,16 @@ function GetDurableClientFromModulePrivateData {
22
22
}
23
23
}
24
24
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
+
25
35
function Get-DurableStatus {
26
36
[CmdletBinding ()]
27
37
param (
@@ -103,6 +113,9 @@ function Start-DurableOrchestration {
103
113
$InstanceId = (New-Guid ).Guid
104
114
}
105
115
116
+ $invocationId = GetInvocationIdFromModulePrivateData
117
+ $headers = Get-TraceHeaders - InvocationId $invocationId
118
+
106
119
$Uri =
107
120
if ($DurableClient.rpcBaseUrl ) {
108
121
# Fast local RPC path
@@ -115,11 +128,49 @@ function Start-DurableOrchestration {
115
128
116
129
$Body = $InputObject | ConvertTo-Json - Compress - Depth 100
117
130
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
119
132
120
133
return $instanceId
121
134
}
122
135
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
+
123
174
function Stop-DurableOrchestration {
124
175
[CmdletBinding ()]
125
176
param (
0 commit comments