Skip to content
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

Fix telemetry failure for long-running sessions #228

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion StoreBroker/StoreBroker.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
CompanyName = 'Microsoft Corporation'
Copyright = 'Copyright (C) Microsoft Corporation. All rights reserved.'

ModuleVersion = '1.21.0'
ModuleVersion = '1.21.1'
Description = 'Provides command-line access to the Windows Store Submission REST API.'

RootModule = 'StoreIngestionApi'
Expand Down
60 changes: 29 additions & 31 deletions StoreBroker/Telemetry.ps1
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# Copyright (C) Microsoft Corporation. All rights reserved.

# Singleton. Don't directly access this though....always get it
# by calling Get-BaseTelemetryEvent to ensure that it has been initialized and that you're always
# getting a fresh copy.
$script:SBBaseTelemetryEvent = $null
# Maintain a consistent ID for this PowerShell session that we'll use as our telemetry's session ID.
$script:TelemetrySessionId = [System.GUID]::NewGuid().ToString()

# Tracks if we've seen the telemetry reminder this session.
$script:SeenTelemetryReminder = $false

Add-Type -TypeDefinition @"
public enum StoreBrokerTelemetryProperty
Expand Down Expand Up @@ -187,40 +188,37 @@ function Get-BaseTelemetryEvent
[CmdletBinding()]
param()

if ($null -eq $script:SBBaseTelemetryEvent)
if ((-not $script:SeenTelemetryReminder) -and
(-not $global:SBSuppressTelemetryReminder))
{
if (-not $global:SBSuppressTelemetryReminder)
{
Write-Log -Message "Telemetry is currently enabled. It can be disabled by setting ""`$global:SBDisableTelemetry = `$true"". Refer to USAGE.md#telemetry for more information. Stop seeing this message in the future by setting `"`$global:SBSuppressTelemetryReminder=`$true`""
}
Write-Log -Message "Telemetry is currently enabled. It can be disabled by setting ""`$global:SBDisableTelemetry = `$true"". Refer to USAGE.md#telemetry for more information. Stop seeing this message in the future by setting `"`$global:SBSuppressTelemetryReminder=`$true`""
$script:SeenTelemetryReminder = $true
}

$username = Get-PiiSafeString -PlainText $env:USERNAME

$script:SBBaseTelemetryEvent = [PSCustomObject] @{
'name' = 'Microsoft.ApplicationInsights.66d83c523070489b886b09860e05e78a.Event'
'time' = (Get-Date).ToUniversalTime().ToString("O")
'iKey' = $global:SBApplicationInsightsKey
'tags' = [PSCustomObject] @{
'ai.user.id' = $username
'ai.session.id' = [System.GUID]::NewGuid().ToString()
'ai.application.ver' = $MyInvocation.MyCommand.Module.Version.ToString()
'ai.internal.sdkVersion' = '2.0.1.33027' # The version this schema was based off of.
}
$username = Get-PiiSafeString -PlainText $env:USERNAME

return [PSCustomObject] @{
'name' = 'Microsoft.ApplicationInsights.66d83c523070489b886b09860e05e78a.Event'
'time' = (Get-Date).ToUniversalTime().ToString("O")
'iKey' = $global:SBApplicationInsightsKey
'tags' = [PSCustomObject] @{
'ai.user.id' = $username
'ai.session.id' = $script:TelemetrySessionId
'ai.application.ver' = $MyInvocation.MyCommand.Module.Version.ToString()
'ai.internal.sdkVersion' = '2.0.1.33027' # The version this schema was based off of.
}

'data' = [PSCustomObject] @{
'baseType' = 'EventData'
'baseData' = [PSCustomObject] @{
'ver' = 2
'properties' = [PSCustomObject] @{
'DayOfWeek' = (Get-Date).DayOfWeek.ToString()
'Username' = $username
}
'data' = [PSCustomObject] @{
'baseType' = 'EventData'
'baseData' = [PSCustomObject] @{
'ver' = 2
'properties' = [PSCustomObject] @{
'DayOfWeek' = (Get-Date).DayOfWeek.ToString()
'Username' = $username
}
}
}
}

return $script:SBBaseTelemetryEvent.PSObject.Copy() # Get a new instance, not a reference
}

function Invoke-SendTelemetryEvent
Expand Down