Skip to content

Commit

Permalink
Also add task_uuid and task_level.
Browse files Browse the repository at this point in the history
  • Loading branch information
tomprince committed Jun 16, 2015
1 parent 1a03a76 commit dfffce5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
4 changes: 4 additions & 0 deletions eliot/_output.py
Expand Up @@ -186,12 +186,16 @@ def write(self, dictionary, serializer=None):
except _DestinationsSendError as e:
for (exc_type, exception, exc_traceback) in e.errors:
try:
from ._message import _defaultAction
# Can't use same code path as serialization errors because
# if destination continues to error out we will get
# infinite recursion. So instead we have to manually
# construct a message.

self._destinations.send({
"message_type": "eliot:destination_failure",
"task_uuid": _defaultAction._identification['task_uuid'],
"task_level": _defaultAction._nextTaskLevel().level,
"reason": safeunicode(exception),
"timestamp": self._time(),
"exception":
Expand Down
13 changes: 13 additions & 0 deletions eliot/tests/test_output.py
Expand Up @@ -18,6 +18,7 @@
MemoryLogger, ILogger, Destinations, Logger, fast_json as json, to_file,
FileDestination, _DestinationsSendError
)
from .._message import _defaultAction
from .._validation import ValidationError, Field, _MessageSerializer
from .._traceback import writeTraceback
from ..testing import assertContainsFields
Expand Down Expand Up @@ -528,6 +529,7 @@ def test_destinationExceptionCaught(self):
assertContainsFields(
self, dest[0],
{"message_type": "eliot:destination_failure",
"task_uuid": _defaultAction._identification["task_uuid"],
"message": logger._safeUnicodeDictionary(message),
"timestamp": 1234.5,
"reason": "ono",
Expand All @@ -553,18 +555,29 @@ def test_destinationMultipleExceptionsCaught(self):
zero_divide = str(e)
zero_type = ZeroDivisionError.__module__ + ".ZeroDivisionError"

# There is no way to get next level without mutating
# some state. We create a task_level, and we know the next
# two messages will be children of _defaultAction, so
# their levels will be consectuive.
task_level = _defaultAction._task_level.next_child()


message = {"hello": 123}
logger.write({"hello": 123})
self.assertEqual(
messages,
[message,
{"message_type": "eliot:destination_failure",
"message": logger._safeUnicodeDictionary(message),
"task_uuid": _defaultAction._identification["task_uuid"],
"task_level": [task_level.level[0] + 1],
"reason": "ono",
"timestamp": 1234.5,
"exception": "eliot.tests.test_output.MyException"},
{"message_type": "eliot:destination_failure",
"message": logger._safeUnicodeDictionary(message),
"task_uuid": _defaultAction._identification["task_uuid"],
"task_level": [task_level.level[0] + 2],
"reason": zero_divide,
"timestamp": 1234.5,
"exception": zero_type}])
Expand Down

0 comments on commit dfffce5

Please sign in to comment.