Skip to content

Commit 360cfb9

Browse files
authored
[Service Bus] Enhance logging for session timeouts (#46388)
* [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.
1 parent b738ffe commit 360cfb9

File tree

2 files changed

+45
-4
lines changed

2 files changed

+45
-4
lines changed

sdk/servicebus/Azure.Messaging.ServiceBus/src/Diagnostics/ServiceBusEventSource.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ protected ServiceBusEventSource() : base(EventSourceName)
204204
internal const int PurgeMessagesCompleteEvent = 120;
205205
internal const int PurgeMessagesExceptionEvent = 121;
206206

207+
internal const int ReceiverAcceptSessionTimeoutEvent = 122;
208+
internal const int ReceiverAcceptSessionCanceledEvent = 123;
209+
207210
#endregion
208211
// add new event numbers here incrementing from previous
209212

@@ -347,6 +350,27 @@ public virtual void ReceiveDeferredMessageException(string identifier, string ex
347350
WriteEvent(ReceiveDeferredMessageExceptionEvent, identifier, exception);
348351
}
349352
}
353+
354+
[Event(ReceiverAcceptSessionCanceledEvent, Level = EventLevel.Verbose, Message = "An accept session operation for a receiver was canceled. (Namespace '{0}', Entity path '{1}'). Error Message: '{2}'")]
355+
public void ReceiverAcceptSessionCanceled(string fullyQualifiedNamespace, string entityPath, string exception)
356+
{
357+
if (IsEnabled())
358+
{
359+
WriteEvent(ReceiverAcceptSessionCanceledEvent, fullyQualifiedNamespace, entityPath, exception);
360+
}
361+
}
362+
363+
[Event(ReceiverAcceptSessionTimeoutEvent, Level = EventLevel.Verbose, Message = "The receiver accept session call timed out. (Namespace '{0}', Entity path '{1}'). Error Message: '{2}'")]
364+
public virtual void ReceiverAcceptSessionTimeout(
365+
string fullyQualifiedNamespace,
366+
string entityPath,
367+
string exception)
368+
{
369+
if (IsEnabled())
370+
{
371+
WriteEvent(ReceiverAcceptSessionTimeoutEvent, fullyQualifiedNamespace, entityPath, exception);
372+
}
373+
}
350374
#endregion
351375

352376
#region Peeking

sdk/servicebus/Azure.Messaging.ServiceBus/src/Receiver/ServiceBusSessionReceiver.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,34 @@ internal static async Task<ServiceBusSessionReceiver> CreateSessionReceiverAsync
8282
return receiver;
8383
}
8484
catch (ServiceBusException e)
85-
when (e.Reason == ServiceBusFailureReason.ServiceTimeout && isProcessor)
85+
when (e.Reason == ServiceBusFailureReason.ServiceTimeout)
8686
{
8787
await receiver.CloseAsync(CancellationToken.None).ConfigureAwait(false);
88-
receiver.Logger.ProcessorAcceptSessionTimeout(receiver.FullyQualifiedNamespace, entityPath, e.ToString());
88+
89+
if (isProcessor)
90+
{
91+
receiver.Logger.ProcessorAcceptSessionTimeout(receiver.FullyQualifiedNamespace, entityPath, e.ToString());
92+
}
93+
else
94+
{
95+
receiver.Logger.ReceiverAcceptSessionTimeout(receiver.FullyQualifiedNamespace, entityPath, e.ToString());
96+
}
97+
8998
throw;
9099
}
91100
catch (TaskCanceledException exception)
92-
when (isProcessor)
93101
{
94102
await receiver.CloseAsync(CancellationToken.None).ConfigureAwait(false);
95-
receiver.Logger.ProcessorStoppingAcceptSessionCanceled(receiver.FullyQualifiedNamespace, entityPath, exception.ToString());
103+
104+
if (isProcessor)
105+
{
106+
receiver.Logger.ProcessorStoppingAcceptSessionCanceled(receiver.FullyQualifiedNamespace, entityPath, exception.ToString());
107+
}
108+
else
109+
{
110+
receiver.Logger.ReceiverAcceptSessionCanceled(receiver.FullyQualifiedNamespace, entityPath, exception.ToString());
111+
}
112+
96113
throw;
97114
}
98115
catch (Exception ex)

0 commit comments

Comments
 (0)