|
| 1 | +param( |
| 2 | + [string]$TelemetryProviderGuid = "" |
| 3 | +) |
| 4 | + |
1 | 5 | # This script unstubs the telemetry at build time and replaces the stubbed file with a reference internal nuget package |
2 | 6 |
|
| 7 | +$ErrorActionPreference = "Stop" |
| 8 | + |
| 9 | +if ($TelemetryProviderGuid -eq "") { |
| 10 | + Write-Error "TelemetryProviderGuid is required" |
| 11 | + exit 1 |
| 12 | +} |
| 13 | + |
3 | 14 | # |
4 | 15 | # Unstub managed telemetry |
5 | 16 | # |
@@ -29,3 +40,39 @@ $itemGroupNode = $xml.CreateElement("ItemGroup") |
29 | 40 | $itemGroupNode.AppendChild($packageReferenceNode) |
30 | 41 | $xml.DocumentElement.AppendChild($itemGroupNode) |
31 | 42 | $xml.Save($projFile) |
| 43 | + |
| 44 | +$telemetryFile = Resolve-Path "$($PSScriptRoot)\..\src\winapp-CLI\WinApp.Cli\Telemetry\Telemetry.cs" |
| 45 | +$oldLine = "EventSource TelemetryEventSourceInstance = new " |
| 46 | +$newLine = "private static readonly EventSource TelemetryEventSourceInstance = new EventSource(ProviderName, EventSourceSettings.EtwManifestEventFormat, new[] {""ETW_GROUP"", ""{$TelemetryProviderGuid}"" });" |
| 47 | + |
| 48 | +Write-Host "Modifying telemetry file: $telemetryFile" |
| 49 | +Write-Host "Looking for line containing: $oldLine" |
| 50 | +Write-Host "Replacing with: $newLine" |
| 51 | + |
| 52 | +if (-not (Test-Path $telemetryFile)) { |
| 53 | + Write-Error "Telemetry file not found: $telemetryFile" |
| 54 | + exit 1 |
| 55 | +} |
| 56 | + |
| 57 | +$telemetryContent = Get-Content $telemetryFile -Encoding UTF8 |
| 58 | +$lineFound = $false |
| 59 | +$newContent = @() |
| 60 | + |
| 61 | +foreach ($line in $telemetryContent) { |
| 62 | + if ($line -like "*$oldLine*") { |
| 63 | + $lineFound = $true |
| 64 | + $newContent += $newLine |
| 65 | + Write-Host "Found and replaced line" |
| 66 | + } else { |
| 67 | + $newContent += $line |
| 68 | + } |
| 69 | +} |
| 70 | + |
| 71 | +if (-not $lineFound) { |
| 72 | + Write-Error "Could not find line containing: $oldLine" |
| 73 | + Write-Error "Please verify the telemetry file format has not changed" |
| 74 | + exit 1 |
| 75 | +} |
| 76 | + |
| 77 | +$newContent | Set-Content $telemetryFile -Encoding UTF8 |
| 78 | +Write-Host "Successfully updated telemetry file" |
0 commit comments