-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: capture errors & messages (#14)
* error capture * refactor * error capture & tests * update dependency list * fixup deps * fixup deps * fixup deps * fixup deps * fixup * missing deps * test compat with windows powershell * try to use .net framework with pwsh 6 * disable pwsh versions that don't work * cleanup
- Loading branch information
Showing
15 changed files
with
207 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
version = 4.5.1 | ||
assemblyVersion = 4.0.3.0 | ||
licenseFile = LICENSE.TXT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
version = 5.0.0 | ||
licenseFile = LICENSE.TXT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
version = 4.5.4 | ||
assemblyVersion = 4.0.1.1 | ||
licenseFile = LICENSE.TXT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
version = 4.5.0 | ||
assemblyVersion = 4.1.4.0 | ||
licenseFile = LICENSE.TXT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
version = 5.0.0 | ||
licenseFile = LICENSE.TXT |
3 changes: 3 additions & 0 deletions
3
dependencies/System.Runtime.CompilerServices.Unsafe.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
version = 4.5.3 | ||
assemblyVersion = 4.0.4.1 | ||
licenseFile = LICENSE.TXT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
version = 6.0.0 | ||
assemblyVersion = 6.0.0.0 | ||
licenseFile = LICENSE.TXT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
version = 4.5.0 | ||
assemblyVersion = 4.0.3.0 | ||
licenseFile = LICENSE.TXT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
function Out-Sentry | ||
{ | ||
param( | ||
[Parameter(ValueFromPipeline = $true)] | ||
[System.Management.Automation.ErrorRecord] | ||
$ErrorRecord, | ||
|
||
[Parameter(ValueFromPipeline = $true)] | ||
[System.Exception] | ||
$Exception, | ||
|
||
[Parameter(ValueFromPipeline = $true)] | ||
[string] | ||
$Message | ||
) | ||
|
||
begin {} | ||
process | ||
{ | ||
if ($ErrorRecord -ne $null) | ||
{ | ||
# TODO details | ||
[Sentry.SentrySdk]::CaptureException($ErrorRecord.Exception) | ||
} | ||
if ($Exception -ne $null -and ($Message -eq $null -or "$Exception" -eq "$Message")) | ||
{ | ||
[Sentry.SentrySdk]::CaptureException($Exception) | ||
} | ||
if ($Message -ne $null -and $Message -ne $ErrorRecord -and $Message -ne $Exception) | ||
{ | ||
[Sentry.SentrySdk]::CaptureMessage($Message) | ||
} | ||
} | ||
end {} | ||
} | ||
|
||
function Invoke-WithSentry | ||
{ | ||
param( | ||
[scriptblock] | ||
$ScriptBlock | ||
) | ||
|
||
try | ||
{ | ||
& $ScriptBlock | ||
} | ||
catch | ||
{ | ||
$_ | Out-Sentry | ||
throw | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
BeforeAll { | ||
$events = [System.Collections.Generic.List[Sentry.SentryEvent]]::new(); | ||
$options = [Sentry.SentryOptions]::new() | ||
$options.Debug = $true | ||
$options.Dsn = 'https://[email protected]/1' | ||
$options.AutoSessionTracking = $false | ||
$options.SetBeforeSend([System.Func[Sentry.SentryEvent, Sentry.SentryEvent]] { | ||
param([Sentry.SentryEvent]$e) | ||
$events.Add($e) | ||
return $null # Prevent sending | ||
}); | ||
[Sentry.SentrySdk]::init($options) | ||
} | ||
|
||
AfterAll { | ||
[Sentry.SentrySdk]::Close() | ||
} | ||
|
||
|
||
Describe 'Out-Sentry' { | ||
AfterEach { | ||
$events.Clear() | ||
} | ||
|
||
It 'captures message' { | ||
'message' | Out-Sentry | ||
$events.Count | Should -Be 1 | ||
[Sentry.SentryEvent]$event = $events.ToArray()[0] | ||
$event.Exception | Should -Be $null | ||
$event.Message.Message | Should -Be 'message' | ||
} | ||
|
||
It 'captures error record' { | ||
try | ||
{ | ||
throw 'error' | ||
} | ||
catch | ||
{ | ||
$_ | Out-Sentry | ||
} | ||
$events.Count | Should -Be 1 | ||
[Sentry.SentryEvent]$event = $events.ToArray()[0] | ||
$event.Exception | Should -BeOfType [System.Management.Automation.RuntimeException] | ||
$event.Exception.Message | Should -Be 'error' | ||
} | ||
|
||
It 'captures exception' { | ||
try | ||
{ | ||
throw 'exception' | ||
} | ||
catch | ||
{ | ||
$_.Exception | Out-Sentry | ||
} | ||
$events.Count | Should -Be 1 | ||
[Sentry.SentryEvent]$event = $events.ToArray()[0] | ||
$event.Exception | Should -BeOfType [System.Management.Automation.RuntimeException] | ||
$event.Exception.Message | Should -Be 'exception' | ||
} | ||
} | ||
|
||
Describe 'Invoke-WithSentry' { | ||
AfterEach { | ||
$events.Clear() | ||
} | ||
|
||
It 'captures error record' { | ||
try | ||
{ | ||
Invoke-WithSentry { throw 'inside invoke' } | ||
} | ||
catch {} | ||
$events.Count | Should -Be 1 | ||
[Sentry.SentryEvent]$event = $events.ToArray()[0] | ||
$event.Exception | Should -BeOfType [System.Management.Automation.RuntimeException] | ||
$event.Exception.Message | Should -Be 'inside invoke' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class RecordingTransport:Sentry.Extensibility.ITransport | ||
{ | ||
$envelopes = [System.Collections.Concurrent.ConcurrentQueue[Sentry.Protocol.Envelopes.Envelope]]::new(); | ||
|
||
[System.Threading.Tasks.Task]SendEnvelopeAsync([Sentry.Protocol.Envelopes.Envelope] $envelope, [System.Threading.CancellationToken] $cancellationToken) | ||
{ | ||
$this.envelopes.Enqueue($envelope); | ||
return [System.Threading.Tasks.Task]::CompletedTask; | ||
} | ||
} | ||
|
||
class TestLogger:Sentry.Infrastructure.DiagnosticLogger | ||
{ | ||
TestLogger([Sentry.SentryLevel]$level) : base($level) {} | ||
|
||
$entries = [System.Collections.Concurrent.ConcurrentQueue[string]]::new(); | ||
|
||
[void]LogMessage([string] $message) { $this.entries.Enqueue($message); } | ||
} |