Skip to content

Commit 0ae4426

Browse files
committed
Removing binary dependencies for telemetry
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.
1 parent 3440909 commit 0ae4426

6 files changed

+369
-724
lines changed

GitHubConfiguration.ps1

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,6 @@ function Set-GitHubConfiguration
7676
Change the Application Insights instance that telemetry will be reported to (if telemetry
7777
hasn't been disabled via DisableTelemetry).
7878
79-
.PARAMETER AssemblyPath
80-
The location that any dependent assemblies that this module depends on can be located.
81-
If the assemblies can't be found at this location, nor in a temporary cache or in
82-
the module's directory, the assemblies will be downloaded and temporarily cached.
83-
8479
.PARAMETER DefaultNoStatus
8580
Control if the -NoStatus switch should be passed-in by default to all methods.
8681
@@ -178,8 +173,6 @@ function Set-GitHubConfiguration
178173

179174
[string] $ApplicationInsightsKey,
180175

181-
[string] $AssemblyPath,
182-
183176
[switch] $DefaultNoStatus,
184177

185178
[string] $DefaultOwnerName,
@@ -273,7 +266,6 @@ function Get-GitHubConfiguration
273266
[ValidateSet(
274267
'ApiHostName',
275268
'ApplicationInsightsKey',
276-
'AssemblyPath',
277269
'DefaultNoStatus',
278270
'DefaultOwnerName',
279271
'DefaultRepositoryName',
@@ -610,7 +602,6 @@ function Import-GitHubConfiguration
610602
$config = [PSCustomObject]@{
611603
'apiHostName' = 'github.com'
612604
'applicationInsightsKey' = '66d83c52-3070-489b-886b-09860e05e78a'
613-
'assemblyPath' = [String]::Empty
614605
'disableLogging' = ([String]::IsNullOrEmpty($logPath))
615606
'disablePiiProtection' = $false
616607
'disableSmarterObjects' = $false

GitHubCore.ps1

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ function Invoke-GHRestMethod
9898
9999
.NOTES
100100
This wraps Invoke-WebRequest as opposed to Invoke-RestMethod because we want access to the headers
101-
that are returned in the response (specifically 'MS-ClientRequestId') for logging purposes, and
102-
Invoke-RestMethod drops those headers.
101+
that are returned in the response, and Invoke-RestMethod drops those headers.
103102
#>
104103
[CmdletBinding(SupportsShouldProcess)]
105104
param(
@@ -142,10 +141,7 @@ function Invoke-GHRestMethod
142141

143142
# Telemetry-related
144143
$stopwatch = New-Object -TypeName System.Diagnostics.Stopwatch
145-
$localTelemetryProperties = @{
146-
'UriFragment' = $UriFragment
147-
'WaitForCompletion' = ($WaitForCompletion -eq $true)
148-
}
144+
$localTelemetryProperties = @{}
149145
$TelemetryProperties.Keys | ForEach-Object { $localTelemetryProperties[$_] = $TelemetryProperties[$_] }
150146
$errorBucket = $TelemetryExceptionBucket
151147
if ([String]::IsNullOrEmpty($errorBucket))
@@ -191,12 +187,13 @@ function Invoke-GHRestMethod
191187
$headers.Add("Content-Type", "application/json; charset=UTF-8")
192188
}
193189

190+
$NoStatus = Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus
191+
194192
try
195193
{
196194
Write-Log -Message $Description -Level Verbose
197195
Write-Log -Message "Accessing [$Method] $url [Timeout = $(Get-GitHubConfiguration -Name WebRequestTimeoutSec))]" -Level Verbose
198196

199-
$NoStatus = Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus
200197
if ($NoStatus)
201198
{
202199
if ($PSCmdlet.ShouldProcess($url, "Invoke-WebRequest"))
@@ -290,7 +287,8 @@ function Invoke-GHRestMethod
290287
Write-Log -Message "Unable to retrieve the raw HTTP Web Response:" -Exception $_ -Level Warning
291288
}
292289

293-
throw (ConvertTo-Json -InputObject $ex -Depth 20)
290+
$jsonConversionDepth = 20 # Seems like it should be more than sufficient
291+
throw (ConvertTo-Json -InputObject $ex -Depth $jsonConversionDepth)
294292
}
295293
}
296294

@@ -331,7 +329,7 @@ function Invoke-GHRestMethod
331329
if (-not [String]::IsNullOrEmpty($TelemetryEventName))
332330
{
333331
$telemetryMetrics = @{ 'Duration' = $stopwatch.Elapsed.TotalSeconds }
334-
Set-TelemetryEvent -EventName $TelemetryEventName -Properties $localTelemetryProperties -Metrics $telemetryMetrics
332+
Set-TelemetryEvent -EventName $TelemetryEventName -Properties $localTelemetryProperties -Metrics $telemetryMetrics -NoStatus:$NoStatus
335333
}
336334

337335
$finalResult = $result.Content
@@ -459,14 +457,14 @@ function Invoke-GHRestMethod
459457
{
460458
# Will be thrown if $ex.Message isn't JSON content
461459
Write-Log -Exception $_ -Level Error
462-
Set-TelemetryException -Exception $ex -ErrorBucket $errorBucket -Properties $localTelemetryProperties
460+
Set-TelemetryException -Exception $ex -ErrorBucket $errorBucket -Properties $localTelemetryProperties -NoStatus:$NoStatus
463461
throw
464462
}
465463
}
466464
else
467465
{
468466
Write-Log -Exception $_ -Level Error
469-
Set-TelemetryException -Exception $_.Exception -ErrorBucket $errorBucket -Properties $localTelemetryProperties
467+
Set-TelemetryException -Exception $_.Exception -ErrorBucket $errorBucket -Properties $localTelemetryProperties -NoStatus:$NoStatus
470468
throw
471469
}
472470

@@ -529,7 +527,7 @@ function Invoke-GHRestMethod
529527

530528
$newLineOutput = ($output -join [Environment]::NewLine)
531529
Write-Log -Message $newLineOutput -Level Error
532-
Set-TelemetryException -Exception $ex -ErrorBucket $errorBucket -Properties $localTelemetryProperties
530+
Set-TelemetryException -Exception $ex -ErrorBucket $errorBucket -Properties $localTelemetryProperties -NoStatus:$NoStatus
533531
throw $newLineOutput
534532
}
535533
}

GitHubIssues.ps1

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -322,16 +322,21 @@ function Get-GitHubIssue
322322
'NoStatus' = (Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus)
323323
}
324324

325-
$result = Invoke-GHRestMethodMultipleResult @params
326-
327-
if ($IgnorePullRequests)
325+
try
328326
{
329-
return ($result | Where-Object { $null -eq (Get-Member -InputObject $_ -Name pull_request) })
330-
}
331-
else
332-
{
333-
return $result
327+
$result = Invoke-GHRestMethodMultipleResult @params
328+
329+
if ($IgnorePullRequests)
330+
{
331+
return ($result | Where-Object { $null -eq (Get-Member -InputObject $_ -Name pull_request) })
332+
}
333+
else
334+
{
335+
return $result
336+
}
337+
334338
}
339+
finally {}
335340
}
336341

337342
function Get-GitHubIssueTimeline

0 commit comments

Comments
 (0)