3131
3232import opentelemetry .instrumentation .fastapi as otel_fastapi
3333from opentelemetry import trace
34- from opentelemetry .instrumentation .auto_instrumentation ._load import _load_instrumentors
34+ from opentelemetry .instrumentation .auto_instrumentation ._load import (
35+ _load_instrumentors ,
36+ )
3537from opentelemetry .instrumentation ._semconv import (
3638 OTEL_SEMCONV_STABILITY_OPT_IN ,
3739 _OpenTelemetrySemanticConventionStability ,
@@ -1034,9 +1036,11 @@ def client_response_hook(send_span, scope, message):
10341036def get_distribution_with_fastapi (* args , ** kwargs ):
10351037 dist = args [0 ]
10361038 if dist == "fastapi~=0.58" :
1037- return None #Value does not matter. Only whether an exception is thrown
1039+ # Value does not matter. Only whether an exception is thrown
1040+ return None
10381041 raise DistributionNotFound ()
10391042
1043+
10401044def get_distribution_without_fastapi (* args , ** kwargs ):
10411045 raise DistributionNotFound ()
10421046
@@ -1051,10 +1055,12 @@ class TestAutoInstrumentation(TestBaseAutoFastAPI):
10511055 def test_entry_point_exists (self ):
10521056 eps = iter_entry_points ("opentelemetry_instrumentor" )
10531057 ep = next (eps )
1054- self .assertEqual (ep .dist .key , 'opentelemetry-instrumentation-fastapi' )
1055- self .assertEqual (ep .module_name , 'opentelemetry.instrumentation.fastapi' )
1056- self .assertEqual (ep .attrs , ('FastAPIInstrumentor' ,))
1057- self .assertEqual (ep .name , 'fastapi' )
1058+ self .assertEqual (ep .dist .key , "opentelemetry-instrumentation-fastapi" )
1059+ self .assertEqual (
1060+ ep .module_name , "opentelemetry.instrumentation.fastapi"
1061+ )
1062+ self .assertEqual (ep .attrs , ("FastAPIInstrumentor" ,))
1063+ self .assertEqual (ep .name , "fastapi" )
10581064 self .assertIsNone (next (eps , None ))
10591065
10601066 @patch ("opentelemetry.instrumentation.dependencies.get_distribution" )
@@ -1066,13 +1072,17 @@ def test_instruments_with_fastapi_installed(self, mock_get_distribution):
10661072 self .assertEqual (len (mock_distro .load_instrumentor .call_args_list ), 1 )
10671073 args = mock_distro .load_instrumentor .call_args .args
10681074 ep = args [0 ]
1069- self .assertEqual (ep .dist .key , 'opentelemetry-instrumentation-fastapi' )
1070- self .assertEqual (ep .module_name , 'opentelemetry.instrumentation.fastapi' )
1071- self .assertEqual (ep .attrs , ('FastAPIInstrumentor' ,))
1072- self .assertEqual (ep .name , 'fastapi' )
1075+ self .assertEqual (ep .dist .key , "opentelemetry-instrumentation-fastapi" )
1076+ self .assertEqual (
1077+ ep .module_name , "opentelemetry.instrumentation.fastapi"
1078+ )
1079+ self .assertEqual (ep .attrs , ("FastAPIInstrumentor" ,))
1080+ self .assertEqual (ep .name , "fastapi" )
10731081
10741082 @patch ("opentelemetry.instrumentation.dependencies.get_distribution" )
1075- def test_instruments_without_fastapi_installed (self , mock_get_distribution ):
1083+ def test_instruments_without_fastapi_installed (
1084+ self , mock_get_distribution
1085+ ):
10761086 mock_get_distribution .side_effect = get_distribution_without_fastapi
10771087 mock_distro = Mock ()
10781088 _load_instrumentors (mock_distro )
0 commit comments