Skip to content

Commit

Permalink
Use importlib.metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
xrmx committed Aug 1, 2024
1 parent 832475f commit d42b9bf
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,10 +172,10 @@ def client_response_hook(span: Span, scope: dict[str, Any], message: dict[str, A
---
"""
import logging
from importlib.metadata import PackageNotFoundError, distribution
from typing import Collection

import fastapi
from pkg_resources import get_distribution
from starlette.routing import Match

from opentelemetry.instrumentation._semconv import (
Expand Down Expand Up @@ -285,18 +285,18 @@ def uninstrument_app(app: fastapi.FastAPI):
app._is_instrumented_by_opentelemetry = False

def instrumentation_dependencies(self) -> Collection[str]:
# need to use get_distribution because find_spec("fastapi") will return
# need to use distribution because find_spec("fastapi") will return
# something even with just fastapi-slim installed
try:
get_distribution("fastapi-slim")
distribution("fastapi-slim")
return (_fastapi_slim,)
except Exception: # pylint: disable=broad-exception-caught
except PackageNotFoundError:
pass

try:
get_distribution("fastapi")
distribution("fastapi")
return (_fastapi,)
except Exception: # pylint: disable=broad-exception-caught
except PackageNotFoundError:
pass

# If neither is installed, return both as potential dependencies
Expand Down

0 comments on commit d42b9bf

Please sign in to comment.