File tree Expand file tree Collapse file tree 2 files changed +51
-0
lines changed
sentry-cli/integration-test Expand file tree Collapse file tree 2 files changed +51
-0
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments