@@ -75,7 +75,7 @@ def response_hook(span, request_obj, response)
75
75
import functools
76
76
import types
77
77
from timeit import default_timer
78
- from typing import Callable , Collection , Optional
78
+ from typing import Any , Callable , Collection , Optional
79
79
from urllib .parse import urlparse
80
80
81
81
from requests .models import PreparedRequest , Response
@@ -146,7 +146,7 @@ def _instrument(
146
146
duration_histogram_new : Histogram ,
147
147
request_hook : _RequestHookT = None ,
148
148
response_hook : _ResponseHookT = None ,
149
- excluded_urls : ExcludeList = None ,
149
+ excluded_urls : ExcludeList | None = None ,
150
150
sem_conv_opt_in_mode : _StabilityMode = _StabilityMode .DEFAULT ,
151
151
):
152
152
"""Enables tracing of all requests calls that go through
@@ -164,7 +164,9 @@ def _instrument(
164
164
165
165
# pylint: disable-msg=too-many-locals,too-many-branches
166
166
@functools .wraps (wrapped_send )
167
- def instrumented_send (self , request , ** kwargs ):
167
+ def instrumented_send (
168
+ self : Session , request : PreparedRequest , ** kwargs : Any
169
+ ):
168
170
if excluded_urls and excluded_urls .url_disabled (request .url ):
169
171
return wrapped_send (self , request , ** kwargs )
170
172
@@ -345,7 +347,7 @@ def _uninstrument():
345
347
_uninstrument_from (Session )
346
348
347
349
348
- def _uninstrument_from (instr_root , restore_as_bound_func = False ):
350
+ def _uninstrument_from (instr_root , restore_as_bound_func : bool = False ):
349
351
for instr_func_name in ("request" , "send" ):
350
352
instr_func = getattr (instr_root , instr_func_name )
351
353
if not getattr (
@@ -361,7 +363,7 @@ def _uninstrument_from(instr_root, restore_as_bound_func=False):
361
363
setattr (instr_root , instr_func_name , original )
362
364
363
365
364
- def get_default_span_name (method ) :
366
+ def get_default_span_name (method : str ) -> str :
365
367
"""
366
368
Default implementation for name_callback, returns HTTP {method_name}.
367
369
https://opentelemetry.io/docs/reference/specification/trace/semantic_conventions/http/#name
@@ -385,7 +387,7 @@ class RequestsInstrumentor(BaseInstrumentor):
385
387
def instrumentation_dependencies (self ) -> Collection [str ]:
386
388
return _instruments
387
389
388
- def _instrument (self , ** kwargs ):
390
+ def _instrument (self , ** kwargs : Any ):
389
391
"""Instruments requests module
390
392
391
393
Args:
@@ -443,10 +445,10 @@ def _instrument(self, **kwargs):
443
445
sem_conv_opt_in_mode = semconv_opt_in_mode ,
444
446
)
445
447
446
- def _uninstrument (self , ** kwargs ):
448
+ def _uninstrument (self , ** kwargs : Any ):
447
449
_uninstrument ()
448
450
449
451
@staticmethod
450
- def uninstrument_session (session ):
452
+ def uninstrument_session (session : Session ):
451
453
"""Disables instrumentation on the session object."""
452
454
_uninstrument_from (session , restore_as_bound_func = True )
0 commit comments