about summary refs log tree commit diff
path: root/MatrixUtils.Desktop/SentryService.cs
blob: c9656322956ab1134bee546d5d35e8b35231b7f2 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Sentry;

namespace MatrixUtils.Desktop;

public class SentryService : IDisposable {
    private IDisposable? _sentrySdkDisposable;
    public SentryService(IServiceScopeFactory scopeFactory, ILogger<SentryService> logger) {
        var config = scopeFactory.CreateScope().ServiceProvider.GetRequiredService<RMUDesktopConfiguration>();
        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();
}