Skip to content

Commit

Permalink
Merge branch 'main' into yunkim/llmobs-safely-create-span
Browse files Browse the repository at this point in the history
  • Loading branch information
Yun-Kim authored Apr 15, 2024
2 parents 3c6c6d7 + 60763e1 commit b259156
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
17 changes: 17 additions & 0 deletions ddtrace/internal/packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,14 @@ def _package_file_mapping():
return None


@callonce
def _third_party_packages() -> set:
from gzip import decompress
from importlib.resources import read_binary

return set(decompress(read_binary("ddtrace.internal", "third-party.tar.gz")).decode("utf-8").splitlines())


def filename_to_package(filename):
# type: (str) -> t.Optional[Distribution]

Expand Down Expand Up @@ -169,6 +177,15 @@ def is_stdlib(path: Path) -> bool:
)


@cached()
def is_third_party(path: Path) -> bool:
package = filename_to_package(str(path))
if package is None:
return False

return package.name in _third_party_packages()


@cached()
def is_distribution_available(name: str) -> bool:
"""Determine if a distribution is available in the current environment."""
Expand Down
Binary file added ddtrace/internal/third-party.tar.gz
Binary file not shown.
1 change: 1 addition & 0 deletions tests/.suitespec.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"ddtrace/internal/metrics.py",
"ddtrace/internal/module.py",
"ddtrace/internal/packages.py",
"ddtrace/internal/third-party.tar.gz",
"ddtrace/internal/periodic.py",
"ddtrace/internal/rate_limiter.py",
"ddtrace/internal/safety.py",
Expand Down
8 changes: 8 additions & 0 deletions tests/internal/test_packages.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest

from ddtrace.internal import packages
from ddtrace.internal.packages import _third_party_packages
from ddtrace.internal.packages import get_distributions


Expand Down Expand Up @@ -86,3 +87,10 @@ def test_filename_to_package():
assert package is None or package.name == "protobuf"

del packages._package_file_mapping.__closure__[0].cell_contents.__callonce_result__


def test_third_party_packages():
assert 4000 < len(_third_party_packages()) < 5000

assert "requests" in _third_party_packages()
assert "nota3rdparty" not in _third_party_packages()

0 comments on commit b259156

Please sign in to comment.