Skip to content

Commit

Permalink
Re-arrange import statements; handle unicode strings (#9)
Browse files Browse the repository at this point in the history
* Re-arrange import statements; convert unicode to non unicode

We were seeing some errors where celery task names might have non
unicode characters in them, which was making a non fatal exception
where blueox couldn't parse it. This change will force unicode
strings in type to be not unicode, and save us millions of useless
sentry events (and not drop the data either).
  • Loading branch information
aabhassharma committed May 18, 2018
1 parent 53989b3 commit 66aa241
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
blueox (0.11.6.3)
* Fix handling of unicode strings

blueox (0.11.6.2)
* Fix DeprecationWarning: integer argument expected

Expand Down
2 changes: 1 addition & 1 deletion blueox/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"""

__title__ = 'blueox'
__version__ = '0.11.6.2'
__version__ = '0.11.6.3'
__author__ = 'Rhett Garber'
__author_email__ = 'rhettg@gmail.com'
__license__ = 'ISC'
Expand Down
14 changes: 9 additions & 5 deletions blueox/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
:license: ISC, see LICENSE for more details.
"""
import atexit
import logging
import threading
import msgpack
import struct
import atexit

import threading
import zmq
import msgpack

from . import utils

Expand Down Expand Up @@ -80,6 +79,11 @@ def _serialize_context(context):
if len(context_dict.get(key, "")) > 64:
raise ValueError("Value too long: %r" % key)

context_dict = {
k: v.encode('utf-8') if isinstance(v, unicode)
else v for k, v in context_dict.items()
}

meta_data = struct.pack(META_STRUCT_FMT, META_STRUCT_VERSION,
context_dict['end'], context_dict['host'],
context_dict['type'])
Expand Down Expand Up @@ -117,7 +121,7 @@ def send(context):
log.debug("Sending msg")
threadLocal.zmq_socket.send_multipart(
(meta_data, context_data), zmq.NOBLOCK)
except zmq.ZMQError, e:
except zmq.ZMQError:
log.exception("Failed sending blueox event, buffer full?")
else:
log.info("Skipping sending event %s", context.name)
Expand Down

0 comments on commit 66aa241

Please sign in to comment.