Skip to content

Commit

Permalink
feat(core): add tracing sample
Browse files Browse the repository at this point in the history
  • Loading branch information
roby2014 committed Sep 29, 2024
1 parent 7984e79 commit 6c8ef7e
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions core/samples/tel/tracing/main.cpp
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
/// [Logging and tracing include]
#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;
/// [Logging and tracing include]

int main()
{
cubos::core::tel::Logger::level(cubos::core::tel::Logger::Level::Trace);
cubos::core::tel::level(Level::Debug);

/// [Using macros]
CUBOS_SPAN_TRACE("this_wont_exist!");

CUBOS_INFO("hello from root span!"); // root span

CUBOS_SPAN_INFO("main_span");
// With this macro, a new RAII guard is created. When dropped, exits the span.
// This indicates that we are in the span for the current lexical scope.
// Logs and metrics from here will be associated with 'main' span.
CUBOS_INFO("hello!");

CUBOS_SPAN_TRACE("other_scope");
CUBOS_SPAN_DEBUG("other_scope");
CUBOS_INFO("hello again!");
// ...
/// [Using macros]

/// [Manually]
SpanManager::Span span("manual_span", CUBOS_SPAN_LEVEL_DEBUG, __FILE__, __LINE__);
SpanManager::enter(&span);
SpanManager::begin("manual_span", cubos::core::tel::Level::Debug);
CUBOS_INFO("entered a manual span");

SpanManager::exit();
SpanManager::end();
CUBOS_INFO("after exit manual span");
/// [Manually]
}
}

0 comments on commit 6c8ef7e

Please sign in to comment.