getsentry / sentry-unity

Development of Sentry SDK for Unity
https://docs.sentry.io/platforms/unity/
MIT License
206 stars 51 forks source link

Cache, background threads and data for UnityEventProcessor #267

Closed semuserable closed 3 years ago

semuserable commented 3 years ago

// Cached, isn't shown in dotTrace, must be called from UI thread SystemInfo.processorCount SystemInfo.processorType SystemInfo.supportsVibration // etc

// Cached, shown in dotTrace, must be called from UI thread new Lazy(() => SystemInfo.deviceUniqueIdentifier) new Lazy(() => SystemInfo.deviceModel) new Lazy(() => SystemInfo.graphicsDeviceVendorID.ToString()) // etc

- [x] `Task.Run(() => SentrySdk.CaptureEvent(sentryEvent));` must not fail and send the event
- [x] If `SentrySdk.CaptureEvent` is called from non-UI thread, make sure the event processing won't fail (because of calling Unity APIs from non-UI thread). But if `SentrySdk.CaptureEvent` is called in UI thread and then non-UI thread (`Task.Run`), populate the data from cached value
```csharp
// In order to have `SystemInfo.deviceType` set in `SentryEvent.Device.DeviceType`, we must call it from UI thread.

// first call, non-UI thread,  `SentryEvent.Device.DeviceType` is `null`
Task.Run(() => SentrySdk.CaptureEvent(sentryEvent));

// second call, UI thread, `SentryEvent.Device.DeviceType` is NOT `null` and equals to 'Desktop'
SentrySdk.CaptureEvent(sentryEvent);

// third call, non-UI thread, `SentryEvent.Device.DeviceType` is NOT `null` and equals to 'Desktop'
Task.Run(() => SentrySdk.CaptureEvent(sentryEvent));
semuserable commented 3 years ago

closed by https://github.com/getsentry/sentry-unity/pull/268