Skip to content

Commit

Permalink
Log telemetry for uses of deprecated features (#1387)
Browse files Browse the repository at this point in the history
Log telemetry for uses of deprecated features
  • Loading branch information
aholstrup1 authored Jan 14, 2025
1 parent ad79576 commit bdca9f4
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Actions/RunPipeline/RunPipeline.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ try {
if ($buildMode -eq 'Clean' -and $settings.ContainsKey('cleanModePreprocessorSymbols')) {
Write-Host "Adding Preprocessor symbols : $($settings.cleanModePreprocessorSymbols -join ',')"
$runAlPipelineParams["preprocessorsymbols"] += $settings.cleanModePreprocessorSymbols
Write-Warning -message "cleanModePreprocessorSymbols is deprecated. See https://aka.ms/ALGoDeprecations#cleanModePreprocessorSymbols for more information."
Trace-DeprecationWarning -Message "cleanModePreprocessorSymbols is deprecated" -DeprecationTag "cleanModePreprocessorSymbols"
}
# <--- REMOVE AFTER April 1st 2025

Expand Down
68 changes: 66 additions & 2 deletions Actions/TelemetryHelper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function AddTelemetryEvent()
[Parameter(Mandatory = $false)]
[System.Collections.Generic.Dictionary[[System.String], [System.String]]] $Data = @{},
[Parameter(Mandatory = $false)]
[ValidateSet("Information", "Error")]
[ValidateSet("Information", "Warning", "Error")]
[String] $Severity = 'Information'
)

Expand Down Expand Up @@ -138,6 +138,33 @@ function Trace-Information() {
AddTelemetryEvent -Message $Message -Severity 'Information' -Data $AdditionalData
}

<#
.SYNOPSIS
Logs a warning message to telemetry
.DESCRIPTION
Logs a warning message to telemetry
.PARAMETER Message
The message to log to telemetry
.PARAMETER AdditionalData
Additional data to log to telemetry
.EXAMPLE
Trace-Warning -Message "AL-Go warning: This is a warning message"
#>
function Trace-Warning() {
param(
[Parameter(Mandatory = $true)]
[String] $Message,
[Parameter(Mandatory = $false)]
[System.Collections.Generic.Dictionary[[System.String], [System.String]]] $AdditionalData = @{}
)

AddTelemetryEvent -Message $Message -Severity 'Warning' -Data $AdditionalData
}

<#
.SYNOPSIS
Logs an exception message to telemetry
Expand Down Expand Up @@ -212,4 +239,41 @@ function Add-TelemetryProperty() {
}
}

Export-ModuleMember -Function Trace-Information, Trace-Exception, Add-TelemetryProperty
<#
.SYNOPSIS
Writes a deprecation warning to telemetry and as a warning in the GitHub action
.DESCRIPTION
Writes a deprecation warning to telemetry and as a warning in the GitHub action
.PARAMETER Message
The message to log to telemetry
.PARAMETER DeprecationTag
The tag to use to link to the deprecation documentation
.PARAMETER AdditionalData
Additional data to log to telemetry
.EXAMPLE
Trace-DeprecationWarning -Message "This setting is deprecated. Use the new setting instead." -DeprecationTag 'SettingName'
#>
function Trace-DeprecationWarning {
param(
[Parameter(Mandatory = $true)]
[String] $Message,
[Parameter(Mandatory = $true)]
[String] $DeprecationTag,
[Parameter(Mandatory = $false)]
[System.Collections.Generic.Dictionary[[System.String], [System.String]]] $AdditionalData = @{}
)

# Show deprecation warning in GitHub
OutputWarning -message "$Message. See https://aka.ms/ALGoDeprecations#$($DeprecationTag) for more information."

# Log deprecation warning to telemetry
Add-TelemetryProperty -Hashtable $AdditionalData -Key 'DeprecationTag' -Value $DeprecationTag
Trace-Warning -Message "Deprecation Warning: $Message" -AdditionalData $AdditionalData
}

Export-ModuleMember -Function Trace-Information, Trace-Warning, Trace-Exception, Add-TelemetryProperty, Trace-DeprecationWarning

0 comments on commit bdca9f4

Please sign in to comment.