19
19
#include " SentryBreadcrumb.h"
20
20
#include " SentryDefines.h"
21
21
#include " SentryEvent.h"
22
- #include " SentryLogData .h"
22
+ #include " SentryLog .h"
23
23
#include " SentryModule.h"
24
24
#include " SentrySamplingContext.h"
25
25
#include " SentrySettings.h"
@@ -124,6 +124,23 @@ static void PrintVerboseLog(sentry_level_t level, const char* message, va_list a
124
124
return log;
125
125
}
126
126
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
+
127
144
sentry_value_t FGenericPlatformSentrySubsystem::OnBeforeSend (sentry_value_t event, void * hint, void * closure, bool isCrash)
128
145
{
129
146
if (!closure || this != closure)
@@ -138,18 +155,8 @@ sentry_value_t FGenericPlatformSentrySubsystem::OnBeforeSend(sentry_value_t even
138
155
return event;
139
156
}
140
157
141
- if (FUObjectThreadContext::Get (). IsRoutingPostLoad )
158
+ if (! IsCallbackSafeToRun ( TEXT ( " beforeSend " )) )
142
159
{
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." ));
153
160
return event;
154
161
}
155
162
@@ -177,17 +184,8 @@ sentry_value_t FGenericPlatformSentrySubsystem::OnBeforeBreadcrumb(sentry_value_
177
184
return breadcrumb;
178
185
}
179
186
180
- if (FUObjectThreadContext::Get (). IsRoutingPostLoad )
187
+ if (! IsCallbackSafeToRun ( TEXT ( " beforeBreadcrumb " )) )
181
188
{
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.
191
189
return breadcrumb;
192
190
}
193
191
@@ -212,24 +210,15 @@ sentry_value_t FGenericPlatformSentrySubsystem::OnBeforeLog(sentry_value_t log,
212
210
return log;
213
211
}
214
212
215
- if (FUObjectThreadContext::Get (). IsRoutingPostLoad )
213
+ if (! IsCallbackSafeToRun ( TEXT ( " beforeLog " )) )
216
214
{
217
- // Skip log processing during post load to avoid issues
218
215
return log;
219
216
}
220
217
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)));
231
220
232
- USentryLogData * ProcessedLogData = Handler->HandleBeforeLog (LogData);
221
+ USentryLog * ProcessedLogData = Handler->HandleBeforeLog (LogData);
233
222
234
223
return ProcessedLogData ? log : sentry_value_new_null ();
235
224
}
@@ -260,18 +249,8 @@ double FGenericPlatformSentrySubsystem::OnTraceSampling(const sentry_transaction
260
249
return parent_sampled != nullptr ? *parent_sampled : 0.0 ;
261
250
}
262
251
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" )))
270
253
{
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." ));
275
254
return parent_sampled != nullptr ? *parent_sampled : 0.0 ;
276
255
}
277
256
@@ -861,22 +840,22 @@ TSharedPtr<ISentryTransactionContext> FGenericPlatformSentrySubsystem::ContinueT
861
840
return transactionContext;
862
841
}
863
842
864
- USentryBeforeSendHandler* FGenericPlatformSentrySubsystem::GetBeforeSendHandler ()
843
+ USentryBeforeSendHandler* FGenericPlatformSentrySubsystem::GetBeforeSendHandler () const
865
844
{
866
845
return beforeSend;
867
846
}
868
847
869
- USentryBeforeBreadcrumbHandler* FGenericPlatformSentrySubsystem::GetBeforeBreadcrumbHandler ()
848
+ USentryBeforeBreadcrumbHandler* FGenericPlatformSentrySubsystem::GetBeforeBreadcrumbHandler () const
870
849
{
871
850
return beforeBreadcrumb;
872
851
}
873
852
874
- USentryBeforeLogHandler* FGenericPlatformSentrySubsystem::GetBeforeLogHandler ()
853
+ USentryBeforeLogHandler* FGenericPlatformSentrySubsystem::GetBeforeLogHandler () const
875
854
{
876
855
return beforeLog;
877
856
}
878
857
879
- USentryTraceSampler* FGenericPlatformSentrySubsystem::GetTraceSampler ()
858
+ USentryTraceSampler* FGenericPlatformSentrySubsystem::GetTraceSampler () const
880
859
{
881
860
return sampler;
882
861
}
0 commit comments