Skip to content

fix: suppress OperationCanceledException APM errors during pod shutdown (5.7.3–5.7.5)#115

Merged
benspeth merged 1 commit into
masterfrom
teams/core/209/task/446605
Jun 11, 2026
Merged

fix: suppress OperationCanceledException APM errors during pod shutdown (5.7.3–5.7.5)#115
benspeth merged 1 commit into
masterfrom
teams/core/209/task/446605

Conversation

@ecofrankie

@ecofrankie ecofrankie commented Jun 10, 2026

Copy link
Copy Markdown
Collaborator

Summary

Three related fixes to eliminate TaskCanceledException / OperationCanceledException noise generated during pod graceful shutdown.

5.7.3 — Broadened shutdown guard (ReceiverWrapper)

The previous guard checked oce.CancellationToken.IsCancellationRequested, which is always false because the Azure SDK raises ProcessErrorAsync with CancellationToken.None during processor shutdown. Guard now matches any OperationCanceledException.

5.7.4 — Override APM transaction outcome (ICancellationAwareTransactionManager)

Added ICancellationAwareTransactionManager — an optional interface ITransactionManager implementations can implement to react to receive-loop cancellations. ApmTransactionManager sets Outcome = Success to override the error state on the transaction.

5.7.5 — Suppress APM error events via filter

Outcome = Success alone was insufficient: Elastic APM captures error events at the DiagnosticSource level — before ReceiverWrapper runs — so the error document was already queued regardless of the outcome override. 5.7.5 registers a one-time Agent.AddFilter(IError) that drops error events whose TransactionId belongs to a cancelled-receive transaction, preventing them from reaching the APM server.

Changes

  • Ev.ServiceBus.Abstractions/Listeners/ICancellationAwareTransactionManager.cs — new optional interface
  • Ev.ServiceBus/Management/Wrappers/ReceiverWrapper.cs — broadened guard + OnReceiveCancelled() call
  • Ev.ServiceBus.Apm/ApmTransactionManager.cs — implements ICancellationAwareTransactionManager; sets Outcome = Success and registers error filter
  • Ev.ServiceBus.UnitTests/ReceiverWrapperTests.cs — 2 new tests

…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.
@ecofrankie ecofrankie force-pushed the teams/core/209/task/446605 branch from 1c4ad2b to f791407 Compare June 10, 2026 10:23
@ecofrankie ecofrankie requested a review from benspeth June 10, 2026 10:26
@ecofrankie ecofrankie changed the title fix: suppress OperationCanceledException APM errors during pod shutdown (5.7.3 + 5.7.4) fix: suppress OperationCanceledException APM errors during pod shutdown (5.7.4) Jun 10, 2026
@ecofrankie ecofrankie self-assigned this Jun 10, 2026
@sokrates209 sokrates209 reopened this Jun 10, 2026
@sokrates209

Copy link
Copy Markdown

Looks good

@benspeth benspeth merged commit f0e645f into master Jun 11, 2026
2 checks passed
@ecofrankie ecofrankie changed the title fix: suppress OperationCanceledException APM errors during pod shutdown (5.7.4) fix: suppress OperationCanceledException APM errors during pod shutdown (5.7.3–5.7.5) Jun 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants