Eventuous/eventuous

"Can not start an Activity that was already started" in BaseProducer

gius opened this issue · 0 comments

gius commented

Describe the bug
When producing an event, System.InvalidOperationException: '"Can not start an Activity that was already started"' is thrown (and immediately swallowed) by System.Diagnostics.DiagnosticSource.dll!System.Diagnostics.Activity.NotifyError(System.Exception exception).

The reason is that in BaseProducer.Produce, we explicitly call act?.Start(), but the activity has already been started by the previous line's call to ProducerActivity.Start.

var (act, producedMessage) = ProducerActivity.Start(messagesArray[0], DefaultTags);
return (act?.Start(), new[] { producedMessage });

To Reproduce
Steps to reproduce the behavior:

  1. Enable Break When Thrown for System.InvalidOperationException in Visual Studio's Exception Settings
  2. Publish an event through RabbitMqProducer
  3. See error

Expected behavior
No exception should be thrown.

I can provide a PR if you want. As far as I can understand, simply changing

return (act?.Start(), new[] { producedMessage });
to return (act, new[] { producedMessage }); should be enough.