public static async Task RecordSend(RedisSettings usedSettings, RedisKey key, string callType, Func <Task <MonitorSingle> > executeAndReturnSentObject, [CallerMemberName] string commandName = "") { var tracerFactory = usedSettings.CommandTracerFactory; ICommandTracer tracer = null; if (tracerFactory != null) { tracer = tracerFactory(); var command = callType + "." + commandName; tracer.CommandStart(usedSettings, command, key); // start within context } MonitorSingle sentObject = null; bool isError = true; try { sentObject = await executeAndReturnSentObject().ForAwait(); isError = false; } finally { if (tracer != null) { tracer.CommandFinish(sentObject?.SentObject, sentObject?.SentSize ?? 0, null, 0, isError); // finish without context } } }
public static async Task <T> RecordReceive <T>(RedisSettings usedSettings, RedisKey key, string callType, Func <Task <MonitorSingle <T> > > executeAndReturnReceivedObject, [CallerMemberName] string commandName = "") { var tracerFactory = usedSettings.CommandTracerFactory; ICommandTracer tracer = null; if (tracerFactory != null) { tracer = tracerFactory(); var command = callType + "." + commandName; tracer.CommandStart(usedSettings, command, key); // start within context } MonitorSingle <T> receivedObject = null; bool isError = true; try { receivedObject = await executeAndReturnReceivedObject().ForAwait(); isError = false; } finally { if (tracer != null) { tracer.CommandFinish(null, 0, (receivedObject != null) ? receivedObject.ReceivedObject : default(T), receivedObject?.ReceivedSize ?? 0, isError); // finish without context } } return((receivedObject == null) ? default(T) : receivedObject.ReceivedObject); }