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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Features

- Add app hang tracking for desktop platforms ([#1270](https://github.com/getsentry/sentry-unreal/pull/1270))
- Add global attributes support for Android ([#1274](https://github.com/getsentry/sentry-unreal/pull/1274))

### Fixes

Expand Down
25 changes: 21 additions & 4 deletions integration-test/Integration.Android.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ Describe 'Sentry Unreal Android Integration Tests (<Platform>)' -ForEach $TestTa

# Fetch logs from Sentry with automatic polling
try {
$script:CapturedLogs = Get-SentryTestLog -AttributeName 'test_id' -AttributeValue $script:TestId -Fields @('handler_added', 'to_be_removed')
$script:CapturedLogs = Get-SentryTestLog -AttributeName 'test_id' -AttributeValue $script:TestId -Fields @('handler_added', 'to_be_removed', 'global_attr', 'global_removed')
}
catch {
Write-Host "Warning: $_" -ForegroundColor Red
Expand Down Expand Up @@ -483,8 +483,15 @@ Describe 'Sentry Unreal Android Integration Tests (<Platform>)' -ForEach $TestTa
$log.'to_be_removed' | Should -BeNullOrEmpty
}

# 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.
It "Should have global attribute set on subsystem" {
$log = $script:CapturedLogs[0]
$log.global_attr | Should -Be 'global_value'
}

It "Should not have global attribute that was removed from subsystem" {
$log = $script:CapturedLogs[0]
$log.global_removed | Should -BeNullOrEmpty
}
}

Context "Metrics Capture Tests" {
Expand All @@ -502,7 +509,7 @@ Describe 'Sentry Unreal Android Integration Tests (<Platform>)' -ForEach $TestTa
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')
$metricFields = @('handler_added', 'to_be_removed', 'global_attr', 'global_removed')

try {
$script:CapturedCounterMetrics = Get-SentryTestMetric -MetricName 'test.integration.counter' -AttributeName 'test_id' -AttributeValue $script:TestId -Fields $metricFields
Expand Down Expand Up @@ -603,6 +610,16 @@ Describe 'Sentry Unreal Android Integration Tests (<Platform>)' -ForEach $TestTa
$metric = $script:CapturedCounterMetrics[0]
$metric.test_id | Should -Be $script:TestId
}

It "Should have global attribute set on subsystem" {
$metric = $script:CapturedCounterMetrics[0]
$metric.global_attr | Should -Be 'global_value'
}

It "Should not have global attribute that was removed from subsystem" {
$metric = $script:CapturedCounterMetrics[0]
$metric.global_removed | Should -BeNullOrEmpty
}
}

Context "Tracing Capture Tests" {
Expand Down
12 changes: 11 additions & 1 deletion integration-test/Integration.Desktop.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ Describe "Sentry Unreal Desktop Integration Tests (<Platform>)" -ForEach $TestTa
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')
$metricFields = @('handler_added', 'to_be_removed', 'global_attr', 'global_removed')

try {
$script:CapturedCounterMetrics = Get-SentryTestMetric -MetricName 'test.integration.counter' -AttributeName 'test_id' -AttributeValue $script:TestId -Fields $metricFields
Expand Down Expand Up @@ -635,6 +635,16 @@ Describe "Sentry Unreal Desktop Integration Tests (<Platform>)" -ForEach $TestTa
$metric = $script:CapturedCounterMetrics[0]
$metric.test_id | Should -Be $script:TestId
}

It "Should have global attribute set on subsystem" {
$metric = $script:CapturedCounterMetrics[0]
$metric.global_attr | Should -Be 'global_value'
}

It "Should not have global attribute that was removed from subsystem" {
$metric = $script:CapturedCounterMetrics[0]
$metric.global_removed | Should -BeNullOrEmpty
}
}

Context "Tracing Capture Tests" {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,12 +382,18 @@ void FAndroidSentrySubsystem::RemoveTag(const FString& key)

void FAndroidSentrySubsystem::SetAttribute(const FString& key, const FSentryVariant& value)
{
// No-op: Android SDK doesn't support global log attributes
TSharedPtr<FSentryJavaObjectWrapper> nativeValue = FAndroidSentryConverters::VariantToNative(value);
if (nativeValue.IsValid())
{
FSentryJavaObjectWrapper::CallStaticMethod<void>(SentryJavaClasses::SentryBridgeJava, "setAttribute", "(Ljava/lang/String;Ljava/lang/Object;)V",
*FSentryJavaObjectWrapper::GetJString(key), nativeValue->GetJObject());
}
}

void FAndroidSentrySubsystem::RemoveAttribute(const FString& key)
{
// No-op: Android SDK doesn't support global log attributes
FSentryJavaObjectWrapper::CallStaticMethod<void>(SentryJavaClasses::SentryBridgeJava, "removeAttribute", "(Ljava/lang/String;)V",
*FSentryJavaObjectWrapper::GetJString(key));
}

void FAndroidSentrySubsystem::SetLevel(ESentryLevel level)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,14 @@ public void run(@NonNull IScope scope) {
});
}

public static void setAttribute(final String key, final Object value) {
Sentry.setAttribute(key, value);
}

public static void removeAttribute(final String key) {
Sentry.removeAttribute(key);
}

public static void setLevel(final SentryLevel level) {
Sentry.configureScope(new ScopeCallback() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,11 @@ void USentryPlaygroundGameInstance::RunMetricTest()

FString TestId = FGuid::NewGuid().ToString(EGuidFormats::DigitsWithHyphens);

SentrySubsystem->SetAttribute(TEXT("global_attr"), FSentryVariant(TEXT("global_value")));

SentrySubsystem->SetAttribute(TEXT("global_removed"), FSentryVariant(TEXT("should_not_appear")));
SentrySubsystem->RemoveAttribute(TEXT("global_removed"));

TMap<FString, FSentryVariant> CounterAttributes;
CounterAttributes.Add(TEXT("test_id"), FSentryVariant(TestId));
CounterAttributes.Add(TEXT("to_be_removed"), FSentryVariant(TEXT("original_value")));
Expand Down