Skip to content

Commit 48b2d08

Browse files
authored
Handle exception when sending entity to Daemon (#292)
* Handle exception when sending entity to Daemon * Added full stop * Removed try-catch block
1 parent e7711fe commit 48b2d08

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

aws_xray_sdk/core/emitters/udp_emitter.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@ def send_entity(self, entity):
3232
3333
:param entity: a trace entity to send to the X-Ray daemon
3434
"""
35-
message = "%s%s%s" % (PROTOCOL_HEADER,
36-
PROTOCOL_DELIMITER,
37-
entity.serialize())
35+
try:
36+
message = "%s%s%s" % (PROTOCOL_HEADER,
37+
PROTOCOL_DELIMITER,
38+
entity.serialize())
3839

39-
log.debug("sending: %s to %s:%s." % (message, self._ip, self._port))
40-
self._send_data(message)
40+
log.debug("sending: %s to %s:%s." % (message, self._ip, self._port))
41+
self._send_data(message)
42+
except Exception:
43+
log.exception("Failed to send entity to Daemon.")
4144

4245
def set_daemon_address(self, address):
4346
"""
@@ -57,12 +60,7 @@ def port(self):
5760
return self._port
5861

5962
def _send_data(self, data):
60-
61-
try:
62-
self._socket.sendto(data.encode('utf-8'), (self._ip,
63-
self._port))
64-
except Exception:
65-
log.exception('failed to send data to X-Ray daemon.')
63+
self._socket.sendto(data.encode('utf-8'), (self._ip, self._port))
6664

6765
def _parse_address(self, daemon_address):
6866
try:

aws_xray_sdk/core/models/entity.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,10 +259,7 @@ def serialize(self):
259259
Serialize to JSON document that can be accepted by the
260260
X-Ray backend service. It uses json to perform serialization.
261261
"""
262-
try:
263-
return json.dumps(self.to_dict(), default=str)
264-
except Exception:
265-
log.exception("Failed to serialize %s", self.name)
262+
return json.dumps(self.to_dict(), default=str)
266263

267264
def to_dict(self):
268265
"""

0 commit comments

Comments
 (0)