Skip to content

Commit 95e67f6

Browse files
committed
feat: add InvokeSentryResult::Events() to extract events from envelopes
1 parent 17cc15e commit 95e67f6

File tree

2 files changed

+51
-0
lines changed

2 files changed

+51
-0
lines changed

sentry-cli/integration-test/action.psm1

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,36 @@ class InvokeSentryResult
3939
return $envelopes
4040
}
4141

42+
# Events are extracted from envelopes, each event body as single item.
43+
# Note: Unlike Envelopes(), this method discards potential duplicates based on event_id.
44+
[string[]]Events()
45+
{
46+
$ids = @()
47+
$events = @()
48+
foreach ($envelope in $this.Envelopes())
49+
{
50+
$lines = @($envelope -split "\\n")
51+
try
52+
{
53+
$header = $lines[0].Trim() | ConvertFrom-Json
54+
if ($header.event_id -and $ids -notcontains $header.event_id)
55+
{
56+
$body = $lines | Select-Object -Skip 1 | Where-Object {
57+
try { ($_ | ConvertFrom-Json).event_id -eq $header.event_id }
58+
catch { $false }
59+
} | Select-Object -First 1
60+
if ($body)
61+
{
62+
$ids += $header.event_id
63+
$events += $body
64+
}
65+
}
66+
}
67+
catch { }
68+
}
69+
return $events
70+
}
71+
4272
[bool]HasErrors()
4373
{
4474
return $this.ServerStdErr.Length -gt 0

sentry-cli/integration-test/tests/action.Tests.ps1

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,4 +97,25 @@ helloworld
9797
$result.Envelopes().Length | Should -Be 1
9898
$result.Envelopes()[0].Length | Should -Be 357
9999
}
100+
101+
It "discards duplicate events" {
102+
$result = Invoke-SentryServer {
103+
param([string]$url)
104+
Invoke-WebRequest -Uri "$url/api/0/envelope" -Method Post -Body @'
105+
{"event_id":"9ec79c33ec9942ab8353589fcb2e04dc","dsn":"https://e12d836b15bb49d7bbf99e64295d995b:@sentry.io/42","sent_at":"2025-11-20T03:53:38.929Z"}
106+
{"type":"event","length":47,"content_type":"application/json"}
107+
{"event_id":"9ec79c33ec9942ab8353589fcb2e04dc"}
108+
'@
109+
Invoke-WebRequest -Uri "$url/api/0/envelope" -Method Post -Body @'
110+
{"event_id":"9ec79c33ec9942ab8353589fcb2e04dc","dsn":"https://e12d836b15bb49d7bbf99e64295d995b:@sentry.io/42","sent_at":"2025-11-20T03:53:41.505Z"}
111+
{"type":"event","length":47,"content_type":"application/json"}
112+
{"event_id":"9ec79c33ec9942ab8353589fcb2e04dc"}
113+
'@
114+
}
115+
116+
Should -ActualValue $result.HasErrors() -BeFalse
117+
$result.Envelopes().Length | Should -Be 2
118+
$result.Events().Length | Should -Be 1
119+
$result.Events()[0].Length | Should -Be 47
120+
}
100121
}

0 commit comments

Comments
 (0)