@Yana Lysenkova Welcome to Microsoft Q&A Forum, Thank you for posting your query here!
I understand that you had faced performance issue in your Azure Service Bus resource, so you want to check how long it took to process the message.
You can rely on the below Azure Service Bus metrics:
You can view these metrics by going to Azure Portal. Search for Monitor and select Monitor.
On the left menu, select Service Bus (preview).
Using these metrics you can observe the trend and try to isolate the performance issue.
More info here.
App Insights:
Also if you have the right telemetry tracing enabled within your application to send the logs to Application Insights, you can leverage that. If you use ProcessMessageAsync
of ServiceBusProcessor
(message handler pattern) to process messages, the message processing is also instrumented. All Service Bus calls done by your service are automatically tracked and correlated with other telemetry items.
async Task ProcessAsync(ProcessMessageEventArgs args)
{
ServiceBusReceivedMessage message = args.Message;
if (message.ApplicationProperties.TryGetValue("Diagnostic-Id", out var objectId) && objectId is string diagnosticId)
{
var activity = new Activity("ServiceBusProcessor.ProcessMessage");
activity.SetParentId(diagnosticId);
// If you're using Microsoft.ApplicationInsights package version 2.6-beta or higher, you should call StartOperation<RequestTelemetry>(activity) instead
using (var operation = telemetryClient.StartOperation<RequestTelemetry>("Process", activity.RootId, activity.ParentId))
{
telemetryClient.TrackTrace("Received message");
try
{
// process message
}
catch (Exception ex)
{
telemetryClient.TrackException(ex);
operation.Telemetry.Success = false;
throw;
}
telemetryClient.TrackTrace("Done");
}
}
}
In case you make calls to supported external components during message processing, they're also automatically tracked and correlated. Refer to Track custom operations with Application Insights .NET SDK for manual tracking and correlation.
If you're running any external code in addition to the Application Insights SDK, expect to see longer duration when viewing Application Insights logs as shown below:
Sharing a few related and useful articles on this topic:
https://zcusa.951200.xyz/en-us/azure/service-bus-messaging/service-bus-end-to-end-tracing?tabs=net-standard-sdk-2#service-bus-net-client-autotracing
https://zcusa.951200.xyz/en-us/azure/service-bus-messaging/service-bus-insights
Hope this helps.
**
Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.