userver: tracing::SpanLogContext Class Reference
Loading...
Searching...
No Matches
tracing::SpanLogContext Class Referencefinal

#include <userver/tracing/span_log_context.hpp>

Detailed Description

Owns a snapshot of a span's tracing identifiers and sampling state for logging.

Useful in rare cases when logs need to be associated with a span that has already finished, such as request or response send errors, or logs from a background task spawned by a request handler.

Capture the context with SetFromSpan() while the span is alive, then append GetLogExtra() to a log record to attach the captured tracing fields.

Definition at line 28 of file span_log_context.hpp.

Public Member Functions

void SetFromSpan (const Span &span)
std::string_view GetTraceId () const noexcept
 Returns the captured trace ID, or an empty string if no context was captured.
std::string_view GetSpanId () const noexcept
 Returns the captured logging span ID, or an empty string if no span in the chain was loggable.
std::string_view GetLink () const noexcept
 Returns the captured link, or an empty string if no context was captured.
bool IsEmpty () const noexcept
 Returns true if no context has been captured with SetFromSpan().
bool IsSampled () const noexcept
 Returns the captured sampling state, or false for an empty context.
logging::LogExtra GetLogExtra () const
bool operator== (const SpanLogContext &) const =default

Member Function Documentation

◆ GetLogExtra()

logging::LogExtra tracing::SpanLogContext::GetLogExtra ( ) const

Returns the captured tracing fields for logging, or an empty LogExtra if no context has been captured.

◆ SetFromSpan()

void tracing::SpanLogContext::SetFromSpan ( const Span & span)

Replaces the captured context with the span's current logging context. The trace ID and the link are always captured. Uses Span::GetSpanIdForChildLogs() to select the span ID, which may belong to a parent span if the supplied span is not loggable, or be absent if no span in the chain is loggable.


The documentation for this class was generated from the following file: