itamarst / eliot

Eliot: the logging system that tells you *why* it happened
https://eliot.readthedocs.io
Apache License 2.0
1.11k stars 66 forks source link

Question: best practice for multi-process/multi-host logging #306

Open stefanfoulis opened 6 years ago

stefanfoulis commented 6 years ago

For the case where a web request triggers a task on a queue to later execute: is it ok if the eliot action originally in the request has "finished" already, but the async task running in another process still adds messages to the sub-action?

Pseudocode (Django-ish, Celery-ish):

# in the web process handling requests
def a_view(request):
    with eliot.start_action('my-web-request') as action:
        my_background_task.delay(
            eliot_action_uuid=action.serialize_task_id().decode('ascii')
        )
    # at this point the action as already finished, but the code in
    # my_background_task has not run yet.
# in a worker process handling background tasks
def my_background_task(eliot_action_uuid):
    with eliot.Action.continue_task(task_id=eliot_action_uuid):
        # here we're logging stuff somewhere in the subtree of an 
        # action that is actually already "finished".
        do_stuff()

Is this ok? Or should this be avoided?

itamarst commented 6 years ago

This is OK, yes - it's one of the reasons Eliot does causal ordering rather than time-based ordering. It makes certain use cases (e.g. profiling) trickier, but it's an accurate representation of many situations.

This should probably be some sort of FAQ or documentation entry, so leaving issue open for that.

stefanfoulis commented 6 years ago

Thanks @itamarst that information helped me a lot in figuring out how to use eliot :-)