-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Sync eng/common directory with azure-sdk-tools for PR 14692 #48563
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
praveenkuttappan
merged 5 commits into
main
from
sync-eng/common-telemetry_hook_script-14692
Mar 25, 2026
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
70167a7
Add a script to ingest copilot tool/skill telemetry from hook
praveenkuttappan 6cfaa4a
Remove mcp tool telemetry
praveenkuttappan 5d6ae32
Apply suggestions from code review
praveenkuttappan 700ad1b
Apply suggestions from code review
praveenkuttappan f1dcae2
Apply suggestions from code review
praveenkuttappan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,191 @@ | ||
| $ErrorActionPreference = "SilentlyContinue" | ||
| . (Join-Path $PSScriptRoot '..' 'scripts' 'Helpers' 'AzSdkTool-Helpers.ps1') | ||
|
|
||
| $cliPath = Get-CommonInstallDirectory | ||
|
praveenkuttappan marked this conversation as resolved.
|
||
|
|
||
| # check for azsdk.exe on Windows or azsdk on Linux/Mac in the install directory | ||
| if ($IsWindows) | ||
| { | ||
| $cliPath = Join-Path $cliPath "azsdk.exe" | ||
| } | ||
| else | ||
| { | ||
| $cliPath = Join-Path $cliPath "azsdk" | ||
| } | ||
|
|
||
| if (-not (Test-Path $cliPath)) | ||
| { | ||
| Write-Success | ||
| } | ||
|
|
||
| # Skip telemetry if opted out | ||
| if ($env:AZSDKTOOLS_COLLECT_TELEMETRY -eq "false") | ||
| { | ||
| Write-Output '{"continue":true}' | ||
| exit 0 | ||
|
praveenkuttappan marked this conversation as resolved.
|
||
| } | ||
|
|
||
| $toolsToIgnore = @( "run_in_terminal", "apply_patch") | ||
|
|
||
| # Return success and exit | ||
| function Write-Success | ||
| { | ||
| Write-Output '{"continue":true}' | ||
| exit 0 | ||
| } | ||
|
|
||
| # Read entire stdin at once - hooks send one complete JSON per invocation | ||
| try | ||
| { | ||
| $rawInput = [Console]::In.ReadToEnd() | ||
| } catch | ||
| { | ||
| Write-Success | ||
| } | ||
| # Return success and exit if no input | ||
| if ([string]::IsNullOrWhiteSpace($rawInput)) | ||
| { | ||
| Write-Success | ||
| } | ||
|
|
||
| try | ||
| { | ||
| $inputData = $rawInput | ConvertFrom-Json | ||
| } catch { | ||
| Write-Success | ||
| } | ||
|
|
||
| $toolName = $inputData.toolName | ||
| if (-not $toolName) | ||
| { | ||
| $toolName = $inputData.tool_name | ||
| } | ||
|
|
||
| # Skip if no tool name found in either format | ||
| if (-not $toolName) | ||
| { | ||
| Write-Success | ||
| } | ||
|
|
||
| # Check if tool name is in ignore list | ||
| if ($toolsToIgnore -contains $toolName) | ||
| { | ||
| Write-Success | ||
| } | ||
|
|
||
| $sessionId = $inputData.sessionId | ||
| if (-not $sessionId) { | ||
| $sessionId = $inputData.session_id | ||
| } | ||
|
|
||
| # Get tool input arguments | ||
| $toolInput = $inputData.toolArgs | ||
| if (-not $toolInput) | ||
| { | ||
| $toolInput = $inputData.tool_input | ||
| } | ||
|
|
||
| $timestamp = (Get-Date).ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ssZ") | ||
|
|
||
| # Helper to extract path from tool input (handles 'path', 'filePath', 'file_path') | ||
| function Get-ToolInputPath | ||
| { | ||
| if ($toolInput.path) { return $toolInput.path } | ||
| if ($toolInput.filePath) { return $toolInput.filePath } | ||
| if ($toolInput.file_path) { return $toolInput.file_path } | ||
| return $null | ||
| } | ||
|
|
||
| # === STEP 2: Determine what to track === | ||
|
|
||
| $shouldTrack = $false | ||
| $eventType = $null | ||
| $skillName = $null | ||
| $clientType = $null | ||
|
|
||
| # check if hook is triggered from vscode or copilot-cli. Azure sdk tools hook is not considering claude at this point. | ||
| if ($inputData.PSObject.Properties['tool_use_id'] -and $inputData.tool_use_id -match ".*_vscode-.*") | ||
| { | ||
| $clientType = "vscode" | ||
| } | ||
| else | ||
| { | ||
| $clientType = "copilot-cli" | ||
| } | ||
|
|
||
| # Process skill invocations (looking for "azsdk" prefix in skill name) | ||
| if ($toolName -eq "skill") | ||
| { | ||
| $skillName = $toolInput.skill | ||
| if ($skillName -and $skillName.StartsWith("azsdk")) | ||
| { | ||
| $eventType = "skill_invocation" | ||
| $shouldTrack = $true | ||
| } | ||
| } | ||
|
|
||
| # Check for skill invocation (reading SKILL.md files) | ||
| if ($toolName -eq "view" -or $toolName -eq "read_file") | ||
| { | ||
| $pathToCheck = Get-ToolInputPath | ||
| if ($pathToCheck) | ||
| { | ||
| # replace backslashes and squeeze consecutive slashes | ||
| $pathNormalized = $pathToCheck -replace '\\', '/' -replace '/+', '/' | ||
| if ($pathNormalized -match "/skills/([^/]+)/SKILL\.md$") | ||
| { | ||
| $skillName = $Matches[1] | ||
| $eventType = "skill_invocation" | ||
| $shouldTrack = $true | ||
| } | ||
| } | ||
| } | ||
|
|
||
| # 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 | ||
| } | ||
|
|
||
|
praveenkuttappan marked this conversation as resolved.
|
||
| # Check for Azure SDK Tools MCP invocation | ||
| # Skip mcp tool telemetry since it's already tracked by MCP server | ||
| if ($toolName.StartsWith("mcp_azure-sdk") -or $toolName.StartsWith("azure-sdk-mcp")) | ||
| { | ||
| Write-Success | ||
| } | ||
|
|
||
| # === STEP 3: Publish event === | ||
|
|
||
| if ($shouldTrack) | ||
| { | ||
| # Build MCP command arguments | ||
| $cliArgs = @( | ||
| "ingest-telemetry", | ||
| "--timestamp", $timestamp, | ||
| "--client-type", $clientType | ||
| ) | ||
|
|
||
| if ($eventType) { $cliArgs += "--event-type"; $cliArgs += $eventType } | ||
| if ($sessionId) { $cliArgs += "--session-id"; $cliArgs += $sessionId } | ||
| if ($skillName) { $cliArgs += "--skill-name"; $cliArgs += $skillName } | ||
|
|
||
| # run azsdk cli to ingest telemetry (non-blocking) | ||
| try | ||
| { | ||
| Start-Process -FilePath $cliPath -ArgumentList $cliArgs -NoNewWindow | ||
| } | ||
| catch { | ||
| Write-Success | ||
| } | ||
| } | ||
| # Output success to stdout (required by hooks) | ||
| Write-Success | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.