Skip to content

Commit 3a55049

Browse files
committed
fix python package name case-sensitive issue in client span code attributes
1 parent c398aed commit 3a55049

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

aws-opentelemetry-distro/src/amazon/opentelemetry/distro/code_correlation/internal/packages_resolver.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,8 @@ def is_third_party_package(file_path: Path) -> bool:
364364
return False
365365

366366
third_party_packages = _load_third_party_packages()
367-
return distribution.name in third_party_packages
367+
# Perform case-insensitive comparison to handle packages like 'Django' vs 'django'
368+
return distribution.name.lower() in third_party_packages
368369

369370

370371
@lru_cache(maxsize=1024)

aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/code_correlation/internal/test_packages_resolver.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -577,6 +577,18 @@ def test_is_third_party_package_not_in_list(self, mock_load_packages, mock_resol
577577

578578
self.assertFalse(result)
579579

580+
@patch("amazon.opentelemetry.distro.code_correlation.internal.packages_resolver.resolve_package_from_filename")
581+
@patch("amazon.opentelemetry.distro.code_correlation.internal.packages_resolver._load_third_party_packages")
582+
def test_is_third_party_package_case_insensitive_match(self, mock_load_packages, mock_resolve):
583+
"""Test case-insensitive detection of third-party package."""
584+
# Test with uppercase package name in distribution but lowercase in third-party list
585+
mock_resolve.return_value = Distribution(name="Django", version="4.2.0")
586+
mock_load_packages.return_value = {"django", "requests", "urllib3"}
587+
588+
result = is_third_party_package(Path("/path/to/Django/__init__.py"))
589+
590+
self.assertTrue(result)
591+
580592

581593
class TestIsUserCode(TestCase):
582594
"""Test the is_user_code function."""

0 commit comments

Comments
 (0)