|
1 | 1 | # Copyright (c) Microsoft Corporation. All rights reserved.
|
2 | 2 | # Licensed under the MIT License.
|
3 | 3 |
|
4 |
| -# Singleton. Don't directly access this though....always get it |
5 |
| -# by calling Get-BaseTelemetryEvent to ensure that it has been initialized and that you're always |
6 |
| -# getting a fresh copy. |
7 |
| -$script:GHBaseTelemetryEvent = $null |
| 4 | +# Maintain a consistent ID for this PowerShell session that we'll use as our telemetry's session ID. |
| 5 | +$script:TelemetrySessionId = [System.GUID]::NewGuid().ToString() |
| 6 | + |
| 7 | +# Tracks if we've seen the telemetry reminder this session. |
| 8 | +$script:SeenTelemetryReminder = $false |
8 | 9 |
|
9 | 10 | function Get-PiiSafeString
|
10 | 11 | {
|
@@ -76,40 +77,37 @@ function Get-BaseTelemetryEvent
|
76 | 77 | [CmdletBinding()]
|
77 | 78 | param()
|
78 | 79 |
|
79 |
| - if ($null -eq $script:GHBaseTelemetryEvent) |
| 80 | + if ((-not $script:SeenTelemetryReminder) -and |
| 81 | + (-not (Get-GitHubConfiguration -Name SuppressTelemetryReminder))) |
80 | 82 | {
|
81 |
| - if (-not (Get-GitHubConfiguration -Name SuppressTelemetryReminder)) |
82 |
| - { |
83 |
| - Write-Log -Message 'Telemetry is currently enabled. It can be disabled by calling "Set-GitHubConfiguration -DisableTelemetry". Refer to USAGE.md#telemetry for more information. Stop seeing this message in the future by calling "Set-GitHubConfiguration -SuppressTelemetryReminder".' |
84 |
| - } |
| 83 | + Write-Log -Message 'Telemetry is currently enabled. It can be disabled by calling "Set-GitHubConfiguration -DisableTelemetry". Refer to USAGE.md#telemetry for more information. Stop seeing this message in the future by calling "Set-GitHubConfiguration -SuppressTelemetryReminder".' |
| 84 | + $script:SeenTelemetryReminder = $true |
| 85 | + } |
85 | 86 |
|
86 |
| - $username = Get-PiiSafeString -PlainText $env:USERNAME |
87 |
| - |
88 |
| - $script:GHBaseTelemetryEvent = [PSCustomObject] @{ |
89 |
| - 'name' = 'Microsoft.ApplicationInsights.66d83c523070489b886b09860e05e78a.Event' |
90 |
| - 'time' = (Get-Date).ToUniversalTime().ToString("O") |
91 |
| - 'iKey' = (Get-GitHubConfiguration -Name ApplicationInsightsKey) |
92 |
| - 'tags' = [PSCustomObject] @{ |
93 |
| - 'ai.user.id' = $username |
94 |
| - 'ai.session.id' = [System.GUID]::NewGuid().ToString() |
95 |
| - 'ai.application.ver' = $MyInvocation.MyCommand.Module.Version.ToString() |
96 |
| - 'ai.internal.sdkVersion' = '2.0.1.33027' # The version this schema was based off of. |
97 |
| - } |
| 87 | + $username = Get-PiiSafeString -PlainText $env:USERNAME |
| 88 | + |
| 89 | + return [PSCustomObject] @{ |
| 90 | + 'name' = 'Microsoft.ApplicationInsights.66d83c523070489b886b09860e05e78a.Event' |
| 91 | + 'time' = (Get-Date).ToUniversalTime().ToString("O") |
| 92 | + 'iKey' = (Get-GitHubConfiguration -Name ApplicationInsightsKey) |
| 93 | + 'tags' = [PSCustomObject] @{ |
| 94 | + 'ai.user.id' = $username |
| 95 | + 'ai.session.id' = $script:TelemetrySessionId |
| 96 | + 'ai.application.ver' = $MyInvocation.MyCommand.Module.Version.ToString() |
| 97 | + 'ai.internal.sdkVersion' = '2.0.1.33027' # The version this schema was based off of. |
| 98 | + } |
98 | 99 |
|
99 |
| - 'data' = [PSCustomObject] @{ |
100 |
| - 'baseType' = 'EventData' |
101 |
| - 'baseData' = [PSCustomObject] @{ |
102 |
| - 'ver' = 2 |
103 |
| - 'properties' = [PSCustomObject] @{ |
104 |
| - 'DayOfWeek' = (Get-Date).DayOfWeek.ToString() |
105 |
| - 'Username' = $username |
106 |
| - } |
| 100 | + 'data' = [PSCustomObject] @{ |
| 101 | + 'baseType' = 'EventData' |
| 102 | + 'baseData' = [PSCustomObject] @{ |
| 103 | + 'ver' = 2 |
| 104 | + 'properties' = [PSCustomObject] @{ |
| 105 | + 'DayOfWeek' = (Get-Date).DayOfWeek.ToString() |
| 106 | + 'Username' = $username |
107 | 107 | }
|
108 | 108 | }
|
109 | 109 | }
|
110 | 110 | }
|
111 |
| - |
112 |
| - return $script:GHBaseTelemetryEvent.PSObject.Copy() # Get a new instance, not a reference |
113 | 111 | }
|
114 | 112 |
|
115 | 113 | function Invoke-SendTelemetryEvent
|
|
0 commit comments