Skip to content

Commit 8099364

Browse files
authored
feat: user feedback support (#34)
* feat: user feedback support * fix windows-pwsh tests
1 parent 9922f6b commit 8099364

File tree

4 files changed

+66
-4
lines changed

4 files changed

+66
-4
lines changed

modules/Sentry/public/Out-Sentry.ps1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
function Out-Sentry
55
{
6+
[OutputType([Sentry.SentryId])]
67
[CmdletBinding(DefaultParameterSetName = 'ErrorRecord')]
78
param(
89
[Parameter(ValueFromPipeline = $true, ParameterSetName = 'ErrorRecord')]
@@ -32,7 +33,7 @@ function Out-Sentry
3233
}
3334

3435
$options = Get-CurrentOptions
35-
[Sentry.SentryEvent]$event_
36+
[Sentry.SentryEvent]$event_ = $null
3637
$processor = [StackTraceProcessor]::new()
3738

3839
if ($ErrorRecord -ne $null)
@@ -106,5 +107,4 @@ function Out-Sentry
106107
$scope | ForEach-Object $EditScope
107108
})
108109
}
109-
end {}
110110
}

tests/init.tests.ps1

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,17 @@ Describe 'SentrySdk' {
9191
}
9292

9393
It 'Out-Sentry does not crash when Sentry is not enabled' {
94-
'message' | Out-Sentry -Debug
94+
$eventId = 'message' | Out-Sentry -Debug
95+
$eventId | Should -Be $null
9596
}
9697

9798
It 'Out-Sentry does not capture when Sentry is not enabled' {
9899
$events = [System.Collections.Generic.List[Sentry.SentryEvent]]::new();
99100
$transport = [RecordingTransport]::new()
100101
StartSentryForEventTests ([ref] $events) ([ref] $transport)
101102
Stop-Sentry
102-
'message' | Out-Sentry -Debug
103+
$eventId = 'message' | Out-Sentry -Debug
104+
$eventId | Should -Be $null
103105
$events.Count | Should -Be 0
104106
}
105107
}

tests/userfeedback.tests.ps1

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
BeforeAll {
2+
. "$PSScriptRoot/utils.ps1"
3+
}
4+
5+
Describe 'UserFeedback' {
6+
BeforeEach {
7+
$events = [System.Collections.Generic.List[Sentry.SentryEvent]]::new();
8+
$transport = [RecordingTransport]::new()
9+
StartSentryForEventTests ([ref] $events) ([ref] $transport)
10+
}
11+
12+
AfterEach {
13+
$events.Clear()
14+
$transport.Clear()
15+
Stop-Sentry
16+
}
17+
18+
It 'Out-Sentry returns an event ID for messages' {
19+
$eventId = 'msg' | Out-Sentry
20+
$eventId | Should -BeOfType [Sentry.SentryId]
21+
$eventId.ToString().Length | Should -Be 32
22+
}
23+
24+
It 'Out-Sentry returns an event ID for an error record' {
25+
try
26+
{
27+
throw 'error'
28+
}
29+
catch
30+
{
31+
$eventId = $_ | Out-Sentry
32+
}
33+
$eventId | Should -BeOfType [Sentry.SentryId]
34+
$eventId.ToString().Length | Should -Be 32
35+
}
36+
37+
It 'Feedback gets captured' {
38+
$eventId = 'msg' | Out-Sentry
39+
40+
$eventId | Should -BeOfType [Sentry.SentryId]
41+
[Sentry.SentrySdk]::Flush()
42+
$transport.Envelopes.Count | Should -Be 1
43+
44+
[Sentry.SentrySdk]::CaptureUserFeedback($eventId, 'email@example.com', 'comments', 'name')
45+
[Sentry.SentrySdk]::Flush()
46+
$transport.Envelopes.Count | Should -Be 2
47+
$envelopeItem = $transport.Envelopes.ToArray()[1].Items[0]
48+
$envelopeItem.Header['type'] | Should -Be 'user_report'
49+
$envelopeItem.Payload.Source.EventId | Should -Be $eventId
50+
$envelopeItem.Payload.Source.Name | Should -Be 'name'
51+
$envelopeItem.Payload.Source.Email | Should -Be 'email@example.com'
52+
$envelopeItem.Payload.Source.Comments | Should -Be 'comments'
53+
}
54+
55+
}

tests/utils.ps1

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ class RecordingTransport:Sentry.Extensibility.ITransport
77
$this.envelopes.Enqueue($envelope);
88
return [System.Threading.Tasks.Task]::CompletedTask;
99
}
10+
11+
[void] Clear()
12+
{
13+
$this.envelopes = [System.Collections.Concurrent.ConcurrentQueue[Sentry.Protocol.Envelopes.Envelope]]::new()
14+
}
1015
}
1116

1217
class TestLogger:Sentry.Infrastructure.DiagnosticLogger

0 commit comments

Comments
 (0)