Due to the async MongoDb commands not sticking to the same async flow the Activity.Current could be changed when the CommandSucceededEvent or CommandFailedEvent are handled. In order for the span to end correctly the change is replacing the Activity.Current, ends the span and then restores the Activity.Current to the previous state.
Due to the async MongoDb commands not sticking to the same async flow the Activity.Current could be changed when the CommandSucceededEvent or CommandFailedEvent are handled. In order for the span to end correctly the change is replacing the Activity.Current, ends the span and then restores the Activity.Current to the previous state.