Examples » Core » Telemetry » Tracing

Using the tracing system.

Tracing in CUBOS can be done through the tracing macros defined in core/tel/tracing.hpp and the core::tel::SpanManager class.

#include <cubos/core/tel/level.hpp>
#include <cubos/core/tel/logging.hpp>
#include <cubos/core/tel/tracing.hpp>

using cubos::core::tel::Level;
using cubos::core::tel::Logger;
using cubos::core::tel::SpanManager;

The following example demonstrates a simple usage of the tracing macros and core::tel::SpanManager class, utilizing spans to track execution flow and log messages.

    cubos::core::tel::level(Level::Debug);

The tracing level is shared with logger's one, via core::tel::level function.

Using the macros is simple as:

You can also do manual span management:

    SpanManager::begin("manual_span", cubos::core::tel::Level::Debug);
    CUBOS_INFO("entered a manual span");

    SpanManager::end();
    CUBOS_INFO("after exit manual span");

We can observe the output of the tracing as follows:

[16:03:31.966] [main.cpp:20 main] [thread11740] info: hello from root span!
[16:03:31.967] [main.cpp:26 main] [thread11740:main_span] info: hello!
[16:03:31.967] [main.cpp:29 main] [thread11740:main_span:other_scope] info: hello again!
[16:03:31.968] [main.cpp:34 main] [thread11740:main_span:other_scope:manual_span] info: entered a manual span
[16:03:31.969] [main.cpp:37 main] [thread11740:main_span:other_scope] info: after exit manual span