Skip to content

Commit

Permalink
lint
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremydvoss committed Sep 10, 2024
1 parent 7e3003c commit 1b913d2
Showing 1 changed file with 21 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@

import opentelemetry.instrumentation.fastapi as otel_fastapi
from opentelemetry import trace
from opentelemetry.instrumentation.auto_instrumentation._load import _load_instrumentors
from opentelemetry.instrumentation.auto_instrumentation._load import (
_load_instrumentors,
)
from opentelemetry.instrumentation._semconv import (
OTEL_SEMCONV_STABILITY_OPT_IN,
_OpenTelemetrySemanticConventionStability,
Expand Down Expand Up @@ -1034,9 +1036,11 @@ def client_response_hook(send_span, scope, message):
def get_distribution_with_fastapi(*args, **kwargs):
dist = args[0]
if dist == "fastapi~=0.58":
return None #Value does not matter. Only whether an exception is thrown
# Value does not matter. Only whether an exception is thrown
return None
raise DistributionNotFound()


def get_distribution_without_fastapi(*args, **kwargs):
raise DistributionNotFound()

Expand All @@ -1051,10 +1055,12 @@ class TestAutoInstrumentation(TestBaseAutoFastAPI):
def test_entry_point_exists(self):
eps = iter_entry_points("opentelemetry_instrumentor")
ep = next(eps)
self.assertEqual(ep.dist.key, 'opentelemetry-instrumentation-fastapi')
self.assertEqual(ep.module_name, 'opentelemetry.instrumentation.fastapi')
self.assertEqual(ep.attrs, ('FastAPIInstrumentor',))
self.assertEqual(ep.name, 'fastapi')
self.assertEqual(ep.dist.key, "opentelemetry-instrumentation-fastapi")
self.assertEqual(
ep.module_name, "opentelemetry.instrumentation.fastapi"
)
self.assertEqual(ep.attrs, ("FastAPIInstrumentor",))
self.assertEqual(ep.name, "fastapi")
self.assertIsNone(next(eps, None))

@patch("opentelemetry.instrumentation.dependencies.get_distribution")
Expand All @@ -1066,13 +1072,17 @@ def test_instruments_with_fastapi_installed(self, mock_get_distribution):
self.assertEqual(len(mock_distro.load_instrumentor.call_args_list), 1)
args = mock_distro.load_instrumentor.call_args.args
ep = args[0]
self.assertEqual(ep.dist.key, 'opentelemetry-instrumentation-fastapi')
self.assertEqual(ep.module_name, 'opentelemetry.instrumentation.fastapi')
self.assertEqual(ep.attrs, ('FastAPIInstrumentor',))
self.assertEqual(ep.name, 'fastapi')
self.assertEqual(ep.dist.key, "opentelemetry-instrumentation-fastapi")
self.assertEqual(
ep.module_name, "opentelemetry.instrumentation.fastapi"
)
self.assertEqual(ep.attrs, ("FastAPIInstrumentor",))
self.assertEqual(ep.name, "fastapi")

@patch("opentelemetry.instrumentation.dependencies.get_distribution")
def test_instruments_without_fastapi_installed(self, mock_get_distribution):
def test_instruments_without_fastapi_installed(
self, mock_get_distribution
):
mock_get_distribution.side_effect = get_distribution_without_fastapi
mock_distro = Mock()
_load_instrumentors(mock_distro)
Expand Down

0 comments on commit 1b913d2

Please sign in to comment.