Skip to content

Commit

Permalink
Fix statsd client on urls that aren't ascii encodable
Browse files Browse the repository at this point in the history
Fixes https://sentry.galaxyproject.org/share/issue/e2c535d2d4904d438a0a1524c991bba4/:
```
UnicodeEncodeError: 'ascii' codec can't encode characters in position 14-16: ordinal not in range(128)
  File "galaxy/web/framework/middleware/error.py", line 167, in __call__
    app_iter = self.application(environ, sr_checker)
  File "galaxy/web/framework/middleware/statsd.py", line 34, in __call__
    self.galaxy_stasd_client.timing(page, dt)
  File "galaxy/web/statsd_client.py", line 35, in timing
    self.statsd_client.timing(infix + path, time)
  File "statsd/client/base.py", line 33, in timing
    self._send_stat(stat, '%0.6f|ms' % delta, rate)
  File "statsd/client/base.py", line 61, in _send_stat
    self._after(self._prepare(stat, value, rate))
  File "statsd/client/base.py", line 76, in _after
    self._send(data)
  File "statsd/client/udp.py", line 42, in _send
    self._sock.sendto(data.encode('ascii'), self._addr)
```
  • Loading branch information
mvdbeek committed Jul 4, 2024
1 parent 56d22ba commit 92bfaa6
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions lib/galaxy/web/framework/middleware/statsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,13 @@ def __call__(self, environ, start_response):
start_time = time.time()
req = self.application(environ, start_response)
dt = int((time.time() - start_time) * 1000)
page = environ.get("controller_action_key", None) or environ.get("PATH_INFO", "NOPATH").strip("/").replace(
"/", "."
page = (
environ.get("controller_action_key", None)
or environ.get("PATH_INFO", "NOPATH")
.strip("/")
.replace("/", ".")
.encode("ascii", errors="replace")
.decode()
)
self.galaxy_stasd_client.timing(page, dt)
try:
Expand Down

0 comments on commit 92bfaa6

Please sign in to comment.