Integrating Tracing into Existing Logging

The MDK supports distributed tracing across and within processes. When you log a message via the MDK, the message is stored with a session-specific trace ID and a message-specific causal-clock level. You can, if you wish, include this information in a separate logging store that you use or operate (e.g. ElasticSearch). This will allow you to trace messages across various processes much like Datawire Mission Control does.

Routing logs to the MDK

It’s possible to route logs from your language or framework’s logging infrastructure to Mission Control via the MDK. The MDK includes built-in support for:

Extracting message identifiers

Whenever you log a messages using mdk.Session.info()/error()/etc. it returns a LoggedMessageId object. It has two relevant attributes, the traceId (a string) and the causalLevel (a list of integers).

In the following example, utilizing the MDK’s Flask integration for Python, you can see how you can use this information:

from flask import Flask
from mdk.flask import mdk_setup

app = Flask(__name__)

@app.route("/")
def hello():
    msg_id = g.mdk_session.info("myservice", "Hello world!")
    print("We just logged message {}:{}".format(msg_id.traceId, msg_id.causalLevel))
    return "hello"


if __name__ == '__main__':
    mdk = mdk_setup(app)
    app.run(port=7070)

You could use this for example to write a custom logging.Handler that accepts standard Python logging messages, writes them to the MDK, and then does additional storage of logging. None of this is Python-specific: you can do this in other MDK languages as well.