Skip to content

Commit

Permalink
Add missing plugin settings (#335)
Browse files Browse the repository at this point in the history
* Add new plugin settings

* Update changelog
  • Loading branch information
tustanivsky authored Jul 28, 2023
1 parent e5e9af1 commit 5a92770
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "Android/AndroidApplication.h"
#include "Android/AndroidJavaEnv.h"

#include "Dom/JsonValue.h"

TSharedPtr<FSentryJavaObjectWrapper> SentryConvertorsAndroid::SentryLevelToNative(ESentryLevel level)
{
TSharedPtr<FSentryJavaObjectWrapper> nativeLevel = nullptr;
Expand Down Expand Up @@ -219,4 +221,16 @@ TArray<uint8> SentryConvertorsAndroid::ByteArrayToUnreal(jbyteArray byteArray)
}

return result;
}
}

TArray<TSharedPtr<FJsonValue>> SentryConvertorsAndroid::StrinArrayToJsonArray(const TArray<FString>& stringArray)
{
TArray<TSharedPtr<FJsonValue>> jsonArray;

for (const FString& stringItem : stringArray)
{
jsonArray.Add(MakeShareable(new FJsonValueString(stringItem)));
}

return jsonArray;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
class USentryScope;
class USentryId;
class FSentryJavaObjectWrapper;
class FJsonValue;

class SentryConvertorsAndroid
{
Expand All @@ -26,4 +27,7 @@ class SentryConvertorsAndroid
static TMap<FString, FString> StringMapToUnreal(jobject stringMap);
static TArray<FString> StringListToUnreal(jobject stringList);
static TArray<uint8> ByteArrayToUnreal(jbyteArray byteArray);

/** Other conversions */
static TArray<TSharedPtr<FJsonValue>> StrinArrayToJsonArray(const TArray<FString>& stringArray);
};
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<TJsonWriter<>> JsonWriter = TJsonWriterFactory<>::Create(&SettingsJsonStr);
Expand Down
15 changes: 15 additions & 0 deletions plugin-dev/Source/Sentry/Private/Apple/SentrySubsystemApple.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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()];
}
}];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion plugin-dev/Source/Sentry/Private/SentrySettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
24 changes: 24 additions & 0 deletions plugin-dev/Source/Sentry/Public/SentrySettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<FString> 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<FString> 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;
Expand Down

0 comments on commit 5a92770

Please sign in to comment.