Skip to content

Commit 933a699

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 ad15657 commit 933a699

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))
@@ -198,13 +194,14 @@ function Invoke-GHRestMethod
198194
return
199195
}
200196

197+
$NoStatus = Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus
198+
201199
try
202200
{
203201
Write-Log -Message $Description -Level Verbose
204202
Write-Log -Message "Accessing [$Method] $url [Timeout = $(Get-GitHubConfiguration -Name WebRequestTimeoutSec))]" -Level Verbose
205203

206204
$result = $null
207-
$NoStatus = Resolve-ParameterWithDefaultConfigurationValue -Name NoStatus -ConfigValueName DefaultNoStatus
208205
if ($NoStatus)
209206
{
210207
$params = @{}
@@ -293,7 +290,8 @@ function Invoke-GHRestMethod
293290
Write-Log -Message "Unable to retrieve the raw HTTP Web Response:" -Exception $_ -Level Warning
294291
}
295292

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

@@ -326,7 +324,7 @@ function Invoke-GHRestMethod
326324
if (-not [String]::IsNullOrEmpty($TelemetryEventName))
327325
{
328326
$telemetryMetrics = @{ 'Duration' = $stopwatch.Elapsed.TotalSeconds }
329-
Set-TelemetryEvent -EventName $TelemetryEventName -Properties $localTelemetryProperties -Metrics $telemetryMetrics
327+
Set-TelemetryEvent -EventName $TelemetryEventName -Properties $localTelemetryProperties -Metrics $telemetryMetrics -NoStatus:$NoStatus
330328
}
331329

332330
$finalResult = $result.Content
@@ -454,14 +452,14 @@ function Invoke-GHRestMethod
454452
{
455453
# Will be thrown if $ex.Message isn't JSON content
456454
Write-Log -Exception $_ -Level Error
457-
Set-TelemetryException -Exception $ex -ErrorBucket $errorBucket -Properties $localTelemetryProperties
455+
Set-TelemetryException -Exception $ex -ErrorBucket $errorBucket -Properties $localTelemetryProperties -NoStatus:$NoStatus
458456
throw
459457
}
460458
}
461459
else
462460
{
463461
Write-Log -Exception $_ -Level Error
464-
Set-TelemetryException -Exception $_.Exception -ErrorBucket $errorBucket -Properties $localTelemetryProperties
462+
Set-TelemetryException -Exception $_.Exception -ErrorBucket $errorBucket -Properties $localTelemetryProperties -NoStatus:$NoStatus
465463
throw
466464
}
467465

@@ -524,7 +522,7 @@ function Invoke-GHRestMethod
524522

525523
$newLineOutput = ($output -join [Environment]::NewLine)
526524
Write-Log -Message $newLineOutput -Level Error
527-
Set-TelemetryException -Exception $ex -ErrorBucket $errorBucket -Properties $localTelemetryProperties
525+
Set-TelemetryException -Exception $ex -ErrorBucket $errorBucket -Properties $localTelemetryProperties -NoStatus:$NoStatus
528526
throw $newLineOutput
529527
}
530528
}

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)