Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 19 additions & 3 deletions sentry-api-client/Public/Get-SentryLogsByAttribute.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@ function Get-SentryLogsByAttribute {
.PARAMETER StatsPeriod
Relative time period (e.g., '24h', '7d'). Default is '24h'.

.PARAMETER Fields
Additional fields to include in the response. These are merged with default fields
(id, trace, severity, timestamp, message) and the filter attribute.

.EXAMPLE
Get-SentryLogsByAttribute -AttributeName 'test_id' -AttributeValue 'integration-test-001'

.EXAMPLE
Get-SentryLogsByAttribute -AttributeName 'user_id' -AttributeValue '12345' -StatsPeriod '7d'

.EXAMPLE
Get-SentryLogsByAttribute -AttributeName 'test_id' -AttributeValue 'test-001' -Fields @('sentry.environment', 'custom_attr')
#>
[CmdletBinding()]
param(
Expand All @@ -38,13 +45,16 @@ function Get-SentryLogsByAttribute {
[int]$Limit = 100,

[Parameter(Mandatory = $false)]
[string]$StatsPeriod = '24h'
[string]$StatsPeriod = '24h',

[Parameter(Mandatory = $false)]
[string[]]$Fields
)

$Query = "$AttributeName`:$AttributeValue"

# Include default fields plus the attribute we're filtering by
$Fields = @(
$DefaultFields = @(
'id',
'trace',
'severity',
Expand All @@ -53,5 +63,11 @@ function Get-SentryLogsByAttribute {
$AttributeName
)

return Get-SentryLogs -Query $Query -Limit $Limit -StatsPeriod $StatsPeriod -Fields $Fields
if ($Fields) {
$AllFields = @($DefaultFields + $Fields) | Select-Object -Unique
} else {
$AllFields = $DefaultFields
}

return Get-SentryLogs -Query $Query -Limit $Limit -StatsPeriod $StatsPeriod -Fields $AllFields
}
7 changes: 5 additions & 2 deletions utils/Integration.TestUtils.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,10 @@ function Get-SentryTestLog {
[int]$TimeoutSeconds = 120,

[Parameter()]
[string]$StatsPeriod = '24h'
[string]$StatsPeriod = '24h',

[Parameter()]
[string[]]$Fields
)

Write-Host "Fetching Sentry logs by attribute: $AttributeName=$AttributeValue" -ForegroundColor Yellow
Expand All @@ -276,7 +279,7 @@ function Get-SentryTestLog {
Write-Progress -Activity $progressActivity -Status "Elapsed: $elapsedSeconds/$TimeoutSeconds seconds" -PercentComplete $percentComplete

try {
$response = Get-SentryLogsByAttribute -AttributeName $AttributeName -AttributeValue $AttributeValue -StatsPeriod $StatsPeriod
$response = Get-SentryLogsByAttribute -AttributeName $AttributeName -AttributeValue $AttributeValue -StatsPeriod $StatsPeriod -Fields $Fields
if ($response.data -and $response.data.Count -ge $ExpectedCount) {
$logs = $response.data
}
Expand Down