@@ -32,9 +32,9 @@ def call(self, module, method, wrapped, instance, args, kwargs):
3232 http_method = args [0 ] if args_len else kwargs .get ('method' )
3333 http_path = args [1 ] if args_len > 1 else kwargs .get ('url' )
3434 params = args [2 ] if args_len > 2 else kwargs .get ('params' )
35- body = params .pop (BODY_REF_NAME , None )
35+ body = params .pop (BODY_REF_NAME , None ) if params else None
3636
37- api_method = params .pop (API_METHOD_KEY_NAME , None )
37+ api_method = params .pop (API_METHOD_KEY_NAME , None ) if params else None
3838
3939 signature = 'ES %s %s' % (http_method , http_path )
4040 context = {'db' : {'type' : 'elasticsearch' }}
@@ -43,7 +43,7 @@ def call(self, module, method, wrapped, instance, args, kwargs):
4343 # using both q AND body is allowed in some API endpoints / ES versions,
4444 # but not in others. We simply capture both if they are there so the
4545 # user can see it.
46- if 'q' in params :
46+ if params and 'q' in params :
4747 # 'q' is already encoded to a byte string at this point
4848 # we assume utf8, which is the default
4949 query .append ('q=' + params ['q' ].decode ('utf-8' , errors = 'replace' ))
@@ -132,8 +132,11 @@ def instrument(self):
132132 super (ElasticsearchInstrumentation , self ).instrument ()
133133
134134 def call (self , module , method , wrapped , instance , args , kwargs ):
135+ params = kwargs .pop ('params' , {})
136+
135137 # make a copy of params in case the caller reuses them for some reason
136- params = kwargs .pop ('params' , {}).copy ()
138+ params = params .copy () if params is not None else {}
139+
137140 cls_name , method_name = method .split ('.' , 1 )
138141 body_pos = (self .body_positions ['all' ].get (method_name ) or
139142 self .body_positions [self .version ].get (method_name ) or None )
0 commit comments