Skip to content

Commit

Permalink
Fixed: SentryHttpMessageHandler added when AddHttpClient is before Us…
Browse files Browse the repository at this point in the history
…eSentry (#2390)

* Fixed #2373: SentryHttpMessageHandler not being added when AddHttpClient is before UseSentry

Fixes #2373

* Updated changelog
  • Loading branch information
jamescrosswell authored May 24, 2023
1 parent 3e8edb7 commit dcc32b2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

## Unreleased

## Fixes
### Fixes

- SentryHttpMessageHandler added when AddHttpClient is before UseSentry ([#2390](https://github.com/getsentry/sentry-dotnet/pull/2390))
- Set the native sdk name for Android ([#2389](https://github.com/getsentry/sentry-dotnet/pull/2389))

## 3.33.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public static IServiceCollection AddSentry<TOptions>(this IServiceCollection ser

// Custom handler for HttpClientFactory.
// Must be singleton: https://github.com/getsentry/sentry-dotnet/issues/785
services.TryAddSingleton<IHttpMessageHandlerBuilderFilter, SentryHttpMessageHandlerBuilderFilter>();
// Must use AddSingleton: https://github.com/getsentry/sentry-dotnet/issues/2373
services.AddSingleton<IHttpMessageHandlerBuilderFilter, SentryHttpMessageHandlerBuilderFilter>();

return services;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,13 @@ public Action<HttpMessageHandlerBuilder> Configure(Action<HttpMessageHandlerBuil
handlerBuilder =>
{
var hub = _getHub();
handlerBuilder.AdditionalHandlers.Add(new SentryHttpMessageHandler(hub));
if (!handlerBuilder.AdditionalHandlers.Any(h => h is SentryHttpMessageHandler))
{
handlerBuilder.AdditionalHandlers.Add(
new SentryHttpMessageHandler(hub)
);
}
next(handlerBuilder);
};
}

0 comments on commit dcc32b2

Please sign in to comment.