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
128 changes: 128 additions & 0 deletions integration-test/Integration.Android.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,16 @@ Describe 'Sentry Unreal Android Integration Tests (<Platform>)' -ForEach $TestTa
$global:AndroidLogResult = Invoke-DeviceApp -ExecutablePath $script:ActivityName -Arguments $logIntentArgs

Write-Host "Log test exit code: $($global:AndroidLogResult.ExitCode)" -ForegroundColor Cyan

# ==========================================
# RUN 4: Metric test - captures custom metric
# ==========================================

Write-Host "Running metric-capture test on $Platform..." -ForegroundColor Yellow
$metricIntentArgs = "-e cmdline '-metric-capture -ini:Engine:[/Script/Sentry.SentrySettings]:EnableMetrics=True -ini:Engine:[/Script/Sentry.SentrySettings]:BeforeMetricHandler=/Script/SentryPlayground.CppBeforeMetricHandler'"
$global:AndroidMetricResult = Invoke-DeviceApp -ExecutablePath $script:ActivityName -Arguments $metricIntentArgs

Write-Host "Metric test exit code: $($global:AndroidMetricResult.ExitCode)" -ForegroundColor Cyan
}

AfterAll {
Expand Down Expand Up @@ -403,6 +413,124 @@ Describe 'Sentry Unreal Android Integration Tests (<Platform>)' -ForEach $TestTa
# Note: Global log attributes (SetAttribute/RemoveAttribute on subsystem) are not supported
# on Android (sentry-java) - the implementation is a no-op. These are tested in desktop tests only.
}

Context "Metrics Capture Tests" {
BeforeAll {
$script:MetricResult = $global:AndroidMetricResult
$script:CapturedCounterMetrics = @()
$script:CapturedDistributionMetrics = @()
$script:CapturedGaugeMetrics = @()
$script:TestId = $null

# Parse test ID from output (format: METRIC_TRIGGERED: <test-id>)
$metricTriggeredLines = @($script:MetricResult.Output | Where-Object { $_ -match 'METRIC_TRIGGERED: ' })
if ($metricTriggeredLines.Count -gt 0) {
$script:TestId = ($metricTriggeredLines[0] -split 'METRIC_TRIGGERED: ')[-1].Trim()
Write-Host "Captured Test ID: $($script:TestId)" -ForegroundColor Cyan

# Fetch all three metric types from Sentry with automatic polling
$metricFields = @('handler_added', 'to_be_removed')

try {
$script:CapturedCounterMetrics = Get-SentryTestMetric -MetricName 'test.integration.counter' -AttributeName 'test_id' -AttributeValue $script:TestId -Fields $metricFields
}
catch {
Write-Host "Warning (counter): $_" -ForegroundColor Red
}

try {
$script:CapturedDistributionMetrics = Get-SentryTestMetric -MetricName 'test.integration.distribution' -AttributeName 'test_id' -AttributeValue $script:TestId -Fields $metricFields
}
catch {
Write-Host "Warning (distribution): $_" -ForegroundColor Red
}

try {
$script:CapturedGaugeMetrics = Get-SentryTestMetric -MetricName 'test.integration.gauge' -AttributeName 'test_id' -AttributeValue $script:TestId -Fields $metricFields
}
catch {
Write-Host "Warning (gauge): $_" -ForegroundColor Red
}
}
else {
Write-Host "Warning: No METRIC_TRIGGERED line found in output" -ForegroundColor Yellow
}
}

It "Should output METRIC_TRIGGERED with test ID" {
$script:TestId | Should -Not -BeNullOrEmpty
}

It "Should output TEST_RESULT with success" {
$testResultLine = $script:MetricResult.Output | Where-Object { $_ -match 'TEST_RESULT:' }
$testResultLine | Should -Not -BeNullOrEmpty
$testResultLine | Should -Match '"success"\s*:\s*true'
}

# Counter metric assertions
It "Should capture counter metric in Sentry" {
$script:CapturedCounterMetrics | Should -Not -BeNullOrEmpty
}

It "Should have correct counter metric name and type" {
$metric = $script:CapturedCounterMetrics[0]
$metric.'metric.name' | Should -Be 'test.integration.counter'
$metric.'metric.type' | Should -Be 'counter'
}

It "Should have correct counter metric value" {
$metric = $script:CapturedCounterMetrics[0]
$metric.value | Should -Be 1.0
}

# Distribution metric assertions
It "Should capture distribution metric in Sentry" {
$script:CapturedDistributionMetrics | Should -Not -BeNullOrEmpty
}

It "Should have correct distribution metric name and type" {
$metric = $script:CapturedDistributionMetrics[0]
$metric.'metric.name' | Should -Be 'test.integration.distribution'
$metric.'metric.type' | Should -Be 'distribution'
}

It "Should have correct distribution metric value" {
$metric = $script:CapturedDistributionMetrics[0]
$metric.value | Should -Be 42.5
}

# Gauge metric assertions
It "Should capture gauge metric in Sentry" {
$script:CapturedGaugeMetrics | Should -Not -BeNullOrEmpty
}

It "Should have correct gauge metric name and type" {
$metric = $script:CapturedGaugeMetrics[0]
$metric.'metric.name' | Should -Be 'test.integration.gauge'
$metric.'metric.type' | Should -Be 'gauge'
}

It "Should have correct gauge metric value" {
$metric = $script:CapturedGaugeMetrics[0]
$metric.value | Should -Be 15.0
}

# BeforeMetricHandler attribute assertions (verified on counter, applies to all)
It "Should have attribute added by BeforeMetricHandler" {
$metric = $script:CapturedCounterMetrics[0]
$metric.'handler_added' | Should -Be 'added_value'
}

It "Should not have attribute removed by BeforeMetricHandler" {
$metric = $script:CapturedCounterMetrics[0]
$metric.'to_be_removed' | Should -BeNullOrEmpty
}

It "Should have test_id attribute matching captured ID" {
$metric = $script:CapturedCounterMetrics[0]
$metric.test_id | Should -Be $script:TestId
}
}
}

AfterAll {
Expand Down
142 changes: 142 additions & 0 deletions integration-test/Integration.Desktop.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,148 @@ Describe "Sentry Unreal Desktop Integration Tests (<Platform>)" -ForEach $TestTa
$log.global_removed | Should -BeNullOrEmpty
}
}

# Metrics are not supported on Apple platforms (macOS/iOS)
Context "Metrics Capture Tests" -Skip:$IsMacOS {
BeforeAll {
$script:MetricResult = $null
$script:CapturedCounterMetrics = @()
$script:CapturedDistributionMetrics = @()
$script:CapturedGaugeMetrics = @()
$script:TestId = $null

Write-Host "Running metrics capture test..." -ForegroundColor Yellow

$appArgs = @(
'-nullrhi', # Runs without graphics rendering (headless mode)
'-unattended', # Disables user prompts and interactive dialogs
'-stdout', # Ensures logs are written to stdout on Linux/Unix systems
'-nosplash' # Prevents splash screen and dialogs
)

# Override default project settings
$appArgs += "-ini:Engine:[/Script/Sentry.SentrySettings]:Dsn=$script:DSN"
$appArgs += "-ini:Engine:[/Script/Sentry.SentrySettings]:EnableMetrics=True"
$appArgs += "-ini:Engine:[/Script/Sentry.SentrySettings]:BeforeMetricHandler=/Script/SentryPlayground.CppBeforeMetricHandler"

# -metric-capture triggers integration test metric scenario in the sample app
$script:MetricResult = Invoke-DeviceApp -ExecutablePath $script:AppPath -Arguments ((@('-metric-capture') + $appArgs) -join ' ')

Write-Host "Metric test executed. Exit code: $($script:MetricResult.ExitCode)" -ForegroundColor Cyan

# Parse test ID from output (format: METRIC_TRIGGERED: <test-id>)
$metricTriggeredLines = @($script:MetricResult.Output | Where-Object { $_ -match 'METRIC_TRIGGERED: ' })
if ($metricTriggeredLines.Count -gt 0) {
$script:TestId = ($metricTriggeredLines[0] -split 'METRIC_TRIGGERED: ')[-1].Trim()
Write-Host "Captured Test ID: $($script:TestId)" -ForegroundColor Cyan

# Fetch all three metric types from Sentry with automatic polling
$metricFields = @('handler_added', 'to_be_removed')

try {
$script:CapturedCounterMetrics = Get-SentryTestMetric -MetricName 'test.integration.counter' -AttributeName 'test_id' -AttributeValue $script:TestId -Fields $metricFields
}
catch {
Write-Host "Warning (counter): $_" -ForegroundColor Red
}

try {
$script:CapturedDistributionMetrics = Get-SentryTestMetric -MetricName 'test.integration.distribution' -AttributeName 'test_id' -AttributeValue $script:TestId -Fields $metricFields
}
catch {
Write-Host "Warning (distribution): $_" -ForegroundColor Red
}

try {
$script:CapturedGaugeMetrics = Get-SentryTestMetric -MetricName 'test.integration.gauge' -AttributeName 'test_id' -AttributeValue $script:TestId -Fields $metricFields
}
catch {
Write-Host "Warning (gauge): $_" -ForegroundColor Red
}
}
else {
Write-Host "Warning: No METRIC_TRIGGERED line found in output" -ForegroundColor Yellow
}
}

It "Should exit cleanly" {
$script:MetricResult.ExitCode | Should -Be 0
}

It "Should output METRIC_TRIGGERED with test ID" {
$script:TestId | Should -Not -BeNullOrEmpty
}

It "Should output TEST_RESULT with success" {
$testResultLine = $script:MetricResult.Output | Where-Object { $_ -match 'TEST_RESULT:' }
$testResultLine | Should -Not -BeNullOrEmpty
$testResultLine | Should -Match '"success"\s*:\s*true'
}

# Counter metric assertions
It "Should capture counter metric in Sentry" {
$script:CapturedCounterMetrics | Should -Not -BeNullOrEmpty
}

It "Should have correct counter metric name and type" {
$metric = $script:CapturedCounterMetrics[0]
$metric.'metric.name' | Should -Be 'test.integration.counter'
$metric.'metric.type' | Should -Be 'counter'
}

It "Should have correct counter metric value" {
$metric = $script:CapturedCounterMetrics[0]
$metric.value | Should -Be 1.0
}

# Distribution metric assertions
It "Should capture distribution metric in Sentry" {
$script:CapturedDistributionMetrics | Should -Not -BeNullOrEmpty
}

It "Should have correct distribution metric name and type" {
$metric = $script:CapturedDistributionMetrics[0]
$metric.'metric.name' | Should -Be 'test.integration.distribution'
$metric.'metric.type' | Should -Be 'distribution'
}

It "Should have correct distribution metric value" {
$metric = $script:CapturedDistributionMetrics[0]
$metric.value | Should -Be 42.5
}

# Gauge metric assertions
It "Should capture gauge metric in Sentry" {
$script:CapturedGaugeMetrics | Should -Not -BeNullOrEmpty
}

It "Should have correct gauge metric name and type" {
$metric = $script:CapturedGaugeMetrics[0]
$metric.'metric.name' | Should -Be 'test.integration.gauge'
$metric.'metric.type' | Should -Be 'gauge'
}

It "Should have correct gauge metric value" {
$metric = $script:CapturedGaugeMetrics[0]
$metric.value | Should -Be 15.0
}

# BeforeMetricHandler attribute assertions (verified on counter, applies to all)
It "Should have attribute added by BeforeMetricHandler" {
$metric = $script:CapturedCounterMetrics[0]
$metric.'handler_added' | Should -Be 'added_value'
}

It "Should not have attribute removed by BeforeMetricHandler" {
$metric = $script:CapturedCounterMetrics[0]
$metric.'to_be_removed' | Should -BeNullOrEmpty
}

It "Should have test_id attribute matching captured ID" {
$metric = $script:CapturedCounterMetrics[0]
$metric.test_id | Should -Be $script:TestId
}
}
}

AfterAll {
Expand Down

This file was deleted.

This file was deleted.

13 changes: 13 additions & 0 deletions sample/Source/SentryPlayground/CppBeforeMetricHandler.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
// Copyright (c) 2025 Sentry. All Rights Reserved.

#include "CppBeforeMetricHandler.h"

#include "SentryMetric.h"

USentryMetric* UCppBeforeMetricHandler::HandleBeforeMetric_Implementation(USentryMetric* Metric)
{
Metric->SetAttribute(TEXT("handler_added"), FSentryVariant(TEXT("added_value")));
Metric->RemoveAttribute(TEXT("to_be_removed"));

return Super::HandleBeforeMetric_Implementation(Metric);
}
Loading