Attempt fix for issue #2357 "Failed to detach context" exception for grpc instrumentation #3893
      
        
          +14
        
        
          −1
        
        
          
        
      
    
  
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Description
Attempt fix for the 2357
The context switching is causing problems, for whatever reason, the grpc streaming interceptor flow is triggered, altho most of the time when the error pop up, there is no streaming endpoint involved, the open source lib's interceptor seems having a genuine problem for handling context switching:
The fix here is to manually create the span and end it as necessary, thus there is no context manager and context token involved at all. Tested in production for my service, with the fix, there is no such error popes up again.
Fixes #2357
Type of change
Please delete options that are not relevant.
How Has This Been Tested?
There is no easy way to reproduce this, the error is constantly and consistently showing up in my service, after this patch, the error is gone and all the tracing functions as before.
Checklist:
See contributing.md for styleguide, changelog guidelines, and more.