From c8d126df8144b208d6fd11681e6aceb7e49949ee Mon Sep 17 00:00:00 2001 From: bitsandfoxes Date: Sun, 25 Oct 2026 07:17:33 +0100 Subject: [PATCH] Add Filter parameter to Get-SentryTestEvent --- utils/Integration.TestUtils.psm1 | 42 +++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/utils/Integration.TestUtils.psm1 b/utils/Integration.TestUtils.psm1 index 3a3c7fe..171149d 100644 --- a/utils/Integration.TestUtils.psm1 +++ b/utils/Integration.TestUtils.psm1 @@ -121,6 +121,22 @@ function Get-EventIds { return , $eventIds # Comma operator ensures array is returned } +# Lifts each entry (exception, breadcrumbs, ...) to a top-level property named after its type. +function ConvertTo-SentryTestEvent { + param($SentryEvent) + + if (-not $SentryEvent) { + return $null + } + + $entries = $SentryEvent.entries + $converted = $SentryEvent | Select-Object -ExcludeProperty 'entries' + foreach ($entry in $entries) { + $converted | Add-Member -MemberType NoteProperty -Name $entry.type -Value $entry.data -Force + } + return $converted +} + function Get-SentryTestEvent { [CmdletBinding()] param( @@ -133,10 +149,18 @@ function Get-SentryTestEvent { [Parameter()] [string]$TagValue, + # Applied to tag lookup results before the single-event check, e.g. to skip unrelated events carrying the same tag. + [Parameter()] + [scriptblock]$Filter, + [Parameter()] [int]$TimeoutSeconds = 300 ) + if ($EventId -and $Filter) { + throw 'Filter is only supported with TagName and TagValue' + } + if ($EventId) { Write-Host "Fetching Sentry event by ID: $EventId" -ForegroundColor Yellow $progressActivity = "Waiting for Sentry event $EventId" @@ -163,10 +187,13 @@ function Get-SentryTestEvent { try { if ($EventId) { # Find by event ID - $sentryEvent = Get-SentryEvent -EventId $EventId + $sentryEvent = ConvertTo-SentryTestEvent (Get-SentryEvent -EventId $EventId) } else { # Find by tag - $result = Find-SentryEventByTag -TagName $TagName -TagValue $TagValue + $result = @((Find-SentryEventByTag -TagName $TagName -TagValue $TagValue) | ForEach-Object { ConvertTo-SentryTestEvent $_ }) + if ($Filter) { + $result = @($result | Where-Object -FilterScript $Filter) + } $result.Count | Should -Be 1 $sentryEvent = $result[0] } @@ -182,11 +209,6 @@ function Get-SentryTestEvent { if ($sentryEvent) { Write-Host "Event $($sentryEvent.id) fetched from Sentry" -ForegroundColor Green - $entries = $sentryEvent.entries - $sentryEvent = $sentryEvent | Select-Object -ExcludeProperty 'entries' - foreach ($entry in $entries) { - $sentryEvent | Add-Member -MemberType NoteProperty -Name $entry.type -Value $entry.data -Force - } $sentryEvent | ConvertTo-Json -Depth 10 | Out-File -FilePath (Get-OutputFilePath "event-$($sentryEvent.id).json") return $sentryEvent } @@ -436,11 +458,7 @@ function Get-SentryTestTransaction { if ($sentryEvent) { Write-Host "Transaction $($sentryEvent.id) fetched from Sentry" -ForegroundColor Green - $entries = $sentryEvent.entries - $sentryEvent = $sentryEvent | Select-Object -ExcludeProperty 'entries' - foreach ($entry in $entries) { - $sentryEvent | Add-Member -MemberType NoteProperty -Name $entry.type -Value $entry.data -Force - } + $sentryEvent = ConvertTo-SentryTestEvent $sentryEvent $sentryEvent | ConvertTo-Json -Depth 10 | Out-File -FilePath (Get-OutputFilePath "transaction-$($sentryEvent.id).json") return $sentryEvent }