getsentry / getsentry/sentry-dotnet

Add Microsoft.Extensions.Http.Resilience support (disable failed request logging)

Open
#4,418 18 comments 0 reactions 0 assignees View on GitHub
.NET Improvement Logs Microsoft.Extensions.Logging Needs Reproduction
Dominant language
C#
Stars
770
Forks
248
Avg merge
3d 4h
Merged PRs (30d)
49

Description

### Problem Statement

We use Microsoft.Extensions.Http.Resilience with IHttpClientFactory in our Maui app, and every time a request fails, it is logged in Sentry.
What we set:
`options.CaptureFailedRequests = false;`
But unfortunately, that doesn't help.
It would be great if we could disable logging of failed requests when using Microsoft.Extensions.Http.Resilience ([https://learn.microsoft.com/en-us/dotnet/core/resilience/http-resilience?tabs=dotnet-cli]()).

The stacks look like this

```
?, in void Logger.Log(LogLevel, EventId, TState, Exception, Func)+LoggerLog(LogLevel, EventId, ILogger, Exception, Func<__ResilienceEventStruct, Exception, string>, ref List, in __ResilienceEventStruct)
?, in void Logger.Log<__ResilienceEventStruct>(LogLevel, EventId, __ResilienceEventStruct, Exception, Func<__ResilienceEventStruct, Exception, string>)
?, in void Log.ResilienceEvent(ILogger, LogLevel, string, string, string, string, string, object, Exception)
?, in void TelemetryListenerImpl.LogEvent(in TelemetryEventArguments, ResilienceEventSeverity)
?, in void TelemetryListenerImpl.Write(in TelemetryEventArguments)
?, in void ResilienceStrategyTelemetry.Report(ResilienceEvent, ResilienceContext, OnTimeoutArguments)
?, in async void d__12>.MoveNext()
?, in void AsyncStateMachineBox<d__12>>.ExecutionContextCallback(object s)
?, in void AsyncStateMachineBox<d__12>>.MoveNext(Thread) x 2
?, in void AwaitTaskContinuation.RunOrScheduleAction(IAsyncStateMachineBox, bool)
?, in void Task.RunContinuations(object)
?, in void Task.FinishContinuations()
?, in bool Task>.TrySetResult(Outcome)
?, in void AsyncTaskMethodBuilder>.SetExistingTaskResult(Task>, Outcome)
?, in void AsyncValueTaskMethodBuilder>.SetResult(Outcome)
?, in async void <g__AwaitTask|0_0>d, HttpResponseMessage>.MoveNext()
?, in void AsyncStateMachineBox<<g__AwaitTask|0_0>d, HttpResponseMessage>>.ExecutionContextCallback(object s)
?, in void AsyncStateMachineBox<<g__AwaitTask|0_0>d, HttpResponseMessage>>.MoveNext(Thread) x 2
?, in void AwaitTaskContinuation.RunOrScheduleAction(IAsyncStateMachineBox, bool)
?, in void Task.RunContinuations(object)
?, in void Task.FinishContinuations()
?, in bool Task>.TrySetResult(Outcome)
?, in void AsyncTaskMethodBuilder>.SetExistingTaskResult(Task>, Outcome)
?, in void AsyncValueTaskMethodBuilder>.SetResult(Outcome)
?, in async Task ResilienceHandler.SendAsync(HttpRequestMessage, CancellationToken)+(?) => { }
?, in void AsyncStateMachineBox<<b__3_0>d>.ExecutionContextCallback(object s)
?, in void AsyncStateMachineBox<<b__3_0>d>.MoveNext(Thread) x 2
?, in void AwaitTaskContinuation.RunOrScheduleAction(IAsyncStateMachineBox, bool)
?, in void Task.RunContinuations(object)
?, in void Task.FinishContinuations()
?, in void Task.FinishStageThree()
?, in void Task.CancellationCleanupLogic()
?, in bool Task.TrySetCanceled(CancellationToken, object)
?, in void AsyncTaskMethodBuilder.SetException(Exception, ref Task)
?, in void AsyncValueTaskMethodBuilder.SetException(Exception)
?, in async ValueTask RedirectHandler.SendAsync(HttpRequestMessage, bool, CancellationToken)
?, in void AsyncStateMachineBox<d__4>.ExecutionContextCallback(object s)
?, in void AsyncStateMachineBox<d__4>.MoveNext(Thread) x 2
?, in void AwaitTaskContinuation.RunOrScheduleAction(IAsyncStateMachineBox, bool)
?, in void Task.RunContinuations(object)
?, in void Task.FinishContinuations()
?, in void Task.FinishStageThree()
?, in void Task.CancellationCleanupLogic()
?, in bool Task.TrySetCanceled(CancellationToken, object)
?, in void AsyncTaskMethodBuilder.SetException(Exception, ref Task)
?, in void AsyncValueTaskMethodBuilder.SetException(Exception)
?, in async ValueTask AuthenticationHelper.SendWithAuthAsync(HttpRequestMessage, Uri, bool, ICredentials, bool, bool, bool, HttpConnectionPool, CancellationToken)
?, in void AsyncStateMachineBox<d__17>.ExecutionContextCallback(object s)
?, in void AsyncStateMachineBox<d__17>.MoveNext(Thread) x 2
?, in void AwaitTaskContinuation.RunOrScheduleAction(IAsyncStateMachineBox, bool)
?, in void Task.RunContinuations(object)
?, in void Task.FinishContinuations()
?, in void Task.FinishStageThree()
?, in void Task.CancellationCleanupLogic()
?, in bool Task.TrySetCanceled(CancellationToken, object)
?, in void AsyncTaskMethodBuilder.SetException(Exception, ref Task)
?, in void AsyncValueTaskMethodBuilder.SetException(Exception)
?, in async ValueTask HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage, bool, bool, CancellationToken)
?, in void AsyncStateMachineBox<d__50>.ExecutionContextCallback(object s)
?, in void AsyncStateMachineBox<d__50>.MoveNext(Thread) x 2
?, in void AwaitTaskContinuation.RunOrScheduleAction(IAsyncStateMachineBox, bool)
?, in void Task.RunContinuations(object)
?, in void Task.FinishContinuations()
?, in void Task.FinishStageThree()
?, in void Task.CancellationCleanupLogic()
?, in bool Task.TrySetCanceled(CancellationToken, object)
?, in void AsyncTaskMethodBuilder.SetException(Exception, ref Task) x 2
?, in async Task AuthenticationHelper.SendWithNtAuthAsync(HttpRequestMessage, Uri, bool, ICredentials, TokenImpersonationLevel, bool, HttpConnection, HttpConnectionPool, CancellationToken)
?, in void AsyncStateMachineBox<d__52>.ExecutionContextCallback(object s)
?, in void AsyncStateMachineBox<d__52>.MoveNext(Thread) x 2
?, in void AwaitTaskContinuation.RunOrScheduleAction(IAsyncStateMachineBox, bool)
?, in void Task.RunContinuations(object)
?, in void Task.FinishContinuations()
?, in void Task.FinishStageThree()
?, in void Task.CancellationCleanupLogic()
?, in bool Task.TrySetCanceled(CancellationToken, object)
?, in void AsyncTaskMethodBuilder.SetException(Exception, ref Task) x 2
?, in async Task HttpConnection.SendAsync(HttpRequestMessage, bool, CancellationToken)
?, in void AsyncStateMachineBox<d__56>.ExecutionContextCallback(object s)
?, in void AsyncStateMachineBox<d__56>.MoveNext(Thread) x 2
?, in void ThreadPool.s_invokeAsyncStateMachineBox(object state)
?, in void ManualResetValueTaskSourceCore.SignalCompletion()
?, in void ManualResetValueTaskSourceCore.SetException(Exception)
?, in void StateMachineBox.SetException(Exception)
?, in void PoolingAsyncValueTaskMethodBuilder.SetException(Exception, ref StateMachineBox) x 2
?, in async void d__170.MoveNext()
?, in void StateMachineBox<d__170>.ExecutionContextCallback(object s)
?, in void StateMachineBox<d__170>.MoveNext()
?, in void ThreadPool.s_invokeAsyncStateMachineBox(object state)
?, in void ManualResetValueTaskSourceCore.SignalCompletion()
?, in void ManualResetValueTaskSourceCore.SetException(Exception)
?, in void StateMachineBox.SetException(Exception)
?, in void PoolingAsyncValueTaskMethodBuilder.SetException(Exception, ref StateMachineBox) x 2
?, in async void d__168.MoveNext()
?, in void StateMachineBox<d__168>.ExecutionContextCallback(object s)
?, in void StateMachineBox<d__168>.MoveNext()
?, in void ThreadPool.s_invokeAsyncStateMachineBox(object state)
?, in void ManualResetValueTaskSourceCore.SignalCompletion()
?, in void ManualResetValueTaskSourceCore.SetResult(bool)
?, in void AwaitableSocketAsyncEventArgs.OnCompleted(SocketAsyncEventArgs)
?, in void SocketAsyncEventArgs.OnCompletedInternal()
?, in void SocketAsyncEventArgs.FinishOperationAsyncSuccess(int, SocketFlags)
?, in void SocketAsyncEventArgs.CompletionCallback(int, SocketFlags, SocketError)
?, in void SocketAsyncEventArgs.TransferCompletionCallbackCore(int bytesTransferred, Memory socketAddress, SocketFlags receivedFlags, SocketError socketError)
?, in void BufferMemoryReceiveOperation.InvokeCallback(bool)
?, in void OperationQueue.ProcessAsyncOperation(ReadOperation)
?, in void SocketAsyncContext.ProcessAsyncReadOperation(ReadOperation)
?, in void ReadOperation.System.Threading.IThreadPoolWorkItem.Execute()
?, in void AsyncOperation.Process()
?, in void SocketAsyncContext.HandleEvents(SocketEvents)
?, in void SocketAsyncEngine.System.Threading.IThreadPoolWorkItem.Execute()
?, in bool ThreadPoolWorkQueue.Dispatch()
?, in void WorkerThread.WorkerThreadStart()
?, in void Thread.StartCallback()
```

### Solution Brainstorm

*No response*

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.