File tree Expand file tree Collapse file tree 1 file changed +10
-6
lines changed 
instrumentation/opentelemetry-instrumentation-pymongo/src/opentelemetry/instrumentation/pymongo Expand file tree Collapse file tree 1 file changed +10
-6
lines changed Original file line number Diff line number Diff line change @@ -148,10 +148,12 @@ def started(self, event: monitoring.CommandStartedEvent):
148148                span .set_attribute (SpanAttributes .DB_NAME , event .database_name )
149149                span .set_attribute (SpanAttributes .DB_OPERATION , command_name )
150150                if  self .capture_statement :
151-                     span .set_attribute (
152-                         SpanAttributes .DB_STATEMENT ,
153-                         _get_statement (event ),
154-                     )
151+                     db_statement  =  _get_statement (event )
152+                     if  db_statement  is  not   None :
153+                         span .set_attribute (
154+                             SpanAttributes .DB_STATEMENT ,
155+                             _get_statement (event ),
156+                         )
155157                if  collection  and  isinstance (collection , str ):
156158                    span .set_attribute (
157159                        SpanAttributes .DB_MONGODB_COLLECTION , collection 
@@ -224,12 +226,14 @@ def _get_span_name(event: CommandEvent) -> str:
224226    return  f"{ event .database_name }  .{ command_name }  " 
225227
226228
227- def  _get_statement (event : CommandEvent ) ->  str :
229+ def  _get_statement (event : CommandEvent ) ->  str   |   None :
228230    """Get the statement for a given pymongo event.""" 
229231    command_name  =  event .command_name 
230232    command_attribute  =  COMMAND_TO_ATTRIBUTE_MAPPING .get (command_name )
231233    command  =  event .command .get (command_attribute )
232-     return  f"{ command }  " 
234+     if  command  is  not   None :
235+         return  f"{ command }  " 
236+     return  None 
233237
234238
235239def  _get_span_dict_key (
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments