Skip to content

Add destination URL for crash envelope #905

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 (EventDestinationUrl.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
EventDestinationUrl.AppendChars(EventIdString, FCStringAnsi::Strlen(EventIdString));
}

UE_LOG(LogSentrySdk, Error, TEXT("%s"), *EventDestinationUrl);

return event;
}
else
{
return sentry_value_new_null();
}
}

void FGenericPlatformSentrySubsystem::InitCrashReporter(const FString& release, const FString& environment)
Expand Down Expand Up @@ -287,13 +302,34 @@ 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 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
),
EventDestinationUrlSlack
);

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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ class FGenericPlatformSentrySubsystem : public ISentrySubsystem
FCriticalSection CriticalSection;

FString databaseParentPath;

/**
* The expected destination URL of the crash envelope.
*/
FString EventDestinationUrl;
};

#endif
Loading