Measures the execution time of the current code block, links it with the parent tracing::Spans and stores that info in the log.
Logging of spans can be controlled at runtime via USERVER_NO_LOG_SPANS, provided that you Append components::LoggingConfigurator component or use components::CommonComponentList.
See Logging and Tracing for usage examples and more descriptions.
- Warning
- Shall be created only as a local variable. Do not use it as a class member!
- Examples
- samples/tcp_full_duplex_service/main.cpp.
Definition at line 35 of file span.hpp.
|
| | Span (std::string name, const utils::impl::SourceLocation &source_location=utils::impl::SourceLocation::Current()) |
| |
| | Span (std::string name, const Span *parent, ReferenceType reference_type=ReferenceType::kChild, const utils::impl::SourceLocation &source_location=utils::impl::SourceLocation::Current()) |
| |
|
| Span (Span &&other) noexcept |
| |
|
| Span (const Span &other)=delete |
| |
|
Span & | operator= (Span &&)=delete |
| |
|
Span & | operator= (const Span &)=delete |
| |
| Span | CreateChild (std::string name, const utils::impl::SourceLocation &source_location=utils::impl::SourceLocation::Current()) const |
| |
|
Span | CreateFollower (std::string name, const utils::impl::SourceLocation &source_location=utils::impl::SourceLocation::Current()) const |
| |
|
ScopeTime | CreateScopeTime () |
| | Creates a tracing::ScopeTime attached to the span.
|
| |
| ScopeTime | CreateScopeTime (std::string name) |
| | Creates a tracing::ScopeTime attached to the Span and starts measuring execution time. Tag {scope_name}_time with elapsed time is added to result span.
|
| |
| ScopeTime::Duration | GetTotalDuration (std::string_view scope_name) const |
| |
| ScopeTime::DurationMillis | GetTotalElapsedTime (std::string_view scope_name) const |
| |
| void | AddTag (std::string key, logging::LogExtra::Value value) |
| |
| void | AddTagFrozen (std::string key, logging::LogExtra::Value value) |
| |
| void | AddNonInheritableTag (std::string key, logging::LogExtra::Value value) |
| |
|
void | AddNonInheritableTags (const logging::LogExtra &) |
| |
|
void | AddEvent (SpanEvent &&event) |
| | Add an event to Span.
|
| |
|
void | AddEvent (std::string_view event_name) |
| |
| void | SetLogLevel (logging::Level log_level) |
| | Sets log level with which the current span itself is written into the tracing system.
|
| |
|
logging::Level | GetLogLevel () const noexcept |
| | See tracing::Span::SetLogLevel.
|
| |
| void | SetLocalLogLevel (std::optional< logging::Level > log_level) noexcept |
| | Sets the log level for the scope of this Span and nested scopes recursively.
|
| |
|
std::optional< logging::Level > | GetLocalLogLevel () const noexcept |
| | See tracing::Span::SetLocalLogLevel.
|
| |
| void | SetLink (std::string_view link) |
| |
| void | SetParentLink (std::string_view parent_link) |
| |
| std::string_view | GetLink () const noexcept |
| |
| std::string_view | GetParentLink () const noexcept |
| |
| std::string_view | GetTraceId () const noexcept |
| |
|
std::string_view | GetSpanId () const noexcept |
| | Identifies a specific span. It does not propagate.
|
| |
|
std::string_view | GetParentId () const noexcept |
| | Span ID of the nearest loggable parent span, or empty string if none exists.
|
| |
| std::optional< std::string_view > | GetSpanIdForChildLogs () const noexcept |
| |
|
std::string_view | GetName () const noexcept |
| | Get name the Span was created with.
|
| |
| bool | ShouldLogDefault () const noexcept |
| |
| bool | IsSampled () const noexcept |
| |
| void | SetSampled (bool sampled) noexcept |
| |
| void | DetachFromCoroStack () noexcept |
| |
| void | AttachToCoroStack () |
| |
|
std::chrono::system_clock::time_point | GetStartSystemTime () const noexcept |
| |
|
std::chrono::steady_clock::time_point | GetStartSteadyTime () const noexcept |
| |
|
| static Span & | CurrentSpan () |
| | Returns the Span of the current task.
|
| |
|
static Span * | CurrentSpanUnchecked () |
| | Returns nullptr if called in non-coroutine context or from a task with no alive Span; otherwise returns the Span of the current task.
|
| |
| static Span | MakeSpan (std::string name, std::string_view trace_id, std::string_view parent_span_id, const utils::impl::SourceLocation &source_location=utils::impl::SourceLocation::Current()) |
| |
| static Span | MakeSpan (std::string name, std::string_view trace_id, std::string_view parent_span_id, std::string_view link, const utils::impl::SourceLocation &source_location=utils::impl::SourceLocation::Current()) |
| |
| static Span | MakeRootSpan (std::string name, const utils::impl::SourceLocation &source_location=utils::impl::SourceLocation::Current()) |
| |
| void tracing::Span::SetLocalLogLevel |
( |
std::optional< logging::Level > | log_level | ) |
|
|
noexcept |
Sets the log level for the scope of this Span and nested scopes recursively.
Overrides the global log level in both directions: can raise the threshold (suppress logs) or lower it (enable debug logs even if the global level is higher).
For example, if the global log level is info, and the current Span has local log level debug, then all LOG_DEBUGs within the current scope will be written.
The cutoff also applies to the span itself. If the span's log level is less than the local log level, then the span is not written to the tracing system.
Local log level of child spans can override local log level of parent spans in both directions.