diff --git a/CHANGELOG.md b/CHANGELOG.md index 2d45e338..e59d0f84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,15 @@ ## Unreleased +### Breaking Changes + +- `Environment` and `Dist` get/set functions were removed from the `Scope` class and now these properties have to be set in plugin settings instead. This unifies their usage across all platforms supported by the Unreal SDK. +- `ConfigureScope` function was removed from `SentrySubsystem` class following the [Hub & Scope refactoring guidelines](https://develop.sentry.dev/sdk/miscellaneous/hub_and_scope_refactoring/) which recommend deprecating this API. + +### Features + +- Add native local scope for Windows/Linux ([#928](https://github.com/getsentry/sentry-unreal/pull/928)) + ### Dependencies - Bump Java SDK (Android) from v8.13.1 to v8.13.2 ([#932](https://github.com/getsentry/sentry-unreal/pull/932)) diff --git a/modules/sentry-native b/modules/sentry-native index 6129d36d..7c80f6f3 160000 --- a/modules/sentry-native +++ b/modules/sentry-native @@ -1 +1 @@ -Subproject commit 6129d36d717b77d53c8af8fe439ed0370fb63ea4 +Subproject commit 7c80f6f332094ccd15a7b966113bceae8f1ca4b1 diff --git a/plugin-dev/Source/Sentry/Private/Android/AndroidSentryScope.cpp b/plugin-dev/Source/Sentry/Private/Android/AndroidSentryScope.cpp index a01b5231..596261ca 100644 --- a/plugin-dev/Source/Sentry/Private/Android/AndroidSentryScope.cpp +++ b/plugin-dev/Source/Sentry/Private/Android/AndroidSentryScope.cpp @@ -99,26 +99,6 @@ TMap FAndroidSentryScope::GetTags() const return FAndroidSentryConverters::StringMapToUnreal(*tags); } -void FAndroidSentryScope::SetDist(const FString& dist) -{ - SetTagValue("dist", dist); -} - -FString FAndroidSentryScope::GetDist() const -{ - return GetTagValue("dist"); -} - -void FAndroidSentryScope::SetEnvironment(const FString& environment) -{ - SetTagValue("environment", environment); -} - -FString FAndroidSentryScope::GetEnvironment() const -{ - return GetTagValue("environment"); -} - void FAndroidSentryScope::SetFingerprint(const TArray& fingerprint) { CallMethod(SetFingerprintMethod, FAndroidSentryConverters::StringArrayToNative(fingerprint)->GetJObject()); diff --git a/plugin-dev/Source/Sentry/Private/Android/AndroidSentryScope.h b/plugin-dev/Source/Sentry/Private/Android/AndroidSentryScope.h index 775b96b0..960423e9 100644 --- a/plugin-dev/Source/Sentry/Private/Android/AndroidSentryScope.h +++ b/plugin-dev/Source/Sentry/Private/Android/AndroidSentryScope.h @@ -23,10 +23,6 @@ class FAndroidSentryScope : public ISentryScope, public FSentryJavaObjectWrapper virtual void RemoveTag(const FString& key) override; virtual void SetTags(const TMap& tags) override; virtual TMap GetTags() const override; - virtual void SetDist(const FString& dist) override; - virtual FString GetDist() const override; - virtual void SetEnvironment(const FString& environment) override; - virtual FString GetEnvironment() const override; virtual void SetFingerprint(const TArray& fingerprint) override; virtual TArray GetFingerprint() const override; virtual void SetLevel(ESentryLevel level) override; diff --git a/plugin-dev/Source/Sentry/Private/Android/AndroidSentrySubsystem.cpp b/plugin-dev/Source/Sentry/Private/Android/AndroidSentrySubsystem.cpp index 114fce53..b2a8f136 100644 --- a/plugin-dev/Source/Sentry/Private/Android/AndroidSentrySubsystem.cpp +++ b/plugin-dev/Source/Sentry/Private/Android/AndroidSentrySubsystem.cpp @@ -33,6 +33,7 @@ void FAndroidSentrySubsystem::InitWithSettings(const USentrySettings* settings, SettingsJson->SetStringField(TEXT("dsn"), settings->Dsn); SettingsJson->SetStringField(TEXT("release"), settings->OverrideReleaseName ? settings->Release : settings->GetFormattedReleaseName()); SettingsJson->SetStringField(TEXT("environment"), settings->Environment); + SettingsJson->SetStringField(TEXT("dist"), settings->Dist); SettingsJson->SetBoolField(TEXT("autoSessionTracking"), settings->EnableAutoSessionTracking); SettingsJson->SetNumberField(TEXT("sessionTimeout"), settings->SessionTimeout); SettingsJson->SetBoolField(TEXT("enableStackTrace"), settings->AttachStacktrace); @@ -195,13 +196,6 @@ void FAndroidSentrySubsystem::RemoveUser() FSentryJavaObjectWrapper::CallStaticMethod(SentryJavaClasses::Sentry, "setUser", "(Lio/sentry/protocol/User;)V", nullptr); } -void FAndroidSentrySubsystem::ConfigureScope(const FSentryScopeDelegate& onConfigureScope) -{ - int64 scopeCallbackId = AndroidSentryScopeCallback::SaveDelegate(onConfigureScope); - - FSentryJavaObjectWrapper::CallStaticMethod(SentryJavaClasses::SentryBridgeJava, "configureScope", "(J)V", scopeCallbackId); -} - void FAndroidSentrySubsystem::SetContext(const FString& key, const TMap& values) { FSentryJavaObjectWrapper::CallStaticMethod(SentryJavaClasses::SentryBridgeJava, "setContext", "(Ljava/lang/String;Ljava/util/HashMap;)V", diff --git a/plugin-dev/Source/Sentry/Private/Android/AndroidSentrySubsystem.h b/plugin-dev/Source/Sentry/Private/Android/AndroidSentrySubsystem.h index b0b7d056..b8303c8b 100644 --- a/plugin-dev/Source/Sentry/Private/Android/AndroidSentrySubsystem.h +++ b/plugin-dev/Source/Sentry/Private/Android/AndroidSentrySubsystem.h @@ -22,7 +22,6 @@ class FAndroidSentrySubsystem : public ISentrySubsystem virtual void CaptureUserFeedback(TSharedPtr userFeedback) override; virtual void SetUser(TSharedPtr user) override; virtual void RemoveUser() override; - virtual void ConfigureScope(const FSentryScopeDelegate& onConfigureScope) override; virtual void SetContext(const FString& key, const TMap& values) override; virtual void SetTag(const FString& key, const FString& value) override; virtual void RemoveTag(const FString& key) override; diff --git a/plugin-dev/Source/Sentry/Private/Android/Java/SentryBridgeJava.java b/plugin-dev/Source/Sentry/Private/Android/Java/SentryBridgeJava.java index 5cf59c54..93b07955 100644 --- a/plugin-dev/Source/Sentry/Private/Android/Java/SentryBridgeJava.java +++ b/plugin-dev/Source/Sentry/Private/Android/Java/SentryBridgeJava.java @@ -46,6 +46,7 @@ public void configure(SentryAndroidOptions options) { options.setDsn(settingJson.getString("dsn")); options.setRelease(settingJson.getString("release")); options.setEnvironment(settingJson.getString("environment")); + options.setDist(settingJson.getString("dist")); options.setEnableAutoSessionTracking(settingJson.getBoolean("autoSessionTracking")); options.setSessionTrackingIntervalMillis(settingJson.getLong("sessionTimeout")); options.setAttachStacktrace(settingJson.getBoolean("enableStackTrace")); @@ -146,15 +147,6 @@ public static SentryId captureException(final String type, final String value) { return eventId; } - public static void configureScope(final long callback) { - Sentry.configureScope(new ScopeCallback() { - @Override - public void run(@NonNull IScope scope) { - onConfigureScope(callback, scope); - } - }); - } - public static void setContext(final String key, final HashMap values) { Sentry.configureScope(new ScopeCallback() { @Override diff --git a/plugin-dev/Source/Sentry/Private/Apple/AppleSentryScope.cpp b/plugin-dev/Source/Sentry/Private/Apple/AppleSentryScope.cpp index 5daaaea6..c4a991ee 100644 --- a/plugin-dev/Source/Sentry/Private/Apple/AppleSentryScope.cpp +++ b/plugin-dev/Source/Sentry/Private/Apple/AppleSentryScope.cpp @@ -81,28 +81,6 @@ TMap FAppleSentryScope::GetTags() const return FAppleSentryConverters::StringMapToUnreal(scopeDict[@"tags"]); } -void FAppleSentryScope::SetDist(const FString& dist) -{ - [ScopeApple setDist:dist.GetNSString()]; -} - -FString FAppleSentryScope::GetDist() const -{ - NSDictionary* scopeDict = [ScopeApple serialize]; - return FString(scopeDict[@"dist"]); -} - -void FAppleSentryScope::SetEnvironment(const FString& environment) -{ - [ScopeApple setEnvironment:environment.GetNSString()]; -} - -FString FAppleSentryScope::GetEnvironment() const -{ - NSDictionary* scopeDict = [ScopeApple serialize]; - return FString(scopeDict[@"environment"]); -} - void FAppleSentryScope::SetFingerprint(const TArray& fingerprint) { [ScopeApple setFingerprint:FAppleSentryConverters::StringArrayToNative(fingerprint)]; diff --git a/plugin-dev/Source/Sentry/Private/Apple/AppleSentryScope.h b/plugin-dev/Source/Sentry/Private/Apple/AppleSentryScope.h index 83e68a61..a0683a08 100644 --- a/plugin-dev/Source/Sentry/Private/Apple/AppleSentryScope.h +++ b/plugin-dev/Source/Sentry/Private/Apple/AppleSentryScope.h @@ -24,10 +24,6 @@ class FAppleSentryScope : public ISentryScope virtual void RemoveTag(const FString& key) override; virtual void SetTags(const TMap& tags) override; virtual TMap GetTags() const override; - virtual void SetDist(const FString& dist) override; - virtual FString GetDist() const override; - virtual void SetEnvironment(const FString& environment) override; - virtual FString GetEnvironment() const override; virtual void SetFingerprint(const TArray& fingerprint) override; virtual TArray GetFingerprint() const override; virtual void SetLevel(ESentryLevel level) override; diff --git a/plugin-dev/Source/Sentry/Private/Apple/AppleSentrySubsystem.cpp b/plugin-dev/Source/Sentry/Private/Apple/AppleSentrySubsystem.cpp index f05da944..0bd0eb03 100644 --- a/plugin-dev/Source/Sentry/Private/Apple/AppleSentrySubsystem.cpp +++ b/plugin-dev/Source/Sentry/Private/Apple/AppleSentrySubsystem.cpp @@ -56,6 +56,7 @@ void FAppleSentrySubsystem::InitWithSettings(const USentrySettings* settings, US } #endif options.environment = settings->Environment.GetNSString(); + options.dist = settings->Dist.GetNSString(); options.enableAutoSessionTracking = settings->EnableAutoSessionTracking; options.sessionTrackingIntervalMillis = settings->SessionTimeout; options.releaseName = settings->OverrideReleaseName ? settings->Release.GetNSString() : settings->GetFormattedReleaseName().GetNSString(); @@ -288,13 +289,6 @@ void FAppleSentrySubsystem::RemoveUser() [SentrySDK setUser:nil]; } -void FAppleSentrySubsystem::ConfigureScope(const FSentryScopeDelegate& onConfigureScope) -{ - [SentrySDK configureScope:^(SentryScope* scope) { - onConfigureScope.ExecuteIfBound(MakeShareable(new FAppleSentryScope(scope))); - }]; -} - void FAppleSentrySubsystem::SetContext(const FString& key, const TMap& values) { [SentrySDK configureScope:^(SentryScope* scope) { diff --git a/plugin-dev/Source/Sentry/Private/Apple/AppleSentrySubsystem.h b/plugin-dev/Source/Sentry/Private/Apple/AppleSentrySubsystem.h index 0ff416c0..4e823e42 100644 --- a/plugin-dev/Source/Sentry/Private/Apple/AppleSentrySubsystem.h +++ b/plugin-dev/Source/Sentry/Private/Apple/AppleSentrySubsystem.h @@ -22,7 +22,6 @@ class FAppleSentrySubsystem : public ISentrySubsystem virtual void CaptureUserFeedback(TSharedPtr userFeedback) override; virtual void SetUser(TSharedPtr user) override; virtual void RemoveUser() override; - virtual void ConfigureScope(const FSentryScopeDelegate& onConfigureScope) override; virtual void SetContext(const FString& key, const TMap& values) override; virtual void SetTag(const FString& key, const FString& value) override; virtual void RemoveTag(const FString& key) override; diff --git a/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentryScope.cpp b/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentryScope.cpp index 73e2fcac..4249c222 100644 --- a/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentryScope.cpp +++ b/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentryScope.cpp @@ -18,26 +18,12 @@ FGenericPlatformSentryScope::FGenericPlatformSentryScope() { } -FGenericPlatformSentryScope::FGenericPlatformSentryScope(const FGenericPlatformSentryScope& Scope) -{ - Dist = Scope.Dist; - Environment = Scope.Environment; - Fingerprint = Scope.Fingerprint; - Tags = Scope.Tags; - Extra = Scope.Extra; - Contexts = Scope.Contexts; - Breadcrumbs = TRingBuffer>(Scope.Breadcrumbs); - Level = Scope.Level; -} - FGenericPlatformSentryScope::~FGenericPlatformSentryScope() { } void FGenericPlatformSentryScope::AddBreadcrumb(TSharedPtr breadcrumb) { - FScopeLock Lock(&CriticalSection); - if (Breadcrumbs.Num() >= FSentryModule::Get().GetSettings()->MaxBreadcrumbs) { Breadcrumbs.PopFront(); @@ -48,8 +34,6 @@ void FGenericPlatformSentryScope::AddBreadcrumb(TSharedPtr br void FGenericPlatformSentryScope::ClearBreadcrumbs() { - FScopeLock Lock(&CriticalSection); - Breadcrumbs.Empty(); } @@ -91,26 +75,6 @@ TMap FGenericPlatformSentryScope::GetTags() const return Tags; } -void FGenericPlatformSentryScope::SetDist(const FString& dist) -{ - Dist = dist; -} - -FString FGenericPlatformSentryScope::GetDist() const -{ - return Dist; -} - -void FGenericPlatformSentryScope::SetEnvironment(const FString& environment) -{ - Environment = environment; -} - -FString FGenericPlatformSentryScope::GetEnvironment() const -{ - return Environment; -} - void FGenericPlatformSentryScope::SetFingerprint(const TArray& fingerprint) { Fingerprint = fingerprint; @@ -128,7 +92,6 @@ void FGenericPlatformSentryScope::SetLevel(ESentryLevel level) ESentryLevel FGenericPlatformSentryScope::GetLevel() const { - return Level; } @@ -188,114 +151,36 @@ void FGenericPlatformSentryScope::Clear() Level = ESentryLevel::Debug; } -void FGenericPlatformSentryScope::Apply(TSharedPtr event) +void FGenericPlatformSentryScope::Apply(sentry_scope_t* scope) { - sentry_value_t nativeEvent = event->GetNativeObject(); - sentry_value_t eventLevel = sentry_value_get_by_key(nativeEvent, "level"); - - FString scopeLevelStr = FGenericPlatformSentryConverters::SentryLevelToString(Level).ToLower(); - if (!scopeLevelStr.IsEmpty() && sentry_value_is_null(eventLevel)) + for (const auto& Breadcrumb : Breadcrumbs) { - sentry_value_set_by_key(nativeEvent, "level", sentry_value_new_string(TCHAR_TO_ANSI(*scopeLevelStr))); - } - - if (!Dist.IsEmpty()) - { - sentry_value_set_by_key(nativeEvent, "dist", sentry_value_new_string(TCHAR_TO_ANSI(*Dist))); - } - - if (!Environment.IsEmpty()) - { - sentry_value_set_by_key(nativeEvent, "environment", sentry_value_new_string(TCHAR_TO_ANSI(*Environment))); + sentry_value_t nativeBreadcrumb = Breadcrumb->GetNativeObject(); + sentry_scope_add_breadcrumb(scope, nativeBreadcrumb); } if (Fingerprint.Num() > 0) { - sentry_value_set_by_key(nativeEvent, "fingerprint", FGenericPlatformSentryConverters::StringArrayToNative(Fingerprint)); + sentry_scope_set_fingerprints(scope, FGenericPlatformSentryConverters::StringArrayToNative(Fingerprint)); } - if (Tags.Num() > 0) + for (const auto& TagItem : Tags) { - sentry_value_t tagsExtra = sentry_value_get_by_key(nativeEvent, "tags"); - if (sentry_value_is_null(tagsExtra)) - { - sentry_value_set_by_key(nativeEvent, "tags", FGenericPlatformSentryConverters::StringMapToNative(Tags)); - } - else - { - for (const auto& TagItem : Tags) - { - sentry_value_set_by_key(tagsExtra, TCHAR_TO_ANSI(*TagItem.Key), sentry_value_new_string(TCHAR_TO_ANSI(*TagItem.Value))); - } - } + sentry_scope_set_tag(scope, TCHAR_TO_UTF8(*TagItem.Key), TCHAR_TO_UTF8(*TagItem.Value)); } - if (Extra.Num() > 0) + for (const auto& ExtraItem : Extra) { - sentry_value_t eventExtra = sentry_value_get_by_key(nativeEvent, "extra"); - if (sentry_value_is_null(eventExtra)) - { - sentry_value_set_by_key(nativeEvent, "extra", FGenericPlatformSentryConverters::StringMapToNative(Extra)); - } - else - { - for (const auto& ExtraItem : Extra) - { - sentry_value_set_by_key(eventExtra, TCHAR_TO_ANSI(*ExtraItem.Key), sentry_value_new_string(TCHAR_TO_ANSI(*ExtraItem.Value))); - } - } + sentry_scope_set_extra(scope, TCHAR_TO_UTF8(*ExtraItem.Key), sentry_value_new_string(TCHAR_TO_UTF8(*ExtraItem.Value))); } - if (Contexts.Num() > 0) + for (const auto& ContextsItem : Contexts) { - sentry_value_t eventContexts = sentry_value_get_by_key(nativeEvent, "contexts"); - if (sentry_value_is_null(eventContexts)) - { - eventContexts = sentry_value_new_object(); - - for (const auto& ContextsItem : Contexts) - { - sentry_value_set_by_key(eventContexts, TCHAR_TO_ANSI(*ContextsItem.Key), FGenericPlatformSentryConverters::StringMapToNative(ContextsItem.Value)); - } - - sentry_value_set_by_key(nativeEvent, "contexts", eventContexts); - } - else - { - for (const auto& ContextsItem : Contexts) - { - sentry_value_set_by_key(eventContexts, TCHAR_TO_ANSI(*ContextsItem.Key), FGenericPlatformSentryConverters::StringMapToNative(ContextsItem.Value)); - } - } + sentry_scope_set_context(scope, TCHAR_TO_UTF8(*ContextsItem.Key), FGenericPlatformSentryConverters::StringMapToNative(ContextsItem.Value)); } - if (!Breadcrumbs.IsEmpty()) - { - sentry_value_t eventBreadcrumbs = sentry_value_get_by_key(nativeEvent, "breadcrumbs"); - if (sentry_value_is_null(eventBreadcrumbs)) - { - eventBreadcrumbs = sentry_value_new_list(); - - for (const auto& Breadcrumb : Breadcrumbs) - { - sentry_value_t nativeBreadcrumb = Breadcrumb->GetNativeObject(); - sentry_value_incref(nativeBreadcrumb); - sentry_value_append(eventBreadcrumbs, nativeBreadcrumb); - } - - sentry_value_set_by_key(nativeEvent, "breadcrumbs", eventBreadcrumbs); - } - else - { - for (const auto& Breadcrumb : Breadcrumbs) - { - sentry_value_t nativeBreadcrumb = Breadcrumb->GetNativeObject(); - sentry_value_incref(nativeBreadcrumb); - sentry_value_append(eventBreadcrumbs, nativeBreadcrumb); - } - } - } + sentry_scope_set_level(scope, FGenericPlatformSentryConverters::SentryLevelToNative(Level)); } #endif diff --git a/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentryScope.h b/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentryScope.h index cbe9f839..b55212ba 100644 --- a/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentryScope.h +++ b/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentryScope.h @@ -3,7 +3,7 @@ #pragma once #include "Containers/RingBuffer.h" -#include "HAL/CriticalSection.h" +#include "Convenience/GenericPlatformSentryInclude.h" #include "Interface/SentryScopeInterface.h" @@ -16,7 +16,6 @@ class FGenericPlatformSentryScope : public ISentryScope { public: FGenericPlatformSentryScope(); - FGenericPlatformSentryScope(const FGenericPlatformSentryScope& Scope); virtual ~FGenericPlatformSentryScope() override; virtual void AddBreadcrumb(TSharedPtr breadcrumb) override; @@ -28,10 +27,6 @@ class FGenericPlatformSentryScope : public ISentryScope virtual void RemoveTag(const FString& key) override; virtual void SetTags(const TMap& tags) override; virtual TMap GetTags() const override; - virtual void SetDist(const FString& dist) override; - virtual FString GetDist() const override; - virtual void SetEnvironment(const FString& environment) override; - virtual FString GetEnvironment() const override; virtual void SetFingerprint(const TArray& fingerprint) override; virtual TArray GetFingerprint() const override; virtual void SetLevel(ESentryLevel level) override; @@ -45,7 +40,7 @@ class FGenericPlatformSentryScope : public ISentryScope virtual TMap GetExtras() const override; virtual void Clear() override; - void Apply(TSharedPtr event); + void Apply(sentry_scope_t* scope); private: FString Dist; @@ -61,8 +56,6 @@ class FGenericPlatformSentryScope : public ISentryScope TRingBuffer> Breadcrumbs; ESentryLevel Level; - - FCriticalSection CriticalSection; }; typedef FGenericPlatformSentryScope FPlatformSentryScope; diff --git a/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentrySubsystem.cpp b/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentrySubsystem.cpp index 705bb0c5..90f0beb5 100644 --- a/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentrySubsystem.cpp +++ b/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentrySubsystem.cpp @@ -104,8 +104,6 @@ sentry_value_t FGenericPlatformSentrySubsystem::OnBeforeSend(sentry_value_t even TSharedPtr Event = MakeShareable(new FGenericPlatformSentryEvent(event)); - GetCurrentScope()->Apply(Event); - if (FUObjectThreadContext::Get().IsRoutingPostLoad) { UE_LOG(LogSentrySdk, Log, TEXT("Executing `beforeSend` handler is not allowed during object post-loading.")); @@ -175,12 +173,8 @@ sentry_value_t FGenericPlatformSentrySubsystem::OnCrash(const sentry_ucontext_t* IFileManager::Get().Copy(*GetGpuDumpBackupPath(), *SentryFileUtils::GetGpuDumpPath()); } - FGenericPlatformSentryCrashContext::Get()->Apply(GetCurrentScope()); - TSharedPtr Event = MakeShareable(new FGenericPlatformSentryEvent(event, true)); - GetCurrentScope()->Apply(Event); - if (FUObjectThreadContext::Get().IsRoutingPostLoad) { UE_LOG(LogSentrySdk, Log, TEXT("Executing `beforeSend` handler is not allowed when post-loading.")); @@ -227,8 +221,6 @@ void FGenericPlatformSentrySubsystem::InitWithSettings(const USentrySettings* se beforeSend = beforeSendHandler; beforeBreadcrumb = beforeBreadcrumbHandler; - scopeStack.Push(MakeShareable(new FGenericPlatformSentryScope())); - sentry_options_t* options = sentry_options_new(); if (settings->EnableAutoLogAttachment) @@ -292,6 +284,7 @@ void FGenericPlatformSentrySubsystem::InitWithSettings(const USentrySettings* se } #endif // WITH_EDITOR sentry_options_set_environment(options, TCHAR_TO_ANSI(*settings->Environment)); + sentry_options_set_dist(options, TCHAR_TO_ANSI(*settings->Dist)); sentry_options_set_logger(options, PrintVerboseLog, nullptr); sentry_options_set_debug(options, settings->Debug); sentry_options_set_auto_session_tracking(options, settings->EnableAutoSessionTracking); @@ -318,8 +311,6 @@ void FGenericPlatformSentrySubsystem::Close() isEnabled = false; sentry_close(); - - scopeStack.Empty(); } bool FGenericPlatformSentrySubsystem::IsEnabled() @@ -353,14 +344,14 @@ void FGenericPlatformSentrySubsystem::AddBreadcrumb(TSharedPtr(breadcrumb)->GetNativeObject(), nullptr, this); - if (sentry_value_is_null(processdBreadcrumb)) + sentry_value_t processedBreadcrumb = HandleBeforeBreadcrumb(StaticCastSharedPtr(breadcrumb)->GetNativeObject(), nullptr, this); + if (sentry_value_is_null(processedBreadcrumb)) { return; } } - GetCurrentScope()->AddBreadcrumb(breadcrumb); + sentry_add_breadcrumb(StaticCastSharedPtr(breadcrumb)->GetNativeObject()); } void FGenericPlatformSentrySubsystem::AddBreadcrumbWithParams(const FString& Message, const FString& Category, const FString& Type, const TMap& Data, ESentryLevel Level) @@ -381,40 +372,45 @@ void FGenericPlatformSentrySubsystem::AddBreadcrumbWithParams(const FString& Mes } } - GetCurrentScope()->AddBreadcrumb(Breadcrumb); + sentry_add_breadcrumb(StaticCastSharedPtr(Breadcrumb)->GetNativeObject()); } void FGenericPlatformSentrySubsystem::ClearBreadcrumbs() { - GetCurrentScope()->ClearBreadcrumbs(); + // Not implemented in sentry-native } TSharedPtr FGenericPlatformSentrySubsystem::CaptureMessage(const FString& message, ESentryLevel level) { - sentry_value_t sentryEvent = sentry_value_new_message_event(FGenericPlatformSentryConverters::SentryLevelToNative(level), nullptr, TCHAR_TO_UTF8(*message)); + sentry_value_t nativeEvent = sentry_value_new_message_event(FGenericPlatformSentryConverters::SentryLevelToNative(level), nullptr, TCHAR_TO_UTF8(*message)); if (isStackTraceEnabled) { - sentry_value_set_stacktrace(sentryEvent, nullptr, 0); + sentry_value_set_stacktrace(nativeEvent, nullptr, 0); } - sentry_uuid_t id = sentry_capture_event(sentryEvent); + sentry_uuid_t id = sentry_capture_event(nativeEvent); return MakeShareable(new FGenericPlatformSentryId(id)); } TSharedPtr FGenericPlatformSentrySubsystem::CaptureMessageWithScope(const FString& message, ESentryLevel level, const FSentryScopeDelegate& onConfigureScope) { - FScopeLock Lock(&CriticalSection); + sentry_value_t nativeEvent = sentry_value_new_message_event(FGenericPlatformSentryConverters::SentryLevelToNative(level), nullptr, TCHAR_TO_UTF8(*message)); - TSharedPtr NewLocalScope = MakeShareable(new FGenericPlatformSentryScope(*GetCurrentScope())); + if (isStackTraceEnabled) + { + sentry_value_set_stacktrace(nativeEvent, nullptr, 0); + } + sentry_scope_t* scope = sentry_local_scope_new(); + + TSharedPtr NewLocalScope = MakeShareable(new FGenericPlatformSentryScope()); onConfigureScope.ExecuteIfBound(NewLocalScope); + NewLocalScope->Apply(scope); - scopeStack.Push(NewLocalScope); - TSharedPtr Id = CaptureMessage(message, level); - scopeStack.Pop(); + sentry_uuid_t id = sentry_capture_event_with_scope(nativeEvent, scope); - return Id; + return MakeShareable(new FGenericPlatformSentryId(id)); } TSharedPtr FGenericPlatformSentrySubsystem::CaptureEvent(TSharedPtr event) @@ -434,17 +430,24 @@ TSharedPtr FGenericPlatformSentrySubsystem::CaptureEvent(TSharedPtr FGenericPlatformSentrySubsystem::CaptureEventWithScope(TSharedPtr event, const FSentryScopeDelegate& onScopeConfigure) { - FScopeLock Lock(&CriticalSection); + TSharedPtr Event = StaticCastSharedPtr(event); + + sentry_value_t nativeEvent = Event->GetNativeObject(); + + if (isStackTraceEnabled) + { + sentry_value_set_stacktrace(nativeEvent, nullptr, 0); + } - TSharedPtr NewLocalScope = MakeShareable(new FGenericPlatformSentryScope(*GetCurrentScope())); + sentry_scope_t* scope = sentry_local_scope_new(); + TSharedPtr NewLocalScope = MakeShareable(new FGenericPlatformSentryScope()); onScopeConfigure.ExecuteIfBound(NewLocalScope); + NewLocalScope->Apply(scope); - scopeStack.Push(NewLocalScope); - TSharedPtr Id = CaptureEvent(event); - scopeStack.Pop(); + sentry_uuid_t id = sentry_capture_event_with_scope(nativeEvent, scope); - return Id; + return MakeShareable(new FGenericPlatformSentryId(id)); } TSharedPtr FGenericPlatformSentrySubsystem::CaptureEnsure(const FString& type, const FString& message) @@ -495,14 +498,9 @@ void FGenericPlatformSentrySubsystem::RemoveUser() } } -void FGenericPlatformSentrySubsystem::ConfigureScope(const FSentryScopeDelegate& onConfigureScope) -{ - onConfigureScope.ExecuteIfBound(GetCurrentScope()); -} - void FGenericPlatformSentrySubsystem::SetContext(const FString& key, const TMap& values) { - GetCurrentScope()->SetContext(key, values); + sentry_set_context(TCHAR_TO_UTF8(*key), FGenericPlatformSentryConverters::StringMapToNative(values)); if (crashReporter) { @@ -512,7 +510,7 @@ void FGenericPlatformSentrySubsystem::SetContext(const FString& key, const TMap< void FGenericPlatformSentrySubsystem::SetTag(const FString& key, const FString& value) { - GetCurrentScope()->SetTagValue(key, value); + sentry_set_tag(TCHAR_TO_UTF8(*key), TCHAR_TO_UTF8(*value)); if (crashReporter) { @@ -522,7 +520,7 @@ void FGenericPlatformSentrySubsystem::SetTag(const FString& key, const FString& void FGenericPlatformSentrySubsystem::RemoveTag(const FString& key) { - GetCurrentScope()->RemoveTag(key); + sentry_remove_tag(TCHAR_TO_UTF8(*key)); if (crashReporter) { @@ -532,7 +530,7 @@ void FGenericPlatformSentrySubsystem::RemoveTag(const FString& key) void FGenericPlatformSentrySubsystem::SetLevel(ESentryLevel level) { - GetCurrentScope()->SetLevel(level); + sentry_set_level(FGenericPlatformSentryConverters::SentryLevelToNative(level)); } void FGenericPlatformSentrySubsystem::StartSession() @@ -626,17 +624,6 @@ FString FGenericPlatformSentrySubsystem::GetGpuDumpBackupPath() const return GpuDumpFullPath; } -TSharedPtr FGenericPlatformSentrySubsystem::GetCurrentScope() -{ - if (scopeStack.Num() == 0) - { - UE_LOG(LogSentrySdk, Warning, TEXT("Scope stack is empty.")); - return nullptr; - } - - return scopeStack.Top(); -} - FString FGenericPlatformSentrySubsystem::GetHandlerPath() const { const FString HandlerPath = FPaths::Combine(FSentryModule::Get().GetBinariesPath(), GetHandlerExecutableName()); diff --git a/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentrySubsystem.h b/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentrySubsystem.h index 5ba1c4a4..768bb024 100644 --- a/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentrySubsystem.h +++ b/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentrySubsystem.h @@ -33,7 +33,6 @@ class FGenericPlatformSentrySubsystem : public ISentrySubsystem virtual void CaptureUserFeedback(TSharedPtr userFeedback) override; virtual void SetUser(TSharedPtr user) override; virtual void RemoveUser() override; - virtual void ConfigureScope(const FSentryScopeDelegate& onConfigureScope) override; virtual void SetContext(const FString& key, const TMap& values) override; virtual void SetTag(const FString& key, const FString& value) override; virtual void RemoveTag(const FString& key) override; @@ -53,8 +52,6 @@ class FGenericPlatformSentrySubsystem : public ISentrySubsystem FString GetGpuDumpBackupPath() const; - TSharedPtr GetCurrentScope(); - protected: virtual void ConfigureHandlerPath(sentry_options_t* Options) {} virtual void ConfigureDatabasePath(sentry_options_t* Options) {} @@ -87,16 +84,12 @@ class FGenericPlatformSentrySubsystem : public ISentrySubsystem TSharedPtr crashReporter; - TArray> scopeStack; - bool isEnabled; bool isStackTraceEnabled; bool isPiiAttachmentEnabled; bool isScreenshotAttachmentEnabled; - FCriticalSection CriticalSection; - FString databaseParentPath; }; diff --git a/plugin-dev/Source/Sentry/Private/Interface/SentryScopeInterface.h b/plugin-dev/Source/Sentry/Private/Interface/SentryScopeInterface.h index 72a07fa3..37cd56f6 100644 --- a/plugin-dev/Source/Sentry/Private/Interface/SentryScopeInterface.h +++ b/plugin-dev/Source/Sentry/Private/Interface/SentryScopeInterface.h @@ -23,10 +23,6 @@ class ISentryScope virtual void RemoveTag(const FString& key) = 0; virtual void SetTags(const TMap& tags) = 0; virtual TMap GetTags() const = 0; - virtual void SetDist(const FString& dist) = 0; - virtual FString GetDist() const = 0; - virtual void SetEnvironment(const FString& environment) = 0; - virtual FString GetEnvironment() const = 0; virtual void SetFingerprint(const TArray& fingerprint) = 0; virtual TArray GetFingerprint() const = 0; virtual void SetLevel(ESentryLevel level) = 0; diff --git a/plugin-dev/Source/Sentry/Private/Interface/SentrySubsystemInterface.h b/plugin-dev/Source/Sentry/Private/Interface/SentrySubsystemInterface.h index 9d8f27e5..9867dba6 100644 --- a/plugin-dev/Source/Sentry/Private/Interface/SentrySubsystemInterface.h +++ b/plugin-dev/Source/Sentry/Private/Interface/SentrySubsystemInterface.h @@ -42,7 +42,6 @@ class ISentrySubsystem virtual void CaptureUserFeedback(TSharedPtr userFeedback) = 0; virtual void SetUser(TSharedPtr user) = 0; virtual void RemoveUser() = 0; - virtual void ConfigureScope(const FSentryScopeDelegate& onConfigureScope) = 0; virtual void SetContext(const FString& key, const TMap& values) = 0; virtual void SetTag(const FString& key, const FString& value) = 0; virtual void RemoveTag(const FString& key) = 0; diff --git a/plugin-dev/Source/Sentry/Private/Null/NullSentryScope.h b/plugin-dev/Source/Sentry/Private/Null/NullSentryScope.h index 6e87f737..2dd12bc7 100644 --- a/plugin-dev/Source/Sentry/Private/Null/NullSentryScope.h +++ b/plugin-dev/Source/Sentry/Private/Null/NullSentryScope.h @@ -18,10 +18,6 @@ class FNullSentryScope final : public ISentryScope virtual void RemoveTag(const FString& key) override {} virtual void SetTags(const TMap& tags) override {} virtual TMap GetTags() const override { return {}; } - virtual void SetDist(const FString& dist) override {} - virtual FString GetDist() const override { return TEXT(""); } - virtual void SetEnvironment(const FString& environment) override {} - virtual FString GetEnvironment() const override { return TEXT(""); } virtual void SetFingerprint(const TArray& fingerprint) override {} virtual TArray GetFingerprint() const override { return {}; } virtual void SetLevel(ESentryLevel level) override {} diff --git a/plugin-dev/Source/Sentry/Private/SentryScope.cpp b/plugin-dev/Source/Sentry/Private/SentryScope.cpp index d09f578d..a005e14a 100644 --- a/plugin-dev/Source/Sentry/Private/SentryScope.cpp +++ b/plugin-dev/Source/Sentry/Private/SentryScope.cpp @@ -83,38 +83,6 @@ TMap USentryScope::GetTags() const return NativeImpl->GetTags(); } -void USentryScope::SetDist(const FString& Dist) -{ - if (!NativeImpl) - return; - - NativeImpl->SetDist(Dist); -} - -FString USentryScope::GetDist() const -{ - if (!NativeImpl) - return FString(); - - return NativeImpl->GetDist(); -} - -void USentryScope::SetEnvironment(const FString& Environment) -{ - if (!NativeImpl) - return; - - NativeImpl->SetEnvironment(Environment); -} - -FString USentryScope::GetEnvironment() const -{ - if (!NativeImpl) - return FString(); - - return NativeImpl->GetEnvironment(); -} - void USentryScope::SetFingerprint(const TArray& Fingerprint) { if (!NativeImpl) diff --git a/plugin-dev/Source/Sentry/Private/SentrySubsystem.cpp b/plugin-dev/Source/Sentry/Private/SentrySubsystem.cpp index 3b4675e2..49026f3d 100644 --- a/plugin-dev/Source/Sentry/Private/SentrySubsystem.cpp +++ b/plugin-dev/Source/Sentry/Private/SentrySubsystem.cpp @@ -146,6 +146,11 @@ void USentrySubsystem::Initialize() } void USentrySubsystem::InitializeWithSettings(const FConfigureSettingsDelegate& OnConfigureSettings) +{ + return InitializeWithSettings(FConfigureSettingsNativeDelegate::CreateUFunction(const_cast(OnConfigureSettings.GetUObject()), OnConfigureSettings.GetFunctionName())); +} + +void USentrySubsystem::InitializeWithSettings(const FConfigureSettingsNativeDelegate& OnConfigureSettings) { USentrySettings* Settings = FSentryModule::Get().GetSettings(); check(Settings); @@ -370,27 +375,6 @@ void USentrySubsystem::RemoveUser() SubsystemNativeImpl->RemoveUser(); } -void USentrySubsystem::ConfigureScope(const FConfigureScopeDelegate& OnConfigureScope) -{ - ConfigureScope(FConfigureScopeNativeDelegate::CreateUFunction(const_cast(OnConfigureScope.GetUObject()), OnConfigureScope.GetFunctionName())); -} - -void USentrySubsystem::ConfigureScope(const FConfigureScopeNativeDelegate& OnConfigureScope) -{ - check(SubsystemNativeImpl); - - if (!SubsystemNativeImpl || !SubsystemNativeImpl->IsEnabled()) - { - return; - } - - SubsystemNativeImpl->ConfigureScope(FSentryScopeDelegate::CreateLambda([OnConfigureScope](TSharedPtr NativeScope) - { - USentryScope* UnrealScope = USentryScope::Create(NativeScope); - OnConfigureScope.ExecuteIfBound(UnrealScope); - })); -} - void USentrySubsystem::SetContext(const FString& Key, const TMap& Values) { check(SubsystemNativeImpl); diff --git a/plugin-dev/Source/Sentry/Private/Tests/SentryScope.spec.cpp b/plugin-dev/Source/Sentry/Private/Tests/SentryScope.spec.cpp index 05111470..a0921fd0 100644 --- a/plugin-dev/Source/Sentry/Private/Tests/SentryScope.spec.cpp +++ b/plugin-dev/Source/Sentry/Private/Tests/SentryScope.spec.cpp @@ -2,12 +2,13 @@ #include "SentryScope.h" #include "SentryEvent.h" +#include "SentryScopeBeforeSendHandler.h" #include "SentryTests.h" +#include "Engine/Engine.h" #include "SentryDataTypes.h" - -#include "Interface/SentryEventInterface.h" -#include "Interface/SentryScopeInterface.h" +#include "SentrySettings.h" +#include "SentrySubsystem.h" #include "Misc/AutomationTest.h" @@ -16,6 +17,8 @@ #include "GenericPlatform/Infrastructure/GenericPlatformSentryConverters.h" +TDelegate UScopeTestBeforeSendHandler::OnScopeTestBeforeSendHandler; + #if WITH_AUTOMATION_TESTS BEGIN_DEFINE_SPEC(SentryScopeSpec, "Sentry.SentryScope", EAutomationTestFlags::ProductFilter | SentryApplicationContextMask) @@ -34,9 +37,6 @@ void SentryScopeSpec::Define() { SentryScope = USentryScope::Create(CreateSharedSentryScope()); - TestDist = TEXT("dist_str"); - TestEnvironment = TEXT("env_str"); - TestTags.Add(TEXT("TagsKey1"), TEXT("TagsVal1")); TestTags.Add(TEXT("TagsKey2"), TEXT("TagsVal2")); @@ -112,13 +112,9 @@ void SentryScopeSpec::Define() It("should persist their values", [this]() { SentryScope->SetLevel(ESentryLevel::Fatal); - SentryScope->SetDist(TestDist); - SentryScope->SetEnvironment(TestEnvironment); SentryScope->SetFingerprint(TestFingerprint); TestEqual("Scope level", SentryScope->GetLevel(), ESentryLevel::Fatal); - TestEqual("Scope dist", SentryScope->GetDist(), TestDist); - TestEqual("Scope environment", SentryScope->GetEnvironment(), TestEnvironment); TestEqual("Scope fingerprint", SentryScope->GetFingerprint(), TestFingerprint); }); }); @@ -127,63 +123,66 @@ void SentryScopeSpec::Define() { It("should be possible to clear", [this]() { - SentryScope->SetDist(TestDist); - SentryScope->SetEnvironment(TestEnvironment); SentryScope->SetFingerprint(TestFingerprint); SentryScope->SetTags(TestTags); SentryScope->SetExtras(TestExtras); SentryScope->Clear(); - TestTrue("Scope dist", SentryScope->GetDist().IsEmpty()); - TestTrue("Scope environment", SentryScope->GetEnvironment().IsEmpty()); TestTrue("Scope fingerprint", SentryScope->GetFingerprint().Num() == 0); TestTrue("Scope tags", SentryScope->GetTags().Num() == 0); TestTrue("Scope extras", SentryScope->GetExtras().Num() == 0); }); }); -#if (PLATFORM_WINDOWS || PLATFORM_LINUX) && USE_SENTRY_NATIVE +#if (PLATFORM_MICROSOFT || PLATFORM_LINUX) && USE_SENTRY_NATIVE Describe("Scope params", [this]() { It("should be applied to event", [this]() { - SentryScope->SetLevel(ESentryLevel::Fatal); - SentryScope->SetDist(TestDist); - SentryScope->SetEnvironment(TestEnvironment); - SentryScope->SetFingerprint(TestFingerprint); - SentryScope->SetTags(TestTags); - SentryScope->SetExtras(TestExtras); - SentryScope->SetContext(TEXT("TestContext"), TestContext); + USentrySubsystem* SentrySubsystem = GEngine->GetEngineSubsystem(); + SentrySubsystem->InitializeWithSettings(FConfigureSettingsNativeDelegate::CreateLambda([=](USentrySettings* Settings) + { + Settings->BeforeSendHandler = UScopeTestBeforeSendHandler::StaticClass(); + })); + + UScopeTestBeforeSendHandler::OnScopeTestBeforeSendHandler.BindLambda([this](USentryEvent* SentryEvent) + { + TSharedPtr Event = StaticCastSharedPtr(SentryEvent->GetNativeObject()); + + sentry_value_t NativeEvent = Event->GetNativeObject(); + + sentry_value_t level = sentry_value_get_by_key(NativeEvent, "level"); + sentry_value_t fingerprint = sentry_value_get_by_key(NativeEvent, "fingerprint"); + sentry_value_t tags = sentry_value_get_by_key(NativeEvent, "tags"); + sentry_value_t extra = sentry_value_get_by_key(NativeEvent, "extra"); + sentry_value_t contexts = sentry_value_get_by_key(NativeEvent, "contexts"); + + sentry_value_t testContext = sentry_value_get_by_key(contexts, "TestContext"); + + TestEqual("Event level", FGenericPlatformSentryConverters::SentryLevelToUnreal(level), ESentryLevel::Fatal); + TestEqual("Event fingerprint", FGenericPlatformSentryConverters::StringArrayToUnreal(fingerprint), TestFingerprint); + TestEqual("Event tags 1", FGenericPlatformSentryConverters::StringMapToUnreal(tags)[TEXT("TagsKey1")], TestTags[TEXT("TagsKey1")]); + TestEqual("Event tags 2", FGenericPlatformSentryConverters::StringMapToUnreal(tags)[TEXT("TagsKey2")], TestTags[TEXT("TagsKey2")]); + TestEqual("Event extra 1", FGenericPlatformSentryConverters::StringMapToUnreal(extra)[TEXT("ExtrasKey1")], TestExtras[TEXT("ExtrasKey1")]); + TestEqual("Event extra 2", FGenericPlatformSentryConverters::StringMapToUnreal(extra)[TEXT("ExtrasKey2")], TestExtras[TEXT("ExtrasKey2")]); + TestEqual("Event context 1", FGenericPlatformSentryConverters::StringMapToUnreal(testContext)[TEXT("ContextKey1")], TestContext[TEXT("ContextKey1")]); + TestEqual("Event context 2", FGenericPlatformSentryConverters::StringMapToUnreal(testContext)[TEXT("ContextKey2")], TestContext[TEXT("ContextKey2")]); + }); USentryEvent* SentryEvent = USentryEvent::Create(CreateSharedSentryEvent()); - - TSharedPtr Event = StaticCastSharedPtr(SentryEvent->GetNativeObject()); - - StaticCastSharedPtr(SentryScope->GetNativeObject())->Apply(Event); - - sentry_value_t NativeEvent = Event->GetNativeObject(); - - sentry_value_t level = sentry_value_get_by_key(NativeEvent, "level"); - sentry_value_t dist = sentry_value_get_by_key(NativeEvent, "dist"); - sentry_value_t environment = sentry_value_get_by_key(NativeEvent, "environment"); - sentry_value_t fingerprint = sentry_value_get_by_key(NativeEvent, "fingerprint"); - sentry_value_t tags = sentry_value_get_by_key(NativeEvent, "tags"); - sentry_value_t extra = sentry_value_get_by_key(NativeEvent, "extra"); - - sentry_value_t contexts = sentry_value_get_by_key(NativeEvent, "contexts"); - sentry_value_t testContext = sentry_value_get_by_key(contexts, "TestContext"); - - TestEqual("Event level", FGenericPlatformSentryConverters::SentryLevelToUnreal(level), ESentryLevel::Fatal); - TestEqual("Event dist", FString(sentry_value_as_string(dist)), TestDist); - TestEqual("Event environment", FString(sentry_value_as_string(environment)), TestEnvironment); - TestEqual("Event fingerprint", FGenericPlatformSentryConverters::StringArrayToUnreal(fingerprint), TestFingerprint); - TestEqual("Event tags 1", FGenericPlatformSentryConverters::StringMapToUnreal(tags)[TEXT("TagsKey1")], TestTags[TEXT("TagsKey1")]); - TestEqual("Event tags 2", FGenericPlatformSentryConverters::StringMapToUnreal(tags)[TEXT("TagsKey2")], TestTags[TEXT("TagsKey2")]); - TestEqual("Event extra 1", FGenericPlatformSentryConverters::StringMapToUnreal(extra)[TEXT("ExtrasKey1")], TestExtras[TEXT("ExtrasKey1")]); - TestEqual("Event extra 2", FGenericPlatformSentryConverters::StringMapToUnreal(extra)[TEXT("ExtrasKey2")], TestExtras[TEXT("ExtrasKey2")]); - TestEqual("Event context 1", FGenericPlatformSentryConverters::StringMapToUnreal(testContext)[TEXT("ContextKey1")], TestContext[TEXT("ContextKey1")]); - TestEqual("Event context 2", FGenericPlatformSentryConverters::StringMapToUnreal(testContext)[TEXT("ContextKey2")], TestContext[TEXT("ContextKey2")]); + SentrySubsystem->CaptureEventWithScope(SentryEvent, FConfigureScopeNativeDelegate::CreateLambda([this](USentryScope* Scope) + { + Scope->SetLevel(ESentryLevel::Fatal); + Scope->SetFingerprint(TestFingerprint); + Scope->SetTags(TestTags); + Scope->SetExtras(TestExtras); + Scope->SetContext(TEXT("TestContext"), TestContext); + })); + + UScopeTestBeforeSendHandler::OnScopeTestBeforeSendHandler.Unbind(); + + SentrySubsystem->Close(); }); }); #endif diff --git a/plugin-dev/Source/Sentry/Private/Tests/SentryScopeBeforeSendHandler.h b/plugin-dev/Source/Sentry/Private/Tests/SentryScopeBeforeSendHandler.h new file mode 100644 index 00000000..9b19ab27 --- /dev/null +++ b/plugin-dev/Source/Sentry/Private/Tests/SentryScopeBeforeSendHandler.h @@ -0,0 +1,23 @@ +// Copyright (c) 2025 Sentry. All Rights Reserved. + +#pragma once + +#include "SentryBeforeSendHandler.h" +#include "SentryEvent.h" +#include "SentryHint.h" + +#include "SentryScopeBeforeSendHandler.generated.h" + +UCLASS() +class UScopeTestBeforeSendHandler : public USentryBeforeSendHandler +{ + GENERATED_BODY() +public: + virtual USentryEvent* HandleBeforeSend_Implementation(USentryEvent* SentryEvent, USentryHint* Hint) override + { + OnScopeTestBeforeSendHandler.ExecuteIfBound(SentryEvent); + return Super::HandleBeforeSend_Implementation(SentryEvent, Hint); + } + + static TDelegate OnScopeTestBeforeSendHandler; +}; diff --git a/plugin-dev/Source/Sentry/Public/SentryScope.h b/plugin-dev/Source/Sentry/Public/SentryScope.h index 0ca0dba9..f94ce0a5 100644 --- a/plugin-dev/Source/Sentry/Public/SentryScope.h +++ b/plugin-dev/Source/Sentry/Public/SentryScope.h @@ -60,22 +60,6 @@ class SENTRY_API USentryScope : public UObject, public TSentryImplWrapper GetTags() const; - /** Sets dist in the scope. */ - UFUNCTION(BlueprintCallable, Category = "Sentry") - void SetDist(const FString& Dist); - - /** Gets dist in the scope. */ - UFUNCTION(BlueprintPure, Category = "Sentry") - FString GetDist() const; - - /** Sets environment in the scope. */ - UFUNCTION(BlueprintCallable, Category = "Sentry") - void SetEnvironment(const FString& Environment); - - /** Gets environment in the scope. */ - UFUNCTION(BlueprintCallable, Category = "Sentry") - FString GetEnvironment() const; - /** Sets fingerprint in the scope. */ UFUNCTION(BlueprintCallable, Category = "Sentry") void SetFingerprint(const TArray& Fingerprint); diff --git a/plugin-dev/Source/Sentry/Public/SentrySettings.h b/plugin-dev/Source/Sentry/Public/SentrySettings.h index 9cf78e4a..9f5596e0 100644 --- a/plugin-dev/Source/Sentry/Public/SentrySettings.h +++ b/plugin-dev/Source/Sentry/Public/SentrySettings.h @@ -201,6 +201,10 @@ class SENTRY_API USentrySettings : public UObject Meta = (DisplayName = "Environment", ToolTip = "Environment which will be used for enriching events.")) FString Environment; + UPROPERTY(Config, EditAnywhere, BlueprintReadWrite, Category = "General", + Meta = (DisplayName = "Distribution", ToolTip = "Distribution which will be used for enriching events.")) + FString Dist; + UPROPERTY(Config, EditAnywhere, Category = "General", 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; diff --git a/plugin-dev/Source/Sentry/Public/SentrySubsystem.h b/plugin-dev/Source/Sentry/Public/SentrySubsystem.h index 341f6aaa..8ae5d06d 100644 --- a/plugin-dev/Source/Sentry/Public/SentrySubsystem.h +++ b/plugin-dev/Source/Sentry/Public/SentrySubsystem.h @@ -25,6 +25,7 @@ class ISentrySubsystem; class FSentryOutputDevice; class FSentryErrorOutputDevice; +DECLARE_DELEGATE_OneParam(FConfigureSettingsNativeDelegate, USentrySettings*); DECLARE_DYNAMIC_DELEGATE_OneParam(FConfigureSettingsDelegate, USentrySettings*, Settings); /** @@ -48,6 +49,7 @@ class SENTRY_API USentrySubsystem : public UEngineSubsystem */ UFUNCTION(BlueprintCallable, Category = "Sentry") void InitializeWithSettings(const FConfigureSettingsDelegate& OnConfigureSettings); + void InitializeWithSettings(const FConfigureSettingsNativeDelegate& OnConfigureSettings); /** Closes the Sentry SDK. */ UFUNCTION(BlueprintCallable, Category = "Sentry") @@ -180,18 +182,6 @@ class SENTRY_API USentrySubsystem : public UEngineSubsystem UFUNCTION(BlueprintCallable, Category = "Sentry") void RemoveUser(); - /** - * Configures the scope through the callback. - * Sentry SDK uses the Scope to attach contextual data to events. - * - * @param OnConfigureScope The callback to configure the scope. - * - * @note: Not supported for Windows/Linux. - */ - UFUNCTION(BlueprintCallable, Category = "Sentry", meta = (AutoCreateRefTerm = "OnCofigureScope")) - void ConfigureScope(const FConfigureScopeDelegate& OnConfigureScope); - void ConfigureScope(const FConfigureScopeNativeDelegate& OnConfigureScope); - /** * Sets context values which will be used for enriching events. * diff --git a/sample/Content/UI/W_SentryDemo.uasset b/sample/Content/UI/W_SentryDemo.uasset index 2cef48ab..163e7eb6 100644 Binary files a/sample/Content/UI/W_SentryDemo.uasset and b/sample/Content/UI/W_SentryDemo.uasset differ diff --git a/scripts/packaging/package-github.snapshot b/scripts/packaging/package-github.snapshot index 5a7b3f39..1cf02ee6 100644 --- a/scripts/packaging/package-github.snapshot +++ b/scripts/packaging/package-github.snapshot @@ -175,6 +175,7 @@ Source/Sentry/Private/SentryUserFeedback.cpp Source/Sentry/Private/Tests/SentryBreadcrumb.spec.cpp Source/Sentry/Private/Tests/SentryEvent.spec.cpp Source/Sentry/Private/Tests/SentryScope.spec.cpp +Source/Sentry/Private/Tests/SentryScopeBeforeSendHandler.h Source/Sentry/Private/Tests/SentrySubsystem.spec.cpp Source/Sentry/Private/Tests/SentryTests.h Source/Sentry/Private/Tests/SentryUser.spec.cpp diff --git a/scripts/packaging/package-marketplace.snapshot b/scripts/packaging/package-marketplace.snapshot index a58beca4..904ac620 100644 --- a/scripts/packaging/package-marketplace.snapshot +++ b/scripts/packaging/package-marketplace.snapshot @@ -174,6 +174,7 @@ Source/Sentry/Private/SentryUserFeedback.cpp Source/Sentry/Private/Tests/SentryBreadcrumb.spec.cpp Source/Sentry/Private/Tests/SentryEvent.spec.cpp Source/Sentry/Private/Tests/SentryScope.spec.cpp +Source/Sentry/Private/Tests/SentryScopeBeforeSendHandler.h Source/Sentry/Private/Tests/SentrySubsystem.spec.cpp Source/Sentry/Private/Tests/SentryTests.h Source/Sentry/Private/Tests/SentryUser.spec.cpp