Skip to content

Commit

Permalink
[Service Bus] Enhance logging for session timeouts (Azure#46388)
Browse files Browse the repository at this point in the history
* [Service Bus] Enhance logging for session timeouts

The focus of these changes is to enhance the logs
emitted when acquiring a session using the `ServiceBusReceiver`
times out or is canceled.  As these are known and
expected exception conditions, they should be logged
as verbose information rather than an error.

Previously, these scenarios were special-cased for
processors, but receivers were treated as standard
errors.  Going forward, the processor and receiver
scenarios are handled consistently.
  • Loading branch information
jsquire authored Oct 2, 2024
1 parent b738ffe commit 360cfb9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,9 @@ protected ServiceBusEventSource() : base(EventSourceName)
internal const int PurgeMessagesCompleteEvent = 120;
internal const int PurgeMessagesExceptionEvent = 121;

internal const int ReceiverAcceptSessionTimeoutEvent = 122;
internal const int ReceiverAcceptSessionCanceledEvent = 123;

#endregion
// add new event numbers here incrementing from previous

Expand Down Expand Up @@ -347,6 +350,27 @@ public virtual void ReceiveDeferredMessageException(string identifier, string ex
WriteEvent(ReceiveDeferredMessageExceptionEvent, identifier, exception);
}
}

[Event(ReceiverAcceptSessionCanceledEvent, Level = EventLevel.Verbose, Message = "An accept session operation for a receiver was canceled. (Namespace '{0}', Entity path '{1}'). Error Message: '{2}'")]
public void ReceiverAcceptSessionCanceled(string fullyQualifiedNamespace, string entityPath, string exception)
{
if (IsEnabled())
{
WriteEvent(ReceiverAcceptSessionCanceledEvent, fullyQualifiedNamespace, entityPath, exception);
}
}

[Event(ReceiverAcceptSessionTimeoutEvent, Level = EventLevel.Verbose, Message = "The receiver accept session call timed out. (Namespace '{0}', Entity path '{1}'). Error Message: '{2}'")]
public virtual void ReceiverAcceptSessionTimeout(
string fullyQualifiedNamespace,
string entityPath,
string exception)
{
if (IsEnabled())
{
WriteEvent(ReceiverAcceptSessionTimeoutEvent, fullyQualifiedNamespace, entityPath, exception);
}
}
#endregion

#region Peeking
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,34 @@ internal static async Task<ServiceBusSessionReceiver> CreateSessionReceiverAsync
return receiver;
}
catch (ServiceBusException e)
when (e.Reason == ServiceBusFailureReason.ServiceTimeout && isProcessor)
when (e.Reason == ServiceBusFailureReason.ServiceTimeout)
{
await receiver.CloseAsync(CancellationToken.None).ConfigureAwait(false);
receiver.Logger.ProcessorAcceptSessionTimeout(receiver.FullyQualifiedNamespace, entityPath, e.ToString());

if (isProcessor)
{
receiver.Logger.ProcessorAcceptSessionTimeout(receiver.FullyQualifiedNamespace, entityPath, e.ToString());
}
else
{
receiver.Logger.ReceiverAcceptSessionTimeout(receiver.FullyQualifiedNamespace, entityPath, e.ToString());
}

throw;
}
catch (TaskCanceledException exception)
when (isProcessor)
{
await receiver.CloseAsync(CancellationToken.None).ConfigureAwait(false);
receiver.Logger.ProcessorStoppingAcceptSessionCanceled(receiver.FullyQualifiedNamespace, entityPath, exception.ToString());

if (isProcessor)
{
receiver.Logger.ProcessorStoppingAcceptSessionCanceled(receiver.FullyQualifiedNamespace, entityPath, exception.ToString());
}
else
{
receiver.Logger.ReceiverAcceptSessionCanceled(receiver.FullyQualifiedNamespace, entityPath, exception.ToString());
}

throw;
}
catch (Exception ex)
Expand Down

0 comments on commit 360cfb9

Please sign in to comment.