Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle exception when sending entity to Daemon #292

Merged
merged 3 commits into from
Apr 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions aws_xray_sdk/core/emitters/udp_emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,15 @@ def send_entity(self, entity):

:param entity: a trace entity to send to the X-Ray daemon
"""
message = "%s%s%s" % (PROTOCOL_HEADER,
PROTOCOL_DELIMITER,
entity.serialize())
try:
srprash marked this conversation as resolved.
Show resolved Hide resolved
message = "%s%s%s" % (PROTOCOL_HEADER,
PROTOCOL_DELIMITER,
entity.serialize())

log.debug("sending: %s to %s:%s." % (message, self._ip, self._port))
self._send_data(message)
log.debug("sending: %s to %s:%s." % (message, self._ip, self._port))
self._send_data(message)
except Exception:
log.exception("Failed to send entity to Daemon.")

def set_daemon_address(self, address):
"""
Expand All @@ -57,12 +60,7 @@ def port(self):
return self._port

def _send_data(self, data):

try:
self._socket.sendto(data.encode('utf-8'), (self._ip,
self._port))
except Exception:
log.exception('failed to send data to X-Ray daemon.')
self._socket.sendto(data.encode('utf-8'), (self._ip, self._port))

def _parse_address(self, daemon_address):
try:
Expand Down
5 changes: 1 addition & 4 deletions aws_xray_sdk/core/models/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,7 @@ def serialize(self):
Serialize to JSON document that can be accepted by the
X-Ray backend service. It uses json to perform serialization.
"""
try:
return json.dumps(self.to_dict(), default=str)
except Exception:
log.exception("Failed to serialize %s", self.name)
return json.dumps(self.to_dict(), default=str)

def to_dict(self):
"""
Expand Down