Skip to content

Commit efa42e2

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 ed9b114 commit efa42e2

7 files changed

+369
-727
lines changed

.gitignore

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1 @@
11
Tests/Config/Settings.ps1
2-
Microsoft.ApplicationInsights.dll
3-
Microsoft.Diagnostics.Tracing.EventSource.dll
4-
Microsoft.Threading.Tasks.dll

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
@@ -182,8 +177,6 @@ function Set-GitHubConfiguration
182177

183178
[string] $ApplicationInsightsKey,
184179

185-
[string] $AssemblyPath,
186-
187180
[switch] $DefaultNoStatus,
188181

189182
[string] $DefaultOwnerName,
@@ -279,7 +272,6 @@ function Get-GitHubConfiguration
279272
[ValidateSet(
280273
'ApiHostName',
281274
'ApplicationInsightsKey',
282-
'AssemblyPath',
283275
'DefaultNoStatus',
284276
'DefaultOwnerName',
285277
'DefaultRepositoryName',
@@ -617,7 +609,6 @@ function Import-GitHubConfiguration
617609
$config = [PSCustomObject]@{
618610
'apiHostName' = 'github.com'
619611
'applicationInsightsKey' = '66d83c52-3070-489b-886b-09860e05e78a'
620-
'assemblyPath' = [String]::Empty
621612
'disableLogging' = ([String]::IsNullOrEmpty($logPath))
622613
'disablePiiProtection' = $false
623614
'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(
@@ -144,10 +143,7 @@ function Invoke-GHRestMethod
144143

145144
# Telemetry-related
146145
$stopwatch = New-Object -TypeName System.Diagnostics.Stopwatch
147-
$localTelemetryProperties = @{
148-
'UriFragment' = $UriFragment
149-
'WaitForCompletion' = ($WaitForCompletion -eq $true)
150-
}
146+
$localTelemetryProperties = @{}
151147
$TelemetryProperties.Keys | ForEach-Object { $localTelemetryProperties[$_] = $TelemetryProperties[$_] }
152148
$errorBucket = $TelemetryExceptionBucket
153149
if ([String]::IsNullOrEmpty($errorBucket))
@@ -193,12 +189,13 @@ function Invoke-GHRestMethod
193189
$headers.Add("Content-Type", "application/json; charset=UTF-8")
194190
}
195191

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

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

295-
throw (ConvertTo-Json -InputObject $ex -Depth 20)
292+
$jsonConversionDepth = 20 # Seems like it should be more than sufficient
293+
throw (ConvertTo-Json -InputObject $ex -Depth $jsonConversionDepth)
296294
}
297295
}
298296

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

339337
$finalResult = $result.Content
@@ -461,14 +459,14 @@ function Invoke-GHRestMethod
461459
{
462460
# Will be thrown if $ex.Message isn't JSON content
463461
Write-Log -Exception $_ -Level Error
464-
Set-TelemetryException -Exception $ex -ErrorBucket $errorBucket -Properties $localTelemetryProperties
462+
Set-TelemetryException -Exception $ex -ErrorBucket $errorBucket -Properties $localTelemetryProperties -NoStatus:$NoStatus
465463
throw
466464
}
467465
}
468466
else
469467
{
470468
Write-Log -Exception $_ -Level Error
471-
Set-TelemetryException -Exception $_.Exception -ErrorBucket $errorBucket -Properties $localTelemetryProperties
469+
Set-TelemetryException -Exception $_.Exception -ErrorBucket $errorBucket -Properties $localTelemetryProperties -NoStatus:$NoStatus
472470
throw
473471
}
474472

@@ -531,7 +529,7 @@ function Invoke-GHRestMethod
531529

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

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)