From 662f7ba3772c87066d285ae93233534690da073b Mon Sep 17 00:00:00 2001 From: Ivan Tustanivskyi Date: Tue, 25 Jul 2023 14:13:53 +0300 Subject: [PATCH 1/2] Add new plugin settings --- .../SentryConvertorsAndroid.cpp | 16 ++++++++++++- .../Infrastructure/SentryConvertorsAndroid.h | 4 ++++ .../Android/Java/SentryBridgeJava.java | 15 ++++++++++++ .../Android/SentrySubsystemAndroid.cpp | 7 ++++++ .../Private/Apple/SentrySubsystemApple.cpp | 15 ++++++++++++ .../Desktop/SentrySubsystemDesktop.cpp | 2 ++ .../Source/Sentry/Private/SentrySettings.cpp | 6 ++++- .../Source/Sentry/Public/SentrySettings.h | 24 +++++++++++++++++++ 8 files changed, 87 insertions(+), 2 deletions(-) diff --git a/plugin-dev/Source/Sentry/Private/Android/Infrastructure/SentryConvertorsAndroid.cpp b/plugin-dev/Source/Sentry/Private/Android/Infrastructure/SentryConvertorsAndroid.cpp index 7eeb06a4..9c5caaa8 100644 --- a/plugin-dev/Source/Sentry/Private/Android/Infrastructure/SentryConvertorsAndroid.cpp +++ b/plugin-dev/Source/Sentry/Private/Android/Infrastructure/SentryConvertorsAndroid.cpp @@ -14,6 +14,8 @@ #include "Android/AndroidApplication.h" #include "Android/AndroidJavaEnv.h" +#include "Dom/JsonValue.h" + TSharedPtr SentryConvertorsAndroid::SentryLevelToNative(ESentryLevel level) { TSharedPtr nativeLevel = nullptr; @@ -219,4 +221,16 @@ TArray SentryConvertorsAndroid::ByteArrayToUnreal(jbyteArray byteArray) } return result; -} \ No newline at end of file +} + +TArray> SentryConvertorsAndroid::StrinArrayToJsonArray(const TArray& stringArray) +{ + TArray> jsonArray; + + for (const FString& stringItem : stringArray) + { + jsonArray.Add(MakeShareable(new FJsonValueString(stringItem))); + } + + return jsonArray; +} diff --git a/plugin-dev/Source/Sentry/Private/Android/Infrastructure/SentryConvertorsAndroid.h b/plugin-dev/Source/Sentry/Private/Android/Infrastructure/SentryConvertorsAndroid.h index 3ec1bd40..0c91f567 100644 --- a/plugin-dev/Source/Sentry/Private/Android/Infrastructure/SentryConvertorsAndroid.h +++ b/plugin-dev/Source/Sentry/Private/Android/Infrastructure/SentryConvertorsAndroid.h @@ -9,6 +9,7 @@ class USentryScope; class USentryId; class FSentryJavaObjectWrapper; +class FJsonValue; class SentryConvertorsAndroid { @@ -26,4 +27,7 @@ class SentryConvertorsAndroid static TMap StringMapToUnreal(jobject stringMap); static TArray StringListToUnreal(jobject stringList); static TArray ByteArrayToUnreal(jbyteArray byteArray); + + /** Other conversions */ + static TArray> StrinArrayToJsonArray(const TArray& stringArray); }; diff --git a/plugin-dev/Source/Sentry/Private/Android/Java/SentryBridgeJava.java b/plugin-dev/Source/Sentry/Private/Android/Java/SentryBridgeJava.java index d53810c1..27a95de3 100644 --- a/plugin-dev/Source/Sentry/Private/Android/Java/SentryBridgeJava.java +++ b/plugin-dev/Source/Sentry/Private/Android/Java/SentryBridgeJava.java @@ -3,9 +3,11 @@ package io.sentry.unreal; import android.app.Activity; +import android.util.Log; import androidx.annotation.NonNull; +import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -41,12 +43,25 @@ public void configure(SentryAndroidOptions options) { options.setEnableAutoSessionTracking(settingJson.getBoolean("autoSessionTracking")); options.setSessionTrackingIntervalMillis(settingJson.getLong("sessionTimeout")); options.setAttachStacktrace(settingJson.getBoolean("enableStackTrace")); + options.setDebug(settingJson.getBoolean("debug")); + options.setSampleRate(settingJson.getDouble("sampleRate")); + options.setMaxBreadcrumbs(settingJson.getInt("maxBreadcrumbs")); + options.setAttachScreenshot(settingJson.getBoolean("attachScreenshot")); + options.setSendDefaultPii(settingJson.getBoolean("sendDefaultPii")); options.setBeforeSend(new SentryOptions.BeforeSendCallback() { @Override public SentryEvent execute(SentryEvent event, Hint hint) { return onBeforeSend(beforeSendHandler, event, hint); } }); + JSONArray Includes = settingJson.getJSONArray("inAppIncludes"); + for (int i = 0; i < Includes.length(); i++) { + options.addInAppInclude(Includes.getString(i)); + } + JSONArray Excludes = settingJson.getJSONArray("inAppExcludes"); + for (int i = 0; i < Excludes.length(); i++) { + options.addInAppExclude(Excludes.getString(i)); + } } catch (JSONException e) { throw new RuntimeException(e); } diff --git a/plugin-dev/Source/Sentry/Private/Android/SentrySubsystemAndroid.cpp b/plugin-dev/Source/Sentry/Private/Android/SentrySubsystemAndroid.cpp index 88ec286c..4ce9f5f4 100644 --- a/plugin-dev/Source/Sentry/Private/Android/SentrySubsystemAndroid.cpp +++ b/plugin-dev/Source/Sentry/Private/Android/SentrySubsystemAndroid.cpp @@ -37,6 +37,13 @@ void SentrySubsystemAndroid::InitWithSettings(const USentrySettings* settings, U SettingsJson->SetBoolField(TEXT("autoSessionTracking"), settings->EnableAutoSessionTracking); SettingsJson->SetNumberField(TEXT("sessionTimeout"), settings->SessionTimeout); SettingsJson->SetBoolField(TEXT("enableStackTrace"), settings->EnableStackTrace); + SettingsJson->SetBoolField(TEXT("debug"), settings->EnableVerboseLogging); + SettingsJson->SetNumberField(TEXT("sampleRate"), settings->SampleRate); + SettingsJson->SetNumberField(TEXT("maxBreadcrumbs"), settings->MaxBreadcrumbs); + SettingsJson->SetBoolField(TEXT("attachScreenshot"), settings->AttachScreenshots); + SettingsJson->SetArrayField(TEXT("inAppIncludes"), SentryConvertorsAndroid::StrinArrayToJsonArray(settings->InAppIncludes)); + SettingsJson->SetArrayField(TEXT("inAppExcludes"), SentryConvertorsAndroid::StrinArrayToJsonArray(settings->InAppExcludes)); + SettingsJson->SetBoolField(TEXT("sendDefaultPii"), settings->SendDafaultPii); FString SettingsJsonStr; TSharedRef> JsonWriter = TJsonWriterFactory<>::Create(&SettingsJsonStr); diff --git a/plugin-dev/Source/Sentry/Private/Apple/SentrySubsystemApple.cpp b/plugin-dev/Source/Sentry/Private/Apple/SentrySubsystemApple.cpp index d665e2d2..42649611 100644 --- a/plugin-dev/Source/Sentry/Private/Apple/SentrySubsystemApple.cpp +++ b/plugin-dev/Source/Sentry/Private/Apple/SentrySubsystemApple.cpp @@ -37,6 +37,13 @@ void SentrySubsystemApple::InitWithSettings(const USentrySettings* settings, USe ? settings->Release.GetNSString() : settings->GetFormattedReleaseName().GetNSString(); options.attachStacktrace = settings->EnableStackTrace; + options.debug = settings->EnableVerboseLogging; + options.sampleRate = [NSNumber numberWithFloat:settings->SampleRate]; + options.maxBreadcrumbs = settings->MaxBreadcrumbs; + options.sendDefaultPii = settings->SendDafaultPii; +#if PLATFORM_IOS + options.attachScreenshot = settings->AttachScreenshots; +#endif options.initialScope = ^(SentryScope *scope) { if(settings->EnableAutoLogAttachment) { const FString logFilePath = IFileManager::Get().ConvertToAbsolutePathForExternalAppForRead(*FGenericPlatformOutputDevices::GetAbsoluteLogFilename()); @@ -50,6 +57,14 @@ void SentrySubsystemApple::InitWithSettings(const USentrySettings* settings, USe EventToProcess->InitWithNativeImpl(MakeShareable(new SentryEventApple(event))); return beforeSendHandler->HandleBeforeSend(EventToProcess, nullptr) ? event : nullptr; }; + for (auto it = settings->InAppIncludes.CreateConstIterator(); it; ++it) + { + [options addInAppInclude:it->GetNSString()]; + } + for (auto it = settings->InAppExcludes.CreateConstIterator(); it; ++it) + { + [options addInAppExclude:it->GetNSString()]; + } }]; } diff --git a/plugin-dev/Source/Sentry/Private/Desktop/SentrySubsystemDesktop.cpp b/plugin-dev/Source/Sentry/Private/Desktop/SentrySubsystemDesktop.cpp index 5096aff4..4cdf470e 100644 --- a/plugin-dev/Source/Sentry/Private/Desktop/SentrySubsystemDesktop.cpp +++ b/plugin-dev/Source/Sentry/Private/Desktop/SentrySubsystemDesktop.cpp @@ -109,6 +109,8 @@ void SentrySubsystemDesktop::InitWithSettings(const USentrySettings* settings, U sentry_options_set_logger(options, PrintVerboseLog, nullptr); sentry_options_set_debug(options, settings->EnableVerboseLogging); sentry_options_set_auto_session_tracking(options, settings->EnableAutoSessionTracking); + sentry_options_set_sample_rate(options, settings->SampleRate); + sentry_options_set_max_breadcrumbs(options, settings->MaxBreadcrumbs); sentry_options_set_before_send(options, HandleBeforeSend, this); #if PLATFORM_LINUX diff --git a/plugin-dev/Source/Sentry/Private/SentrySettings.cpp b/plugin-dev/Source/Sentry/Private/SentrySettings.cpp index 4e218413..338b4240 100644 --- a/plugin-dev/Source/Sentry/Private/SentrySettings.cpp +++ b/plugin-dev/Source/Sentry/Private/SentrySettings.cpp @@ -16,8 +16,12 @@ USentrySettings::USentrySettings(const FObjectInitializer& ObjectInitializer) , EnableAutoCrashCapturing(true) , EnableAutoLogAttachment(false) , EnableStackTrace(true) - , UseProxy(false) + , UseProxy(false) , ProxyUrl() + , SampleRate(1.0f) + , MaxBreadcrumbs(100) + , AttachScreenshots(false) + , SendDafaultPii(false) , EnableAutoSessionTracking(true) , SessionTimeout(30000) , OverrideReleaseName(false) diff --git a/plugin-dev/Source/Sentry/Public/SentrySettings.h b/plugin-dev/Source/Sentry/Public/SentrySettings.h index ca301cba..3dde08d5 100644 --- a/plugin-dev/Source/Sentry/Public/SentrySettings.h +++ b/plugin-dev/Source/Sentry/Public/SentrySettings.h @@ -177,6 +177,30 @@ class SENTRY_API USentrySettings : public UObject Meta = (DisplayName = "HTTP proxy (for Windows/Linux only)", ToolTip = "HTTP proxy through which requests can be tunneled to Sentry.", EditCondition = "UseProxy")) FString ProxyUrl; + UPROPERTY(Config, EditAnywhere, Category = "Misc", + Meta = (DisplayName = "Sample rate", ToolTip = "Configures the sample rate for error events in the range of 0.0 to 1.0. The default is 1.0 which means that 100% of error events are sent. If set to 0.1 only 10% of error events will be sent. Events are picked randomly.", ClampMin = 0.0f, ClampMax = 1.0f)) + float SampleRate; + + UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "Misc", + Meta = (DisplayName = "Max breadcrumbs", Tooltip = "Total amount of breadcrumbs that should be captured.")) + int32 MaxBreadcrumbs; + + UPROPERTY(Config, EditAnywhere, Category = "Misc", + Meta = (DisplayName = "Attach screenshots (for iOS only)", ToolTip = "Flag indicating whether to attach screenshot of the application when an error occurs.")) + bool AttachScreenshots; + + UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "Misc", + Meta = (DisplayName = "In-app includes (for Android/Apple only)", Tooltip = "A list of string prefixes of module names that belong to the app.")) + TArray InAppIncludes; + + UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "Misc", + Meta = (DisplayName = "In-app exludes (for Android/Apple only)", Tooltip = "A list of string prefixes of module names that don't belong to the app.")) + TArray InAppExcludes; + + UPROPERTY(Config, EditAnywhere, Category = "Misc", + Meta = (DisplayName = "Attach personally identifiable information (for Android/Apple only)", ToolTip = "Flag indicating whether to attach personally identifiable information (PII) to captured events.")) + bool SendDafaultPii; + UPROPERTY(Config, EditAnywhere, Category = "Release & Health", Meta = (DisplayName = "Enable automatic session tracking ", ToolTip = "Flag indicating whether the SDK should automatically start a new session when it is initialized.")) bool EnableAutoSessionTracking; From 817815c3e250c321495f102e4655cd9df266e8ea Mon Sep 17 00:00:00 2001 From: Ivan Tustanivskyi Date: Tue, 25 Jul 2023 14:19:51 +0300 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 049e4918..a8d39574 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ - Add HTTP proxy for desktop ([#322](https://github.com/getsentry/sentry-unreal/pull/322)) - Add scope support for Windows/Linux ([#328](https://github.com/getsentry/sentry-unreal/pull/328)) +- Add missing plugin settings ([#335](https://github.com/getsentry/sentry-unreal/pull/335)) ### Fixes