Skip to content

Commit 81452c1

Browse files
Fixed duplicate SentryMauiEventProcessors (#3905)
1 parent a4fc2fe commit 81452c1

File tree

4 files changed

+24
-4
lines changed

4 files changed

+24
-4
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
- .NET on iOS: Add experimental EnableAppHangTrackingV2 configuration flag to the options binding SDK ([#3877](https://github.com/getsentry/sentry-dotnet/pull/3877))
1212
- 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))
1313

14+
### Fixes
15+
16+
- Fixed duplicate SentryMauiEventProcessors ([#3905](https://github.com/getsentry/sentry-dotnet/pull/3905))
17+
1418
### Dependencies
1519

1620
- Bump Native SDK from v0.7.17 to v0.7.19 ([#3891](https://github.com/getsentry/sentry-dotnet/pull/3891), [#3908](https://github.com/getsentry/sentry-dotnet/pull/3908))

src/Sentry.Maui/Internal/SentryMauiOptionsSetup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal class SentryMauiOptionsSetup : IConfigureOptions<SentryMauiOptions>
1515
public SentryMauiOptionsSetup(IConfiguration config)
1616
{
1717
ArgumentNullException.ThrowIfNull(config);
18-
_config = config;
18+
_config = config.GetSection("Sentry");
1919
}
2020

2121
public void Configure(SentryMauiOptions options)

src/Sentry.Maui/SentryMauiAppBuilderExtensions.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ public static MauiAppBuilder UseSentry(this MauiAppBuilder builder,
4444
{
4545
var services = builder.Services;
4646

47-
var section = builder.Configuration.GetSection("Sentry");
48-
services.AddSingleton<IConfigureOptions<SentryMauiOptions>>(_ => new SentryMauiOptionsSetup(section));
49-
5047
if (configureOptions != null)
5148
{
5249
services.Configure(configureOptions);

test/Sentry.Maui.Tests/SentryMauiAppBuilderExtensionsTests.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Microsoft.Extensions.Options;
22
using Sentry.Internal.Http;
3+
using Sentry.Maui.Internal;
34
using MauiConstants = Sentry.Maui.Internal.Constants;
45

56
namespace Sentry.Maui.Tests;
@@ -29,6 +30,24 @@ public Fixture()
2930

3031
private readonly Fixture _fixture = new();
3132

33+
[Fact]
34+
public void UseSentry_RegistersEventProcessorOnlyOnce()
35+
{
36+
// Arrange
37+
var builder = _fixture.Builder;
38+
builder.Services.Configure<SentryMauiOptions>(options =>
39+
{
40+
options.Dsn = ValidDsn;
41+
});
42+
43+
// Act
44+
using var app = builder.UseSentry().Build();
45+
46+
// Assert
47+
var options = app.Services.GetRequiredService<IOptions<SentryMauiOptions>>().Value;
48+
options.EventProcessors.Should().ContainSingle(t => t.Type == typeof(SentryMauiEventProcessor));
49+
}
50+
3251
[Fact]
3352
public void CanUseSentry_WithConfigurationOnly()
3453
{

0 commit comments

Comments
 (0)