31
31
32
32
import opentelemetry .instrumentation .fastapi as otel_fastapi
33
33
from 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
+ )
35
37
from opentelemetry .instrumentation ._semconv import (
36
38
OTEL_SEMCONV_STABILITY_OPT_IN ,
37
39
_OpenTelemetrySemanticConventionStability ,
@@ -1034,9 +1036,11 @@ def client_response_hook(send_span, scope, message):
1034
1036
def get_distribution_with_fastapi (* args , ** kwargs ):
1035
1037
dist = args [0 ]
1036
1038
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
1038
1041
raise DistributionNotFound ()
1039
1042
1043
+
1040
1044
def get_distribution_without_fastapi (* args , ** kwargs ):
1041
1045
raise DistributionNotFound ()
1042
1046
@@ -1051,10 +1055,12 @@ class TestAutoInstrumentation(TestBaseAutoFastAPI):
1051
1055
def test_entry_point_exists (self ):
1052
1056
eps = iter_entry_points ("opentelemetry_instrumentor" )
1053
1057
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" )
1058
1064
self .assertIsNone (next (eps , None ))
1059
1065
1060
1066
@patch ("opentelemetry.instrumentation.dependencies.get_distribution" )
@@ -1066,13 +1072,17 @@ def test_instruments_with_fastapi_installed(self, mock_get_distribution):
1066
1072
self .assertEqual (len (mock_distro .load_instrumentor .call_args_list ), 1 )
1067
1073
args = mock_distro .load_instrumentor .call_args .args
1068
1074
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" )
1073
1081
1074
1082
@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
+ ):
1076
1086
mock_get_distribution .side_effect = get_distribution_without_fastapi
1077
1087
mock_distro = Mock ()
1078
1088
_load_instrumentors (mock_distro )
0 commit comments