Skip to content

Commit

Permalink
Fixed duplicate SentryMauiEventProcessors (#3905)
Browse files Browse the repository at this point in the history
  • Loading branch information
jamescrosswell authored Jan 28, 2025
1 parent a4fc2fe commit 81452c1
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,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.19 ([#3891](https://github.com/getsentry/sentry-dotnet/pull/3891), [#3908](https://github.com/getsentry/sentry-dotnet/pull/3908))
Expand Down
2 changes: 1 addition & 1 deletion src/Sentry.Maui/Internal/SentryMauiOptionsSetup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal class SentryMauiOptionsSetup : IConfigureOptions<SentryMauiOptions>
public SentryMauiOptionsSetup(IConfiguration config)
{
ArgumentNullException.ThrowIfNull(config);
_config = config;
_config = config.GetSection("Sentry");
}

public void Configure(SentryMauiOptions options)
Expand Down
3 changes: 0 additions & 3 deletions src/Sentry.Maui/SentryMauiAppBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,6 @@ public static MauiAppBuilder UseSentry(this MauiAppBuilder builder,
{
var services = builder.Services;

var section = builder.Configuration.GetSection("Sentry");
services.AddSingleton<IConfigureOptions<SentryMauiOptions>>(_ => new SentryMauiOptionsSetup(section));

if (configureOptions != null)
{
services.Configure(configureOptions);
Expand Down
19 changes: 19 additions & 0 deletions test/Sentry.Maui.Tests/SentryMauiAppBuilderExtensionsTests.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -29,6 +30,24 @@ public Fixture()

private readonly Fixture _fixture = new();

[Fact]
public void UseSentry_RegistersEventProcessorOnlyOnce()
{
// Arrange
var builder = _fixture.Builder;
builder.Services.Configure<SentryMauiOptions>(options =>
{
options.Dsn = ValidDsn;
});

// Act
using var app = builder.UseSentry().Build();

// Assert
var options = app.Services.GetRequiredService<IOptions<SentryMauiOptions>>().Value;
options.EventProcessors.Should().ContainSingle(t => t.Type == typeof(SentryMauiEventProcessor));
}

[Fact]
public void CanUseSentry_WithConfigurationOnly()
{
Expand Down

0 comments on commit 81452c1

Please sign in to comment.