diff --git a/CHANGELOG.md b/CHANGELOG.md index cf2cf291e5..11864c37de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ - .NET on iOS: Add experimental EnableAppHangTrackingV2 configuration flag to the options binding SDK ([#3877](https://github.com/getsentry/sentry-dotnet/pull/3877)) - Added `SentryOptions.DisableSentryHttpMessageHandler`. Useful if you're using `OpenTelemetry.Instrumentation.Http` and ending up with duplicate spans. ([#3879](https://github.com/getsentry/sentry-dotnet/pull/3879)) +### Fixes + +- Fixed duplicate SentryMauiEventProcessors ([#3905](https://github.com/getsentry/sentry-dotnet/pull/3905)) + ### Dependencies - Bump Native SDK from v0.7.17 to v0.7.18 ([#3891](https://github.com/getsentry/sentry-dotnet/pull/3891)) diff --git a/src/Sentry.Maui/Internal/SentryMauiOptionsSetup.cs b/src/Sentry.Maui/Internal/SentryMauiOptionsSetup.cs index d13b9731d8..7436d0720e 100644 --- a/src/Sentry.Maui/Internal/SentryMauiOptionsSetup.cs +++ b/src/Sentry.Maui/Internal/SentryMauiOptionsSetup.cs @@ -15,7 +15,7 @@ internal class SentryMauiOptionsSetup : IConfigureOptions public SentryMauiOptionsSetup(IConfiguration config) { ArgumentNullException.ThrowIfNull(config); - _config = config; + _config = config.GetSection("Sentry"); } public void Configure(SentryMauiOptions options) diff --git a/src/Sentry.Maui/SentryMauiAppBuilderExtensions.cs b/src/Sentry.Maui/SentryMauiAppBuilderExtensions.cs index da2a569926..1cbefb19bf 100644 --- a/src/Sentry.Maui/SentryMauiAppBuilderExtensions.cs +++ b/src/Sentry.Maui/SentryMauiAppBuilderExtensions.cs @@ -44,9 +44,6 @@ public static MauiAppBuilder UseSentry(this MauiAppBuilder builder, { var services = builder.Services; - var section = builder.Configuration.GetSection("Sentry"); - services.AddSingleton>(_ => new SentryMauiOptionsSetup(section)); - if (configureOptions != null) { services.Configure(configureOptions); diff --git a/test/Sentry.Maui.Tests/SentryMauiAppBuilderExtensionsTests.cs b/test/Sentry.Maui.Tests/SentryMauiAppBuilderExtensionsTests.cs index 2bbd4b493e..c3fac5e100 100644 --- a/test/Sentry.Maui.Tests/SentryMauiAppBuilderExtensionsTests.cs +++ b/test/Sentry.Maui.Tests/SentryMauiAppBuilderExtensionsTests.cs @@ -1,5 +1,6 @@ using Microsoft.Extensions.Options; using Sentry.Internal.Http; +using Sentry.Maui.Internal; using MauiConstants = Sentry.Maui.Internal.Constants; namespace Sentry.Maui.Tests; @@ -29,6 +30,24 @@ public Fixture() private readonly Fixture _fixture = new(); + [Fact] + public void UseSentry_RegistersEventProcessorOnlyOnce() + { + // Arrange + var builder = _fixture.Builder; + builder.Services.Configure(options => + { + options.Dsn = ValidDsn; + }); + + // Act + using var app = builder.UseSentry().Build(); + + // Assert + var options = app.Services.GetRequiredService>().Value; + options.EventProcessors.Should().ContainSingle(t => t.Type == typeof(SentryMauiEventProcessor)); + } + [Fact] public void CanUseSentry_WithConfigurationOnly() {