kind-knife-49817
05/29/2025, 8:59 PMpants run
command, I can get the application working with this new library. When I package it into a .pex and then try to run the .pex directly, I get an error.
All I'm basically adding in the code is:
from azure.monitor.opentelemetry import configure_azure_monitor
configure_azure_monitor(
logger_name="app",
)
and adding azure-monitor-opentelemetry==1.6.*
to the reqs file.
Here is the error I am getting with the .pex file:
File "/<MY_HOME_DIR>/Library/Caches/pex/unzipped_pexes/4385a4cf921d3dcc4d7b10750fc92a7f3daee3eb/<SNIP>/manage.py", line 4, in <module>
from azure.monitor.opentelemetry import configure_azure_monitor
File "/<MY_HOME_DIR>/Library/Caches/pex/installed_wheels/04478aac471824d84810668118ad087271f7acc28f03850793592f9511290f0d/azure_monitor_opentelemetry-1.6.9-py3-none-any.whl/azure/monitor/opentelemetry/__init__.py", line 7, in <module>
from azure.monitor.opentelemetry._configure import configure_azure_monitor
File "/<MY_HOME_DIR>/Library/Caches/pex/installed_wheels/04478aac471824d84810668118ad087271f7acc28f03850793592f9511290f0d/azure_monitor_opentelemetry-1.6.9-py3-none-any.whl/azure/monitor/opentelemetry/_configure.py", line 36, in <module>
from azure.core.tracing.ext.opentelemetry_span import OpenTelemetrySpan
ModuleNotFoundError: No module named 'azure.core.tracing.ext.opentelemetry_span'
Now in the working version via pants run
if I remove proper configuration I can get it to throw an error so we can look at the difference in the library references:
File "/<MY_HOME_DIR>/.cache/pants/named_caches/pex_root/venvs/2b3d36fe33989eb01166bfaf9319677abf2c82ab/2fb925c691d5e4fac574b1d4e566e4d42d78dc6f/lib/python3.12/site-packages/azure/monitor/opentelemetry/exporter/_connection_string_parser.py", line 39, in _initialize
env_cs = self._parse_connection_string(os.getenv("APPLICATIONINSIGHTS_CONNECTION_STRING"))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/<MY_HOME_DIR>/.cache/pants/named_caches/pex_root/venvs/2b3d36fe33989eb01166bfaf9319677abf2c82ab/2fb925c691d5e4fac574b1d4e566e4d42d78dc6f/lib/python3.12/site-packages/azure/monitor/opentelemetry/exporter/_connection_string_parser.py", line 90, in _parse_connection_string
raise ValueError("Invalid connection string") from exc
ValueError: Invalid connection string
I am suspicious it has something to do with how the modules are mapped differently when ran from pants run, vs pants package, and have played around with module_mapping