about summary refs log tree commit diff
path: root/MatrixRoomUtils.Desktop/SentryService.cs
diff options
context:
space:
mode:
authorEmma@Rory& <root@rory.gay>2023-07-26 21:02:50 +0200
committerEmma@Rory& <root@rory.gay>2023-07-26 21:02:50 +0200
commit2e89a0717a60598904c92499adb7e01b2075fbb9 (patch)
tree56b9b7f07180154d9d98dafa91d7c16a0a872100 /MatrixRoomUtils.Desktop/SentryService.cs
parentStart of nix flake (diff)
downloadMatrixUtils-2e89a0717a60598904c92499adb7e01b2075fbb9.tar.xz
MRU desktop start
Diffstat (limited to 'MatrixRoomUtils.Desktop/SentryService.cs')
-rw-r--r--MatrixRoomUtils.Desktop/SentryService.cs29
1 files changed, 29 insertions, 0 deletions
diff --git a/MatrixRoomUtils.Desktop/SentryService.cs b/MatrixRoomUtils.Desktop/SentryService.cs
new file mode 100644
index 0000000..ed96697
--- /dev/null
+++ b/MatrixRoomUtils.Desktop/SentryService.cs
@@ -0,0 +1,29 @@
+using Microsoft.Extensions.DependencyInjection;
+using Microsoft.Extensions.Logging;
+using Sentry;
+
+namespace MatrixRoomUtils.Desktop;
+
+public class SentryService : IDisposable {
+    private IDisposable? _sentrySdkDisposable;
+    public SentryService(IServiceScopeFactory scopeFactory, ILogger<SentryService> logger) {
+        MRUDesktopConfiguration config = scopeFactory.CreateScope().ServiceProvider.GetRequiredService<MRUDesktopConfiguration>();
+        if (config.SentryDsn is null) {
+            logger.LogWarning("Sentry DSN is not set, skipping Sentry initialisation");
+            return;
+        }
+        _sentrySdkDisposable = SentrySdk.Init(o => {
+            o.Dsn = config.SentryDsn;
+            // When configuring for the first time, to see what the SDK is doing:
+            o.Debug = true;
+            // Set traces_sample_rate to 1.0 to capture 100% of transactions for performance monitoring.
+            // We recommend adjusting this value in production.
+            o.TracesSampleRate = 1.0;
+            // Enable Global Mode if running in a client app
+            o.IsGlobalModeEnabled = true;
+        });
+    }
+
+    /// <summary>Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.</summary>
+    public void Dispose() => _sentrySdkDisposable?.Dispose();
+}