elastic / apm-agent-python

https://www.elastic.co/guide/en/apm/agent/python/current/index.html
BSD 3-Clause "New" or "Revised" License
415 stars 220 forks source link

ValueError, Can't set ELASTIC_APM_SERVER_URL as "url:port" with aiohttp since new update of python yarl librairy #2141

Open thetintin1000 opened 1 month ago

thetintin1000 commented 1 month ago

Describe the bug: Can't use ELASTIC_APM_SERVER_URL = "url:port" when building elastic apm instance from aiohttp app since new url control have been added on Yarl dependent library.

To Reproduce

  1. Intall dependencies
  2. configure aiohttp web app with global variable ELASTIC_APM_SERVER_URL = "url:port"
  3. build ElasticAPM(app) instance app as a aiohttp web app.
  4. raises a ValueError from yarl python library because of the format "url:port" not allowed (since yarl 1.13)

Environment (please complete the following information)

Additional context Error: File \"/home/nonroot/venv/lib/python3.12/site-packages/yarl/_url.py\", line 1607, in _host_validate\n raise ValueError(\nValueError: Host 'X.X.X.X:8080' cannot contain ':' (at position 11)"

When downgrading yarl to 1.12.1, it's now working again.

xrmx commented 1 month ago

Strange, yarl 1.13.0 is able to parse urls just fine here:

$ python3
Python 3.10.12 (main, Sep 11 2024, 15:47:36) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from yarl import URL
>>> URL("http://localhost:8200")
URL('http://localhost:8200')
>>> URL("http://10.0.0.1:8200")
URL('http://10.0.0.1:8200')
$ pip freeze
idna==3.10
multidict==6.1.0
propcache==0.2.0
typing_extensions==4.12.2
yarl==1.13.0
thetintin1000 commented 1 month ago

It's because the _host_validate is not called when you instantiate URL. See the regex actually breaking the format ip:port https://github.com/aio-libs/yarl/blob/v1.13.0/yarl/_url.py#L52

xrmx commented 1 month ago

@thetintin1000 does it work if you bump aiohttp to 3.10.7?