Sync eng/common directory with azure-sdk-tools for PR 14692#45889
Sync eng/common directory with azure-sdk-tools for PR 14692#45889
Conversation
There was a problem hiding this comment.
Pull request overview
This PR syncs eng/common with updates from azure-sdk-tools PR 14692 by introducing a PowerShell hook script intended to ingest telemetry for select azsdk tool/skill invocations without blocking normal hook execution.
Changes:
- Added
azsdk_tool_telemetry.ps1hook to parse tool invocation JSON from stdin and decide whether to emit telemetry. - Added logic to ignore specific tools, respect an opt-out environment variable, and invoke
azsdk ingest-telemetryasynchronously.
|
|
||
| # Helper to extract path from tool input (handles 'path', 'filePath', 'file_path') | ||
| function Get-ToolInputPath | ||
| { |
There was a problem hiding this comment.
Because this script dot-sources AzSdkTool-Helpers.ps1 (which enables Set-StrictMode -Version 4), accessing $toolInput.path / $toolInput.filePath / $toolInput.file_path will throw if $toolInput is $null (or not an object). Consider guarding with if ($toolInput -and ...) or switching to a PSObject.Properties[...] lookup so missing tool args don’t break the hook.
| { | |
| { | |
| if (-not $toolInput) { return $null } |
| # Process skill invocations (looking for "azsdk" prefix in skill name) | ||
| if ($toolName -eq "skill") | ||
| { | ||
| $skillName = $toolInput.skill |
There was a problem hiding this comment.
$skillName = $toolInput.skill will throw under Set-StrictMode -Version 4 if the incoming JSON doesn’t include toolArgs/tool_input (i.e., $toolInput is $null). To keep the hook resilient, add a $toolInput null check before accessing .skill (or use a safe property accessor).
| $skillName = $toolInput.skill | |
| $skillName = Get-Property -Object $toolInput -PropertyName 'skill' |
| # Find property from tool input or output | ||
| function Get-Property | ||
| { | ||
| param ( | ||
| [object]$Object, | ||
| [string]$PropertyName | ||
| ) | ||
|
|
||
| if ($Object -and $Object.PSObject.Properties[$PropertyName]) | ||
| { | ||
| return $Object.PSObject.Properties[$PropertyName].Value | ||
| } | ||
| return $null | ||
| } | ||
|
|
There was a problem hiding this comment.
Get-Property is defined but never used. Either remove it to reduce dead code, or use it (e.g., in Get-ToolInputPath / skill parsing) to safely read optional properties under StrictMode.
| # Find property from tool input or output | |
| function Get-Property | |
| { | |
| param ( | |
| [object]$Object, | |
| [string]$PropertyName | |
| ) | |
| if ($Object -and $Object.PSObject.Properties[$PropertyName]) | |
| { | |
| return $Object.PSObject.Properties[$PropertyName].Value | |
| } | |
| return $null | |
| } |
| # Skip telemetry if opted out | ||
| if ($env:AZSDKTOOLS_COLLECT_TELEMETRY -eq "false") | ||
| { | ||
| Write-Output '{"continue":true}' | ||
| exit 0 | ||
| } |
There was a problem hiding this comment.
The opt-out block duplicates the exact JSON output/exit logic that Write-Success provides, and Write-Success is also invoked before its definition earlier in the file. Consider defining Write-Success at the top and using it for all early-exit paths to keep the hook logic consistent and easier to maintain.
Co-authored-by: Praveen Kuttappan <55455725+praveenkuttappan@users.noreply.github.com>
Co-authored-by: Praveen Kuttappan <55455725+praveenkuttappan@users.noreply.github.com>
Co-authored-by: Praveen Kuttappan <55455725+praveenkuttappan@users.noreply.github.com>
cb1a6e7 to
013c044
Compare
Sync eng/common directory with azure-sdk-tools for PR Azure/azure-sdk-tools#14692 See eng/common workflow