Track requests and dependencies from ServiceBus #740
Description
openedon Nov 13, 2017
ServiceBus .NET Client (version 2.1.0) vas instrumented with DiagnosticsSource and Activity.
ServiceBus is a messaging (queue) service, it implements AMQP protocol, and cannot be tracked with HTTP dependency collection.
Typical ServiceBus .Net Client scenario usage:
// Sends message on producer side
queueClient.SendAsync(message);
// process message on consumer side
queueClient.RegisterMessageHandler(
(message, ct) => await Process(message),
(exceptionArgs) => Task.CompletedTask);
This scenario translates into the 3 telemetry items to be collected:
- Send - dependency
- Receive - dependency
- Process - request
There are several other instrumented operations, see Azure/azure-service-bus-dotnet#370
Instrumentation can be hooked with TelemetryDiagnosticSourceListener
generic listener, however, some customization is needed to make sure all useful data is properly collected:
- We need to collect Requests (message processing).
- Correctly map activity properties and diagnostic source events to AI telemetry
ServiceBus telemetry properties
Dependencies:
SB operations that are tracked as depednency:
- MessageSender (i.e. QueueClient and TopicClient): SendAsync, ScheduleMessage and CancelScheduledMessage
- MessageReceiver: Receive, ReceiveDeffered, Peek, Abandon, Defer, Complete, DeadLetter, RenewLock
MessageSession: AcceptMessageSession - SubscriptionClient : AddRule, RemoveRule, GetRules
Corresponding dependencies will have following properties:
- Target: 'endpoint | entityPath' (sb://myservicebus.servicebus.windows.net/ | myqueue")
- Type: 'Azure Service Bus'
- Name: Operation name (i.e.
Send
orAddRule
)
Requests
Operations that are tracked as requests:
Processing messages with QueueClient.RegisterMessageHandler
and QueueClient.RegisterSessionHandler
RequestTelemetry will have following properties:
- Name: operation name - 'Process' or 'ProcessSession'
- Source: 'type: Azure Service Bus | name:myqueue | endpoint:sb://myservicebus.servicebus.windows.net/'
Telemetry also must have timestamp, duration, correlation identifiers and success (bool) property.
In case if ServiceBus message/operation had MessageId or SessionId associated with it, it will be added to custom properties.