Skip to content

Commit 0a8bd0b

Browse files
authored
Merge pull request #110 from microsoft/jessecol/use-provider-guid
Use provider guid for telemetry
2 parents e117209 + 0326da1 commit 0a8bd0b

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

.pipelines/Unstub.ps1

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
1+
param(
2+
[string]$TelemetryProviderGuid = ""
3+
)
4+
15
# This script unstubs the telemetry at build time and replaces the stubbed file with a reference internal nuget package
26

7+
$ErrorActionPreference = "Stop"
8+
9+
if ($TelemetryProviderGuid -eq "") {
10+
Write-Error "TelemetryProviderGuid is required"
11+
exit 1
12+
}
13+
314
#
415
# Unstub managed telemetry
516
#
@@ -29,3 +40,39 @@ $itemGroupNode = $xml.CreateElement("ItemGroup")
2940
$itemGroupNode.AppendChild($packageReferenceNode)
3041
$xml.DocumentElement.AppendChild($itemGroupNode)
3142
$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"

.pipelines/release.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ extends:
6666
displayName: Replace Stubbed Files
6767
inputs:
6868
filePath: '.pipelines/Unstub.ps1'
69+
arguments: '-TelemetryProviderGuid "$(TelemetryProviderGuid)"'
6970
- template: ./.pipelines/templates/build.yaml@self
7071
parameters:
7172
stable: 'true'

0 commit comments

Comments
 (0)