jbogard / MongoDB.Driver.Core.Extensions.DiagnosticSources

Apache License 2.0
46 stars 18 forks source link

Resolves issue with unexpected InvalidOperationExceptions #32

Closed NorekZ closed 2 months ago

NorekZ commented 3 months ago

Hello.

This PR resolves issue #30.

The problem is that DiagnosticsActivityEventSubscriber wants to return previously captured current activity to Activity.Current property again. In the Activity.Current setter there is a check that fails when the activity is stopped. When the "parent" activity is stopped in the meanwhile, exception is thrown.

The same code raises the exception also when you call a sync version of a mongo command. In this case, command's activity is the same as the Activity.Current activity. Inside action(), activity gets stopped, and afterwards activity is again assigned to Activity.Current property.

Both issues should be fixed by this PR.

Thanks.