We have written a custom pipeline behavior to plug into a telemetry platform (DataDog). Currently every message that has an exception marks the span as failed. But what we really want to do is only mark the span as failed if its about to go to the error queue. Is there a way to do that?
Here is the gist of what the behavior does
public override async Task Invoke(ITransportReceiveContext context, Func<Task> next)
{
using (var scope = Tracer.Instance.StartActive("nservicebus.receive_message")
{
scope.Span.ResourceName = GetEnclosedMessageType(context);
scope.Span.Type = "nservicebus";
try
{
await next().ConfigureAwait(false);
}
catch (Exception ex)
{
scope.Span.SetException(ex); // we only want to do this if it is failed
throw;
}
}
}