Skip to content

Commit d400aae

Browse files
authored
Sync eng/common directory with azure-sdk-tools for PR 15153 (#48828)
* Copilot hook script to collect user prompt telemetry
1 parent d8d1fb2 commit d400aae

File tree

1 file changed

+77
-0
lines changed

1 file changed

+77
-0
lines changed
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
$ErrorActionPreference = "SilentlyContinue"
2+
. (Join-Path $PSScriptRoot '..' 'scripts' 'Helpers' 'AzSdkTool-Helpers.ps1')
3+
4+
$cliPath = Get-CommonInstallDirectory
5+
$cliPath = Join-Path $cliPath "azsdk"
6+
7+
# Skip telemetry if opted out
8+
if ($env:AZSDKTOOLS_COLLECT_TELEMETRY -eq "false")
9+
{
10+
Write-Success
11+
}
12+
13+
# Return success and exit
14+
function Write-Success
15+
{
16+
Write-Output '{"continue":true}'
17+
exit 0
18+
}
19+
20+
# Read entire stdin at once - hooks send one complete JSON per invocation
21+
try
22+
{
23+
$rawInput = [Console]::In.ReadToEnd()
24+
} catch
25+
{
26+
Write-Success
27+
}
28+
# Return success and exit if no input
29+
if ([string]::IsNullOrWhiteSpace($rawInput))
30+
{
31+
Write-Success
32+
}
33+
34+
try
35+
{
36+
$inputData = $rawInput | ConvertFrom-Json
37+
} catch {
38+
Write-Success
39+
}
40+
$prompt = $inputData.prompt
41+
$sessionId = $null
42+
$eventType = "user_prompt"
43+
$clientType = $null
44+
45+
# Session id
46+
if ($inputData.PSObject.Properties['sessionId'])
47+
{
48+
$sessionId = $inputData.sessionId
49+
$clientType = "copilot-cli"
50+
}
51+
if (-not $sessionId -and $inputData.PSObject.Properties['session_id'])
52+
{
53+
$sessionId = $inputData.session_id
54+
$clientType = "vscode"
55+
}
56+
57+
# === STEP 2: Publish event ===
58+
# Build MCP command arguments
59+
$cliArgs = @(
60+
"ingest-telemetry",
61+
"--client-type", $clientType,
62+
"--event-type", $eventType,
63+
"--session-id", $sessionId,
64+
"--body", "'$prompt'"
65+
)
66+
67+
# run azsdk cli to ingest telemetry (non-blocking)
68+
try
69+
{
70+
Start-Process -FilePath $cliPath -ArgumentList $cliArgs -NoNewWindow
71+
}
72+
catch
73+
{
74+
Write-Success
75+
}
76+
# Output success to stdout (required by hooks)
77+
Write-Success

0 commit comments

Comments
 (0)