From fd0a3ede7cb5f50d833a30972fd1a578d28365b0 Mon Sep 17 00:00:00 2001 From: Nathan White Date: Thu, 8 May 2025 12:07:58 -0700 Subject: [PATCH 1/3] Add destination URL for crash envelope --- .../GenericPlatformSentrySubsystem.cpp | 46 ++++++++++++++++--- .../GenericPlatformSentrySubsystem.h | 5 ++ 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentrySubsystem.cpp b/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentrySubsystem.cpp index 737d26d2c..0e4a811c3 100644 --- a/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentrySubsystem.cpp +++ b/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentrySubsystem.cpp @@ -198,10 +198,25 @@ sentry_value_t FGenericPlatformSentrySubsystem::OnCrash(const sentry_ucontext_t* USentryEvent* EventToProcess = USentryEvent::Create(Event); - USentryEvent* ProcessedEvent = GetBeforeSendHandler()->HandleBeforeSend(EventToProcess, nullptr); + if (USentryEvent* ProcessedEvent = GetBeforeSendHandler()->HandleBeforeSend(EventToProcess, nullptr)) + { + if (SentryEventUrl.EndsWith(TEXT("="))) + { + sentry_value_t EventId = sentry_value_get_by_key(event, "event_id"); + const char* EventIdString = sentry_value_as_string(EventId); - return ProcessedEvent ? event : sentry_value_new_null(); + // AppendChars takes into consideration slack space in order to avoid growing the array + SentryEventUrl.AppendChars(EventIdString, FCStringAnsi::Strlen(EventIdString)); + } + + UE_LOG(LogSentrySdk, Error, TEXT("%s"), *SentryEventUrl); + return event; + } + else + { + return sentry_value_new_null(); + } } void FGenericPlatformSentrySubsystem::InitCrashReporter(const FString& release, const FString& environment) @@ -287,13 +302,30 @@ void FGenericPlatformSentrySubsystem::InitWithSettings(const USentrySettings* se ? *settings->Release : *settings->GetFormattedReleaseName())); - sentry_options_set_dsn(options, TCHAR_TO_ANSI(*settings->Dsn)); + const FString& Dsn = #if WITH_EDITOR - if (!settings->EditorDsn.IsEmpty()) - { - sentry_options_set_dsn(options, TCHAR_TO_ANSI(*settings->EditorDsn)); - } + !settings->EditorDsn.IsEmpty() ? settings->EditorDsn : #endif // WITH_EDITOR + settings->Dsn; + + FString Ignored; + FString ProjectId; + + // Grab the project ID at the end of the DSN - after the last forward-slash + Dsn.Split(TEXT("/"), &Ignored, &ProjectId, ESearchCase::IgnoreCase, ESearchDir::FromEnd); + + // Allocate large enough buffer to hold the URL base plus event ID to avoid memory allocations + // during crash handling + constexpr int32 SentryEventUrlSlack = 64; + SentryEventUrl = FString::ConstructWithSlack( + *FString::Printf( + TEXT("http://sentry.io/organizations/riotgames/issues/?project=%s&statsPeriod=1h&query="), + *ProjectId + ), + SentryEventUrlSlack + ); + + sentry_options_set_dsn(options, TCHAR_TO_ANSI(*Dsn)); sentry_options_set_environment(options, TCHAR_TO_ANSI(*settings->Environment)); sentry_options_set_logger(options, PrintVerboseLog, nullptr); sentry_options_set_debug(options, settings->Debug); diff --git a/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentrySubsystem.h b/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentrySubsystem.h index 57a312dfd..64e027879 100644 --- a/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentrySubsystem.h +++ b/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentrySubsystem.h @@ -98,6 +98,11 @@ class FGenericPlatformSentrySubsystem : public ISentrySubsystem FCriticalSection CriticalSection; FString databaseParentPath; + + /** + * The expected destination URL of the crash envelope. + */ + FString EventDestinationUrl; }; #endif From c1ed967adce42f5e6f7f09b9335a329e0fd102e2 Mon Sep 17 00:00:00 2001 From: Nathan White Date: Thu, 8 May 2025 12:10:37 -0700 Subject: [PATCH 2/3] Update CHANGELOG --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index b3024de85..a5e4030b8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- Add destination URL for crash envelope ([#905](https://github.com/getsentry/sentry-unreal/pull/905)) + ### Fixes - Windows default crash handling mechanism is no longer disabled if SDK initialization failed ([#901](https://github.com/getsentry/sentry-unreal/pull/901)) From 5c525c92e9c176844b36f5990bd20f396b42972f Mon Sep 17 00:00:00 2001 From: Nathan White Date: Thu, 8 May 2025 12:55:41 -0700 Subject: [PATCH 3/3] Fix names and handle engine version differences --- .../GenericPlatformSentrySubsystem.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentrySubsystem.cpp b/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentrySubsystem.cpp index 0e4a811c3..346333a2b 100644 --- a/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentrySubsystem.cpp +++ b/plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentrySubsystem.cpp @@ -200,16 +200,16 @@ sentry_value_t FGenericPlatformSentrySubsystem::OnCrash(const sentry_ucontext_t* if (USentryEvent* ProcessedEvent = GetBeforeSendHandler()->HandleBeforeSend(EventToProcess, nullptr)) { - if (SentryEventUrl.EndsWith(TEXT("="))) + if (EventDestinationUrl.EndsWith(TEXT("="))) { sentry_value_t EventId = sentry_value_get_by_key(event, "event_id"); const char* EventIdString = sentry_value_as_string(EventId); // AppendChars takes into consideration slack space in order to avoid growing the array - SentryEventUrl.AppendChars(EventIdString, FCStringAnsi::Strlen(EventIdString)); + EventDestinationUrl.AppendChars(EventIdString, FCStringAnsi::Strlen(EventIdString)); } - UE_LOG(LogSentrySdk, Error, TEXT("%s"), *SentryEventUrl); + UE_LOG(LogSentrySdk, Error, TEXT("%s"), *EventDestinationUrl); return event; } @@ -316,13 +316,17 @@ void FGenericPlatformSentrySubsystem::InitWithSettings(const USentrySettings* se // Allocate large enough buffer to hold the URL base plus event ID to avoid memory allocations // during crash handling - constexpr int32 SentryEventUrlSlack = 64; - SentryEventUrl = FString::ConstructWithSlack( + constexpr int32 EventDestinationUrlSlack = 64; +#if UE_VERSION_OLDER_THAN(5, 4, 0) + EventDestinationUrl = FString( +#else + EventDestinationUrl = FString::ConstructWithSlack( +#endif *FString::Printf( TEXT("http://sentry.io/organizations/riotgames/issues/?project=%s&statsPeriod=1h&query="), *ProjectId ), - SentryEventUrlSlack + EventDestinationUrlSlack ); sentry_options_set_dsn(options, TCHAR_TO_ANSI(*Dsn));