Skip to content

Commit

Permalink
Removing binary dependencies for telemetry
Browse files Browse the repository at this point in the history
This reverse engineers the REST API for Application Insights so that
we no longer need to download / depend on the 3 .dll files that were
necessary to use the Application Insights .NET SDK.

As a result, this also removes the `AssemblyPath` configuration property
since there are no longer any assemblies that this module needs.
  • Loading branch information
HowardWolosky committed May 31, 2020
1 parent ed9b114 commit efa42e2
Show file tree
Hide file tree
Showing 7 changed files with 369 additions and 727 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
Tests/Config/Settings.ps1
Microsoft.ApplicationInsights.dll
Microsoft.Diagnostics.Tracing.EventSource.dll
Microsoft.Threading.Tasks.dll
9 changes: 0 additions & 9 deletions GitHubConfiguration.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ function Set-GitHubConfiguration
Change the Application Insights instance that telemetry will be reported to (if telemetry
hasn't been disabled via DisableTelemetry).
.PARAMETER AssemblyPath
The location that any dependent assemblies that this module depends on can be located.
If the assemblies can't be found at this location, nor in a temporary cache or in
the module's directory, the assemblies will be downloaded and temporarily cached.
.PARAMETER DefaultNoStatus
Control if the -NoStatus switch should be passed-in by default to all methods.
Expand Down Expand Up @@ -182,8 +177,6 @@ function Set-GitHubConfiguration

[string] $ApplicationInsightsKey,

[string] $AssemblyPath,

[switch] $DefaultNoStatus,

[string] $DefaultOwnerName,
Expand Down Expand Up @@ -279,7 +272,6 @@ function Get-GitHubConfiguration
[ValidateSet(
'ApiHostName',
'ApplicationInsightsKey',
'AssemblyPath',
'DefaultNoStatus',
'DefaultOwnerName',
'DefaultRepositoryName',
Expand Down Expand Up @@ -617,7 +609,6 @@ function Import-GitHubConfiguration
$config = [PSCustomObject]@{
'apiHostName' = 'github.com'
'applicationInsightsKey' = '66d83c52-3070-489b-886b-09860e05e78a'
'assemblyPath' = [String]::Empty
'disableLogging' = ([String]::IsNullOrEmpty($logPath))
'disablePiiProtection' = $false
'disableSmarterObjects' = $false
Expand Down
22 changes: 10 additions & 12 deletions GitHubCore.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,7 @@ function Invoke-GHRestMethod
.NOTES
This wraps Invoke-WebRequest as opposed to Invoke-RestMethod because we want access to the headers
that are returned in the response (specifically 'MS-ClientRequestId') for logging purposes, and
Invoke-RestMethod drops those headers.
that are returned in the response, and Invoke-RestMethod drops those headers.
#>
[CmdletBinding(SupportsShouldProcess)]
param(
Expand Down Expand Up @@ -144,10 +143,7 @@ function Invoke-GHRestMethod

# Telemetry-related
$stopwatch = New-Object -TypeName System.Diagnostics.Stopwatch
$localTelemetryProperties = @{
'UriFragment' = $UriFragment
'WaitForCompletion' = ($WaitForCompletion -eq $true)
}
$localTelemetryProperties = @{}
$TelemetryProperties.Keys | ForEach-Object { $localTelemetryProperties[$_] = $TelemetryProperties[$_] }
$errorBucket = $TelemetryExceptionBucket
if ([String]::IsNullOrEmpty($errorBucket))
Expand Down Expand Up @@ -193,12 +189,13 @@ function Invoke-GHRestMethod
$headers.Add("Content-Type", "application/json; charset=UTF-8")
}

$NoStatus = Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus

try
{
Write-Log -Message $Description -Level Verbose
Write-Log -Message "Accessing [$Method] $url [Timeout = $(Get-GitHubConfiguration -Name WebRequestTimeoutSec))]" -Level Verbose

$NoStatus = Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus
if ($NoStatus)
{
if ($PSCmdlet.ShouldProcess($url, "Invoke-WebRequest"))
Expand Down Expand Up @@ -292,7 +289,8 @@ function Invoke-GHRestMethod
Write-Log -Message "Unable to retrieve the raw HTTP Web Response:" -Exception $_ -Level Warning
}

throw (ConvertTo-Json -InputObject $ex -Depth 20)
$jsonConversionDepth = 20 # Seems like it should be more than sufficient
throw (ConvertTo-Json -InputObject $ex -Depth $jsonConversionDepth)
}
}

Expand Down Expand Up @@ -333,7 +331,7 @@ function Invoke-GHRestMethod
if (-not [String]::IsNullOrEmpty($TelemetryEventName))
{
$telemetryMetrics = @{ 'Duration' = $stopwatch.Elapsed.TotalSeconds }
Set-TelemetryEvent -EventName $TelemetryEventName -Properties $localTelemetryProperties -Metrics $telemetryMetrics
Set-TelemetryEvent -EventName $TelemetryEventName -Properties $localTelemetryProperties -Metrics $telemetryMetrics -NoStatus:$NoStatus
}

$finalResult = $result.Content
Expand Down Expand Up @@ -461,14 +459,14 @@ function Invoke-GHRestMethod
{
# Will be thrown if $ex.Message isn't JSON content
Write-Log -Exception $_ -Level Error
Set-TelemetryException -Exception $ex -ErrorBucket $errorBucket -Properties $localTelemetryProperties
Set-TelemetryException -Exception $ex -ErrorBucket $errorBucket -Properties $localTelemetryProperties -NoStatus:$NoStatus
throw
}
}
else
{
Write-Log -Exception $_ -Level Error
Set-TelemetryException -Exception $_.Exception -ErrorBucket $errorBucket -Properties $localTelemetryProperties
Set-TelemetryException -Exception $_.Exception -ErrorBucket $errorBucket -Properties $localTelemetryProperties -NoStatus:$NoStatus
throw
}

Expand Down Expand Up @@ -531,7 +529,7 @@ function Invoke-GHRestMethod

$newLineOutput = ($output -join [Environment]::NewLine)
Write-Log -Message $newLineOutput -Level Error
Set-TelemetryException -Exception $ex -ErrorBucket $errorBucket -Properties $localTelemetryProperties
Set-TelemetryException -Exception $ex -ErrorBucket $errorBucket -Properties $localTelemetryProperties -NoStatus:$NoStatus
throw $newLineOutput
}
}
Expand Down
21 changes: 13 additions & 8 deletions GitHubIssues.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -322,16 +322,21 @@ function Get-GitHubIssue
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
}

$result = Invoke-GHRestMethodMultipleResult @params

if ($IgnorePullRequests)
try
{
return ($result | Where-Object { $null -eq (Get-Member -InputObject $_ -Name pull_request) })
}
else
{
return $result
$result = Invoke-GHRestMethodMultipleResult @params

if ($IgnorePullRequests)
{
return ($result | Where-Object { $null -eq (Get-Member -InputObject $_ -Name pull_request) })
}
else
{
return $result
}

}
finally {}
}

function Get-GitHubIssueTimeline
Expand Down
Loading

0 comments on commit efa42e2

Please sign in to comment.