The SagaAudit plugin enables the Saga View feature in ServiceInsight.
It is built specifically to help developers verify saga logic during development. It does this by capturing saga message behavior and changes in saga data/state as the saga is being processed. It then sends this information to a ServiceControl instance set up in the development environment. The information is available in the Saga view in ServiceInsight.
Implementation
The SagaAudit plugin captures the following information:
- The incoming messages (including timeouts) that initiate change in the saga
- The outgoing messages that the saga sends
- A snapshot of the current saga state
ServiceControl Queue
(the input queue of the main ServiceControl instance). Starting with version 4.13.0, the saga state change data can also be processed by the ServiceControl audit instance via the audit
queue. The latter approach is recommended.All this information is sent to and stored in ServiceControl. Note that the saga state audit data is transmitted to ServiceControl via a separate message and is serialized using the built in JSON Serializer of NServiceBus.
Impact on ServiceControl performance
This plugin results in an increase in load in several areas:
- Endpoint load in order to capture the required information
- Network load due to the extra information sent to ServiceControl
- ServiceControl load in the areas of ingestion, correlation and data cleanup
The increase in load is proportional to size of the saga data multiplied by the number of messages the the saga receives. Since both these variables are dependent on the specific saga implementation it is not possible to give accurate predictions on the impact of this load in a production system. In versions of ServiceControl prior to 4.13.0, do not run SagaAudit plugin in production environments due to the increased load on the main ServiceControl instance. Starting with version 4.13.0, audit instances can process saga state change information from the SagaAudit plugin. In case the additional load from the SagaAudit plugin is too big for a single audit instance to handle, consider scaling out ServiceControl audit processing.
Configuration
The SagaAudit plugin is enabled via:
var endpointConfiguration = new EndpointConfiguration("MyEndpoint");
//For ServiceControl 4.13.0 and later
endpointConfiguration.AuditSagaStateChanges(
serviceControlQueue: "audit@machine");
//For previous versions of ServiceControl
endpointConfiguration.AuditSagaStateChanges(
serviceControlQueue: "particular.servicecontrol@machine");
Custom serialization
The SagaAudit plugin serializes the saga data objects using a simple json serializer. This serializer should be fine for most use cases. It handles all primitive types (including TimeSpan
and DateTime
), their nullable variants as well as nested objects. However, if more sophisticated mechanism is required, the serialization method can be provided by the user:
var endpointConfiguration = new EndpointConfiguration("MyEndpoint");
endpointConfiguration.AuditSagaStateChanges(
serviceControlQueue: "particular.servicecontrol@machine",
customSagaEntitySerialization: saga =>
{
var data = (MySagaData) saga;
var dictionary = new Dictionary<string, string>
{
["prop1"] = data.Name,
["prop2"] = data.Address
};
return dictionary;
});