Skip to content

Commit 3f3a37d

Browse files
committed
Resolve PR comments
1 parent f512d9d commit 3f3a37d

File tree

8 files changed

+57
-72
lines changed

8 files changed

+57
-72
lines changed

plugin-dev/Source/Sentry/Private/Android/Jni/AndroidSentryJni.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "SentryDefines.h"
2121
#include "SentryEvent.h"
2222
#include "SentryHint.h"
23-
#include "SentryLogData.h"
23+
#include "SentryLog.h"
2424
#include "SentrySamplingContext.h"
2525
#include "SentryTraceSampler.h"
2626

@@ -120,10 +120,10 @@ JNI_METHOD jobject Java_io_sentry_unreal_SentryBridgeJava_onBeforeLog(JNIEnv* en
120120

121121
USentryBeforeLogHandler* handler = reinterpret_cast<USentryBeforeLogHandler*>(objAddr);
122122

123-
USentryLogData* LogDataToProcess = USentryLogData::Create(MakeShareable(new FAndroidSentryLog(logEvent)));
123+
USentryLog* LogDataToProcess = USentryLog::Create(MakeShareable(new FAndroidSentryLog(logEvent)));
124124
USentryHint* HintToProcess = USentryHint::Create(MakeShareable(new FAndroidSentryHint(hint)));
125125

126-
USentryLogData* ProcessedLogData = handler->HandleBeforeLog(LogDataToProcess);
126+
USentryLog* ProcessedLogData = handler->HandleBeforeLog(LogDataToProcess);
127127

128128
return ProcessedLogData ? logEvent : nullptr;
129129
}

plugin-dev/Source/Sentry/Private/Apple/AppleSentrySubsystem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,9 +143,9 @@ void FAppleSentrySubsystem::InitWithSettings(const USentrySettings* settings, US
143143
return log;
144144
}
145145

146-
USentryLogData* LogToProcess = USentryLogData::Create(MakeShareable(new FAppleSentryLog(log)));
146+
USentryLog* LogToProcess = USentryLog::Create(MakeShareable(new FAppleSentryLog(log)));
147147

148-
USentryLogData* ProcessedLog = beforeLogHandler->HandleBeforeLog(LogToProcess);
148+
USentryLog* ProcessedLog = beforeLogHandler->HandleBeforeLog(LogToProcess);
149149

150150
return ProcessedLog ? log : nullptr;
151151
};

plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentrySubsystem.cpp

Lines changed: 29 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
#include "SentryBreadcrumb.h"
2020
#include "SentryDefines.h"
2121
#include "SentryEvent.h"
22-
#include "SentryLogData.h"
22+
#include "SentryLog.h"
2323
#include "SentryModule.h"
2424
#include "SentrySamplingContext.h"
2525
#include "SentrySettings.h"
@@ -124,6 +124,23 @@ static void PrintVerboseLog(sentry_level_t level, const char* message, va_list a
124124
return log;
125125
}
126126

127+
bool FGenericPlatformSentrySubsystem::IsCallbackSafeToRun(const FString& handlerName) const
128+
{
129+
if (FUObjectThreadContext::Get().IsRoutingPostLoad)
130+
{
131+
UE_LOG(LogSentrySdk, Log, TEXT("Executing `%s` handler is not allowed during object post-loading."), *handlerName);
132+
return false;
133+
}
134+
135+
if (IsGarbageCollecting())
136+
{
137+
UE_LOG(LogSentrySdk, Log, TEXT("Executing `%s` handler is not allowed during garbage collection."), *handlerName);
138+
return false;
139+
}
140+
141+
return true;
142+
}
143+
127144
sentry_value_t FGenericPlatformSentrySubsystem::OnBeforeSend(sentry_value_t event, void* hint, void* closure, bool isCrash)
128145
{
129146
if (!closure || this != closure)
@@ -138,18 +155,8 @@ sentry_value_t FGenericPlatformSentrySubsystem::OnBeforeSend(sentry_value_t even
138155
return event;
139156
}
140157

141-
if (FUObjectThreadContext::Get().IsRoutingPostLoad)
158+
if (!IsCallbackSafeToRun(TEXT("beforeSend")))
142159
{
143-
UE_LOG(LogSentrySdk, Log, TEXT("Executing `beforeSend` handler is not allowed during object post-loading."));
144-
return event;
145-
}
146-
147-
if (IsGarbageCollecting())
148-
{
149-
// If event is captured during garbage collection we can't instantiate UObjects safely or obtain a GC lock
150-
// since it will cause a deadlock (see https://github.com/getsentry/sentry-unreal/issues/850).
151-
// In this case event will be reported without calling a `beforeSend` handler.
152-
UE_LOG(LogSentrySdk, Log, TEXT("Executing `beforeSend` handler is not allowed during garbage collection."));
153160
return event;
154161
}
155162

@@ -177,17 +184,8 @@ sentry_value_t FGenericPlatformSentrySubsystem::OnBeforeBreadcrumb(sentry_value_
177184
return breadcrumb;
178185
}
179186

180-
if (FUObjectThreadContext::Get().IsRoutingPostLoad)
187+
if (!IsCallbackSafeToRun(TEXT("beforeBreadcrumb")))
181188
{
182-
// Don't print to logs within `onBeforeBreadcrumb` handler as this can lead to creating new breadcrumb
183-
return breadcrumb;
184-
}
185-
186-
if (IsGarbageCollecting())
187-
{
188-
// If breadcrumb is added during garbage collection we can't instantiate UObjects safely or obtain a GC lock
189-
// since there is no guarantee it will be ever freed.
190-
// In this case breadcrumb will be added without calling a `beforeBreadcrumb` handler.
191189
return breadcrumb;
192190
}
193191

@@ -212,24 +210,15 @@ sentry_value_t FGenericPlatformSentrySubsystem::OnBeforeLog(sentry_value_t log,
212210
return log;
213211
}
214212

215-
if (FUObjectThreadContext::Get().IsRoutingPostLoad)
213+
if (!IsCallbackSafeToRun(TEXT("beforeLog")))
216214
{
217-
// Skip log processing during post load to avoid issues
218215
return log;
219216
}
220217

221-
if (IsGarbageCollecting())
222-
{
223-
// If breadcrumb is added during garbage collection we can't instantiate UObjects safely or obtain a GC lock
224-
// since there is no guarantee it will be ever freed.
225-
// In this case breadcrumb will be added without calling a `beforeBreadcrumb` handler.
226-
return log;
227-
}
228-
229-
// Create USentryLogData object using the log wrapper
230-
USentryLogData* LogData = USentryLogData::Create(MakeShareable(new FGenericPlatformSentryLog(log)));
218+
// Create USentryLog object using the log wrapper
219+
USentryLog* LogData = USentryLog::Create(MakeShareable(new FGenericPlatformSentryLog(log)));
231220

232-
USentryLogData* ProcessedLogData = Handler->HandleBeforeLog(LogData);
221+
USentryLog* ProcessedLogData = Handler->HandleBeforeLog(LogData);
233222

234223
return ProcessedLogData ? log : sentry_value_new_null();
235224
}
@@ -260,18 +249,8 @@ double FGenericPlatformSentrySubsystem::OnTraceSampling(const sentry_transaction
260249
return parent_sampled != nullptr ? *parent_sampled : 0.0;
261250
}
262251

263-
if (FUObjectThreadContext::Get().IsRoutingPostLoad)
264-
{
265-
UE_LOG(LogSentrySdk, Log, TEXT("Executing traces sampler is not allowed during object post-loading."));
266-
return parent_sampled != nullptr ? *parent_sampled : 0.0;
267-
}
268-
269-
if (IsGarbageCollecting())
252+
if (!IsCallbackSafeToRun(TEXT("traceSampler")))
270253
{
271-
// If traces sampling happens during garbage collection we can't instantiate UObjects safely or obtain a GC lock
272-
// since it will cause a deadlock (see https://github.com/getsentry/sentry-unreal/issues/850).
273-
// In this case event will be reported without calling a `beforeSend` handler.
274-
UE_LOG(LogSentrySdk, Log, TEXT("Executing traces sampler is not allowed during garbage collection."));
275254
return parent_sampled != nullptr ? *parent_sampled : 0.0;
276255
}
277256

@@ -861,22 +840,22 @@ TSharedPtr<ISentryTransactionContext> FGenericPlatformSentrySubsystem::ContinueT
861840
return transactionContext;
862841
}
863842

864-
USentryBeforeSendHandler* FGenericPlatformSentrySubsystem::GetBeforeSendHandler()
843+
USentryBeforeSendHandler* FGenericPlatformSentrySubsystem::GetBeforeSendHandler() const
865844
{
866845
return beforeSend;
867846
}
868847

869-
USentryBeforeBreadcrumbHandler* FGenericPlatformSentrySubsystem::GetBeforeBreadcrumbHandler()
848+
USentryBeforeBreadcrumbHandler* FGenericPlatformSentrySubsystem::GetBeforeBreadcrumbHandler() const
870849
{
871850
return beforeBreadcrumb;
872851
}
873852

874-
USentryBeforeLogHandler* FGenericPlatformSentrySubsystem::GetBeforeLogHandler()
853+
USentryBeforeLogHandler* FGenericPlatformSentrySubsystem::GetBeforeLogHandler() const
875854
{
876855
return beforeLog;
877856
}
878857

879-
USentryTraceSampler* FGenericPlatformSentrySubsystem::GetTraceSampler()
858+
USentryTraceSampler* FGenericPlatformSentrySubsystem::GetTraceSampler() const
880859
{
881860
return sampler;
882861
}

plugin-dev/Source/Sentry/Private/GenericPlatform/GenericPlatformSentrySubsystem.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@ class FGenericPlatformSentrySubsystem : public ISentrySubsystem
5555

5656
virtual void HandleAssert() override {}
5757

58-
USentryBeforeSendHandler* GetBeforeSendHandler();
59-
USentryBeforeBreadcrumbHandler* GetBeforeBreadcrumbHandler();
60-
USentryBeforeLogHandler* GetBeforeLogHandler();
61-
USentryTraceSampler* GetTraceSampler();
58+
USentryBeforeSendHandler* GetBeforeSendHandler() const;
59+
USentryBeforeBreadcrumbHandler* GetBeforeBreadcrumbHandler() const;
60+
USentryBeforeLogHandler* GetBeforeLogHandler() const;
61+
USentryTraceSampler* GetTraceSampler() const;
6262

6363
void TryCaptureScreenshot();
6464
void TryCaptureGpuDump();
@@ -98,6 +98,12 @@ class FGenericPlatformSentrySubsystem : public ISentrySubsystem
9898
static sentry_value_t HandleOnCrash(const sentry_ucontext_t* uctx, sentry_value_t event, void* closure);
9999
static double HandleTraceSampling(const sentry_transaction_context_t* transaction_ctx, sentry_value_t custom_sampling_ctx, const int* parent_sampled, void* closure);
100100

101+
/**
102+
* Checks if it's safe to run callback handlers that instantiate UObjects.
103+
* Returns false if during post-load or garbage collection to prevent deadlocks.
104+
*/
105+
bool IsCallbackSafeToRun(const FString& handlerName) const;
106+
101107
USentryBeforeSendHandler* beforeSend;
102108
USentryBeforeBreadcrumbHandler* beforeBreadcrumb;
103109
USentryBeforeLogHandler* beforeLog;
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
// Copyright (c) 2025 Sentry. All Rights Reserved.
22

33
#include "SentryBeforeLogHandler.h"
4-
#include "SentryLogData.h"
4+
#include "SentryLog.h"
55

6-
USentryLogData* USentryBeforeLogHandler::HandleBeforeLog_Implementation(USentryLogData* LogData)
6+
USentryLog* USentryBeforeLogHandler::HandleBeforeLog_Implementation(USentryLog* LogData)
77
{
88
return LogData;
99
}

plugin-dev/Source/Sentry/Private/SentryLogData.cpp renamed to plugin-dev/Source/Sentry/Private/SentryLog.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,39 @@
11
// Copyright (c) 2025 Sentry. All Rights Reserved.
22

3-
#include "SentryLogData.h"
3+
#include "SentryLog.h"
44

55
#include "HAL/PlatformSentryLog.h"
66

7-
void USentryLogData::Initialize()
7+
void USentryLog::Initialize()
88
{
99
NativeImpl = CreateSharedSentryLog();
1010
}
1111

12-
void USentryLogData::SetMessage(const FString& InMessage)
12+
void USentryLog::SetMessage(const FString& InMessage)
1313
{
1414
if (!NativeImpl)
1515
return;
1616

1717
NativeImpl->SetMessage(InMessage);
1818
}
1919

20-
FString USentryLogData::GetMessage() const
20+
FString USentryLog::GetMessage() const
2121
{
2222
if (!NativeImpl)
2323
return FString();
2424

2525
return NativeImpl->GetMessage();
2626
}
2727

28-
void USentryLogData::SetLevel(ESentryLevel InLevel)
28+
void USentryLog::SetLevel(ESentryLevel InLevel)
2929
{
3030
if (!NativeImpl)
3131
return;
3232

3333
NativeImpl->SetLevel(InLevel);
3434
}
3535

36-
ESentryLevel USentryLogData::GetLevel() const
36+
ESentryLevel USentryLog::GetLevel() const
3737
{
3838
if (!NativeImpl)
3939
return ESentryLevel::Info;

plugin-dev/Source/Sentry/Public/SentryBeforeLogHandler.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
#include "SentryBeforeLogHandler.generated.h"
99

10-
class USentryLogData;
10+
class USentryLog;
1111

1212
UCLASS(Blueprintable)
1313
class SENTRY_API USentryBeforeLogHandler : public UObject
@@ -16,6 +16,6 @@ class SENTRY_API USentryBeforeLogHandler : public UObject
1616

1717
public:
1818
UFUNCTION(BlueprintNativeEvent)
19-
USentryLogData* HandleBeforeLog(USentryLogData* LogData);
20-
virtual USentryLogData* HandleBeforeLog_Implementation(USentryLogData* LogData);
19+
USentryLog* HandleBeforeLog(USentryLog* LogData);
20+
virtual USentryLog* HandleBeforeLog_Implementation(USentryLog* LogData);
2121
};

plugin-dev/Source/Sentry/Public/SentryLogData.h renamed to plugin-dev/Source/Sentry/Public/SentryLog.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
#include "SentryImplWrapper.h"
77
#include "SentryVariant.h"
88

9-
#include "SentryLogData.generated.h"
9+
#include "SentryLog.generated.h"
1010

1111
class ISentryLog;
1212

1313
/**
1414
* Data structure representing a structured log entry for Sentry.
1515
*/
1616
UCLASS(BlueprintType, NotBlueprintable, HideDropdown)
17-
class SENTRY_API USentryLogData : public UObject, public TSentryImplWrapper<ISentryLog, USentryLogData>
17+
class SENTRY_API USentryLog : public UObject, public TSentryImplWrapper<ISentryLog, USentryLog>
1818
{
1919
GENERATED_BODY()
2020

0 commit comments

Comments
 (0)