fix: suppress OperationCanceledException APM errors during pod shutdown (5.7.3–5.7.5)#115
Merged
Merged
Conversation
…wn (5.7.4) Added ICancellationAwareTransactionManager to Ev.ServiceBus.Abstractions — an optional interface for ITransactionManager implementations that need to react to receive-loop cancellations. ApmTransactionManager implements it by setting the current Elastic APM transaction outcome to Success, overriding the error state set by the Azure SDK auto-instrumentation. ReceiverWrapper calls OnReceiveCancelled() via a runtime cast inside the existing cancellation guard. The 5.7.3 guard already prevented LogError for shutdown cancellations; this fix closes the remaining gap where APM errors were still recorded through the Elastic APM agent's Azure Service Bus DiagnosticSource instrumentation.
1c4ad2b to
f791407
Compare
|
Looks good |
benspeth
approved these changes
Jun 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Three related fixes to eliminate
TaskCanceledException/OperationCanceledExceptionnoise generated during pod graceful shutdown.5.7.3 — Broadened shutdown guard (
ReceiverWrapper)The previous guard checked
oce.CancellationToken.IsCancellationRequested, which is alwaysfalsebecause the Azure SDK raisesProcessErrorAsyncwithCancellationToken.Noneduring processor shutdown. Guard now matches anyOperationCanceledException.5.7.4 — Override APM transaction outcome (
ICancellationAwareTransactionManager)Added
ICancellationAwareTransactionManager— an optional interfaceITransactionManagerimplementations can implement to react to receive-loop cancellations.ApmTransactionManagersetsOutcome = Successto override the error state on the transaction.5.7.5 — Suppress APM error events via filter
Outcome = Successalone was insufficient: Elastic APM captures error events at theDiagnosticSourcelevel — beforeReceiverWrapperruns — so the error document was already queued regardless of the outcome override. 5.7.5 registers a one-timeAgent.AddFilter(IError)that drops error events whoseTransactionIdbelongs to a cancelled-receive transaction, preventing them from reaching the APM server.Changes
Ev.ServiceBus.Abstractions/Listeners/ICancellationAwareTransactionManager.cs— new optional interfaceEv.ServiceBus/Management/Wrappers/ReceiverWrapper.cs— broadened guard +OnReceiveCancelled()callEv.ServiceBus.Apm/ApmTransactionManager.cs— implementsICancellationAwareTransactionManager; setsOutcome = Successand registers error filterEv.ServiceBus.UnitTests/ReceiverWrapperTests.cs— 2 new tests