fix: suppress OperationCanceledException APM errors during pod shutdown (5.7.4)#115
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
Prevents
OperationCanceledExceptionraised during pod graceful shutdown from being recorded as APM errors.Context
5.7.3 (PR #114) broadened the
ReceiverWrapperguard to suppressLogErrorentries on shutdown. However, APM errors persisted in production. Root cause: Elastic APM's Azure Service Bus auto-instrumentation (viaWithAllSubscribers()) captures transaction errors at theDiagnosticSource/Activitylevel -- upstream ofReceiverWrapper, so the guard has no effect on the APM channel.Changes
Ev.ServiceBus.Abstractions/Listeners/ICancellationAwareTransactionManager.cs-- new optional interface thatITransactionManagerimplementations can implement to react to receive-loop cancellationsEv.ServiceBus/Management/Wrappers/ReceiverWrapper.cs-- callsOnReceiveCancelled()via runtime cast in the cancellation guardEv.ServiceBus.Apm/ApmTransactionManager.cs-- implementsICancellationAwareTransactionManager; sets current APM transactionOutcome = Successto override the error state set by Azure SDK auto-instrumentationEv.ServiceBus.UnitTests/ReceiverWrapperTests.cs-- 2 new tests:OnReceiveCancelledcalled on cancellation, not called on other exceptions