jbogard / MongoDB.Driver.Core.Extensions.DiagnosticSources

Apache License 2.0
46 stars 18 forks source link

Parallel activities failing test and fix #3

Closed dgrozenok closed 3 years ago

dgrozenok commented 4 years ago

In order to reproduce an issue with the parallel activities I added the stricter assertion to the unit test to verify that not only there are the total of 4 activities added to the collection, but all of them are actually command related activities. As the result the test failed due to the fact that when the first activity stopped the Activity.Current became the outer activity and while handling the command succeeded event that wrong activity was collected. This is how the OpenTelemetry pulls the activity in their integration with the diagnostics and that's why the correct Activity.Current is important (https://github.com/open-telemetry/opentelemetry-dotnet/blob/7863cee67a7efc62bb57cd20ceb7351d8757f884/src/OpenTelemetry/Instrumentation/DiagnosticSourceListener.cs#L61).

In order to fix the failing test I added a couple of lines to save the current activity into a temp, setting it to being stopped activity and after stopping it returning to the previous activity.

dgrozenok commented 3 years ago

Will create a new one with a clean change.