From d6f6ccefda7251002e0413b9fd6508fffce6c02b Mon Sep 17 00:00:00 2001 From: Andy Staples Date: Wed, 2 Jul 2025 12:04:33 -0600 Subject: [PATCH 1/2] DT change PoC --- ...osoft.Azure.Functions.PowerShellWorker.psm1 | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/Modules/Microsoft.Azure.Functions.PowerShellWorker/Microsoft.Azure.Functions.PowerShellWorker.psm1 b/src/Modules/Microsoft.Azure.Functions.PowerShellWorker/Microsoft.Azure.Functions.PowerShellWorker.psm1 index 7c1c5396..8a48603e 100644 --- a/src/Modules/Microsoft.Azure.Functions.PowerShellWorker/Microsoft.Azure.Functions.PowerShellWorker.psm1 +++ b/src/Modules/Microsoft.Azure.Functions.PowerShellWorker/Microsoft.Azure.Functions.PowerShellWorker.psm1 @@ -132,9 +132,25 @@ function Start-DurableOrchestration { } $Body = $InputObject | ConvertTo-Json -Compress + + try { + $activity = Start-FunctionsOpenTelemetrySpan + $traceID = $activity.activity.TraceId + # Do whatever you need to do with the trace information using the activity here + } catch { + # Do something better - correctly handle errors when the OTel SDK is not available + # Output errors from this command in a reasonable way + # Detect if calling Stop-FunctionsOpenTelemetrySpan is necessary and change that logic too + } $null = Invoke-RestMethod -Uri $Uri -Method 'POST' -ContentType 'application/json' -Body $Body - + + try { + Stop-FunctionsOpenTelemetrySpan -Activity $activity + } catch { + # Do something better here + } + return $instanceId } From 46daa71177efaa10add1ebc3282f77beed20880d Mon Sep 17 00:00:00 2001 From: Varshitha Bachu Date: Thu, 3 Jul 2025 17:54:47 -0700 Subject: [PATCH 2/2] updated how traceparent is created --- ...soft.Azure.Functions.PowerShellWorker.psm1 | 25 ++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/Modules/Microsoft.Azure.Functions.PowerShellWorker/Microsoft.Azure.Functions.PowerShellWorker.psm1 b/src/Modules/Microsoft.Azure.Functions.PowerShellWorker/Microsoft.Azure.Functions.PowerShellWorker.psm1 index 8a48603e..8cd09af7 100644 --- a/src/Modules/Microsoft.Azure.Functions.PowerShellWorker/Microsoft.Azure.Functions.PowerShellWorker.psm1 +++ b/src/Modules/Microsoft.Azure.Functions.PowerShellWorker/Microsoft.Azure.Functions.PowerShellWorker.psm1 @@ -133,9 +133,28 @@ function Start-DurableOrchestration { $Body = $InputObject | ConvertTo-Json -Compress + $invokeParams = @{ + Uri = $Uri + Method = 'POST' + ContentType = 'application/json' + Body = $Body + } + try { - $activity = Start-FunctionsOpenTelemetrySpan - $traceID = $activity.activity.TraceId + $activity = Start-FunctionsOpenTelemetrySpan -ActivityName "Starting orchestration" + + $traceId = $activity.activity.TraceId + $spanId = $activity.activity.SpanId + + # Construct the traceparent header + $traceParent = "00-$traceId-$spanId-01" + + $traceState = $activity.activity.TraceState + + $invokeParams.Headers = @{ + 'traceparent' = $traceParent + 'tracestate' = $traceState + } # Do whatever you need to do with the trace information using the activity here } catch { # Do something better - correctly handle errors when the OTel SDK is not available @@ -143,7 +162,7 @@ function Start-DurableOrchestration { # Detect if calling Stop-FunctionsOpenTelemetrySpan is necessary and change that logic too } - $null = Invoke-RestMethod -Uri $Uri -Method 'POST' -ContentType 'application/json' -Body $Body + $null = Invoke-RestMethod @invokeParams try { Stop-FunctionsOpenTelemetrySpan -Activity $activity