From 66aa241059bd68ea22b1b80db61f7babc37a9a7e Mon Sep 17 00:00:00 2001 From: Aabhas Sharma Date: Thu, 17 May 2018 20:48:13 -0700 Subject: [PATCH] Re-arrange import statements; handle unicode strings (#9) * 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). --- CHANGES | 3 +++ blueox/__init__.py | 2 +- blueox/network.py | 14 +++++++++----- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CHANGES b/CHANGES index 9bba935..2de7816 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ +blueox (0.11.6.3) + * Fix handling of unicode strings + blueox (0.11.6.2) * Fix DeprecationWarning: integer argument expected diff --git a/blueox/__init__.py b/blueox/__init__.py index afa54ec..8cc8cfc 100644 --- a/blueox/__init__.py +++ b/blueox/__init__.py @@ -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' diff --git a/blueox/network.py b/blueox/network.py index 377a786..ede1a1e 100644 --- a/blueox/network.py +++ b/blueox/network.py @@ -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 @@ -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']) @@ -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)