From ade9bfd8832f75daa3a8a6d219e7ee3b1319cb8c Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Mon, 20 Jan 2025 20:54:59 +1300 Subject: [PATCH 1/6] Fixed duplicate SentryMauiOptions registration --- .../SentryMauiAppBuilderExtensions.cs | 1 - .../SentryMauiAppBuilderExtensionsTests.cs | 19 +++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/Sentry.Maui/SentryMauiAppBuilderExtensions.cs b/src/Sentry.Maui/SentryMauiAppBuilderExtensions.cs index da2a569926..ad9b05ba27 100644 --- a/src/Sentry.Maui/SentryMauiAppBuilderExtensions.cs +++ b/src/Sentry.Maui/SentryMauiAppBuilderExtensions.cs @@ -55,7 +55,6 @@ public static MauiAppBuilder UseSentry(this MauiAppBuilder builder, services.AddLogging(); services.AddSingleton(); services.AddSingleton(); - services.AddSingleton, SentryMauiOptionsSetup>(); services.AddSingleton(); services.TryAddSingleton(); 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() { From 77ecd1bc70f93e4d0eccb68452703fe9a0f9b8c1 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Mon, 20 Jan 2025 20:56:50 +1300 Subject: [PATCH 2/6] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf2cf291e5..662bdf58e1 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 SentryMauiOptions registration ([#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)) From ec1389e7171f6a2b69c16ef0ce7905dd77fa2211 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Mon, 20 Jan 2025 22:24:30 +1300 Subject: [PATCH 3/6] Update SentryMauiAppBuilderExtensions.cs --- src/Sentry.Maui/SentryMauiAppBuilderExtensions.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Sentry.Maui/SentryMauiAppBuilderExtensions.cs b/src/Sentry.Maui/SentryMauiAppBuilderExtensions.cs index ad9b05ba27..924abe09bf 100644 --- a/src/Sentry.Maui/SentryMauiAppBuilderExtensions.cs +++ b/src/Sentry.Maui/SentryMauiAppBuilderExtensions.cs @@ -44,9 +44,7 @@ public static MauiAppBuilder UseSentry(this MauiAppBuilder builder, { var services = builder.Services; - var section = builder.Configuration.GetSection("Sentry"); - services.AddSingleton>(_ => new SentryMauiOptionsSetup(section)); - + services.AddSingleton, SentryMauiOptionsSetup>(); if (configureOptions != null) { services.Configure(configureOptions); From 7aece247c733474f593e0d586fd0099a7d1bab26 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Mon, 20 Jan 2025 23:17:30 +1300 Subject: [PATCH 4/6] Update SentryMauiAppBuilderExtensions.cs --- src/Sentry.Maui/SentryMauiAppBuilderExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Sentry.Maui/SentryMauiAppBuilderExtensions.cs b/src/Sentry.Maui/SentryMauiAppBuilderExtensions.cs index 924abe09bf..1cbefb19bf 100644 --- a/src/Sentry.Maui/SentryMauiAppBuilderExtensions.cs +++ b/src/Sentry.Maui/SentryMauiAppBuilderExtensions.cs @@ -44,7 +44,6 @@ public static MauiAppBuilder UseSentry(this MauiAppBuilder builder, { var services = builder.Services; - services.AddSingleton, SentryMauiOptionsSetup>(); if (configureOptions != null) { services.Configure(configureOptions); @@ -53,6 +52,7 @@ public static MauiAppBuilder UseSentry(this MauiAppBuilder builder, services.AddLogging(); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton, SentryMauiOptionsSetup>(); services.AddSingleton(); services.TryAddSingleton(); From f374309b4c6dc4ba040b2115c16075ee7501b636 Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Wed, 22 Jan 2025 12:15:39 +1300 Subject: [PATCH 5/6] Update SentryMauiOptionsSetup.cs --- src/Sentry.Maui/Internal/SentryMauiOptionsSetup.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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) From 1112bd86ebbccbf00f0af2b8d71d0a96c343963b Mon Sep 17 00:00:00 2001 From: James Crosswell Date: Wed, 22 Jan 2025 12:18:51 +1300 Subject: [PATCH 6/6] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 662bdf58e1..11864c37de 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,7 +9,7 @@ ### Fixes -- Fixed duplicate SentryMauiOptions registration ([#3905](https://github.com/getsentry/sentry-dotnet/pull/3905)) +- Fixed duplicate SentryMauiEventProcessors ([#3905](https://github.com/getsentry/sentry-dotnet/pull/3905)) ### Dependencies