Skip to content

Commit

Permalink
Add special cases for urllib,sqlite3
Browse files Browse the repository at this point in the history
  • Loading branch information
tammy-baylis-swi committed Dec 16, 2022
1 parent 992ec87 commit a1fc5ee
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions solarwinds_apm/configurator.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,8 +281,11 @@ def _add_all_instrumented_python_framework_versions(
Example output:
{
"Python.Urllib.Version": "3.9",
"Python.Requests.Version": "2.28.1",
"Python.Django.Version": "4.1.4",
"Python.Psycopg2.Version": "2.9.5 (dt dec pq3 ext lo64)",
"Python.Sqlite3.Version": "3.34.1",
"Python.Logging.Version": "0.5.1.2",
}
"""
Expand Down Expand Up @@ -317,8 +320,19 @@ def _add_all_instrumented_python_framework_versions(

instr_key = f"Python.{entry_point.name.capitalize()}.Version"
try:
importlib.import_module(entry_point.name)
version_keys[instr_key] = sys.modules[entry_point.name].__version__
# urllib has a rich complex history
if entry_point.name == "urllib":
importlib.import_module(f"{entry_point.name}.request")
else:
importlib.import_module(entry_point.name)

# some Python frameworks just don't have __version__
if entry_point.name == "urllib":
version_keys[instr_key] = sys.modules[f"{entry_point.name}.request"].__version__
elif entry_point.name == "sqlite3":
version_keys[instr_key] = sys.modules[entry_point.name].sqlite_version
else:
version_keys[instr_key] = sys.modules[entry_point.name].__version__
except (AttributeError, ImportError) as ex:
# could not import package for whatever reason
logger.warning(
Expand Down

0 comments on commit a1fc5ee

Please sign in to comment.