A11 (C++ runtime)
Native C++ implementation of the A11 action and streaming runtime
Loading...
Searching...
No Matches
a11::obs::Span Class Reference

Move-only RAII handle to one action, session, or transport span. More...

#include <cpp/a11/obs/span.h>

Classes

struct  Impl
 

Public Member Functions

 Span () noexcept=default
 
 ~Span ()
 
 Span (Span &&other) noexcept
 Transfer ownership without ending the span.
 
Spanoperator= (Span &&other) noexcept
 End the currently owned span, then transfer other.
 
 Span (const Span &)=delete
 
Spanoperator= (const Span &)=delete
 
bool IsRecording () const noexcept
 Whether this handle currently records attributes and events.
 
std::string TraceIdHex () const
 Return the 32-character trace id, or empty when inactive.
 
std::string SpanIdHex () const
 Return the 16-character span id, or empty when inactive.
 
void SetAttribute (std::string_view key, std::string_view value)
 Set or replace a string attribute on the live span.
 
void SetAttribute (std::string_view key, const char *value)
 Set or replace a C-string attribute on the live span.
 
void SetAttribute (std::string_view key, std::int64_t value)
 Set or replace an integer attribute on the live span.
 
void SetAttribute (std::string_view key, bool value)
 Set or replace a boolean attribute on the live span.
 
void SetAttribute (std::string_view key, double value)
 Set or replace a floating-point attribute on the live span.
 
void AddEvent (std::string_view name)
 Record a named point-in-time event.
 
void AddEvent (std::string_view name, const std::vector< std::pair< std::string, std::string > > &attributes)
 Record an event with string attributes.
 
void SetStatus (const absl::Status &status)
 Map an A11 operation status onto the span's OTel outcome.
 
void SetStatus (SpanStatus status, std::string_view description={})
 Set an explicit OTel outcome; description explains kError.
 
void UpdateName (std::string_view name)
 Replace the name that will be exported when the span ends.
 
void End () noexcept
 Finish the span and release its implementation; safe to call repeatedly.
 
absl::Status InjectContext (data::ByteMap &headers) const
 Inject trace context and inherited baggage into reserved A11 headers.
 

Friends

class Tracer
 

Detailed Description

Move-only RAII handle to one action, session, or transport span.

A default-constructed or moved-from Span is inactive: IsRecording() is false and every mutator is a no-op. Tracer also returns an inactive span when tracing is not configured, so agent runtime call sites need no feature branches. End() is idempotent, and destruction ends a live span.

OpenTelemetry types remain hidden in fixed inline storage so this public header does not expose the SDK or allocate a separate pImpl for every span.

Constructor & Destructor Documentation

◆ Span() [1/3]

a11::obs::Span::Span ( )
defaultnoexcept

◆ ~Span()

a11::obs::Span::~Span ( )

◆ Span() [2/3]

a11::obs::Span::Span ( Span &&  other)
noexcept

Transfer ownership without ending the span.

◆ Span() [3/3]

a11::obs::Span::Span ( const Span )
delete

Member Function Documentation

◆ AddEvent() [1/2]

void a11::obs::Span::AddEvent ( std::string_view  name)

Record a named point-in-time event.

◆ AddEvent() [2/2]

void a11::obs::Span::AddEvent ( std::string_view  name,
const std::vector< std::pair< std::string, std::string > > &  attributes 
)

Record an event with string attributes.

◆ End()

void a11::obs::Span::End ( )
noexcept

Finish the span and release its implementation; safe to call repeatedly.

◆ InjectContext()

absl::Status a11::obs::Span::InjectContext ( data::ByteMap headers) const

Inject trace context and inherited baggage into reserved A11 headers.

◆ IsRecording()

bool a11::obs::Span::IsRecording ( ) const
noexcept

Whether this handle currently records attributes and events.

◆ operator=() [1/2]

Span & a11::obs::Span::operator= ( const Span )
delete

◆ operator=() [2/2]

Span & a11::obs::Span::operator= ( Span &&  other)
noexcept

End the currently owned span, then transfer other.

◆ SetAttribute() [1/5]

void a11::obs::Span::SetAttribute ( std::string_view  key,
bool  value 
)

Set or replace a boolean attribute on the live span.

◆ SetAttribute() [2/5]

void a11::obs::Span::SetAttribute ( std::string_view  key,
const char value 
)

Set or replace a C-string attribute on the live span.

◆ SetAttribute() [3/5]

void a11::obs::Span::SetAttribute ( std::string_view  key,
double  value 
)

Set or replace a floating-point attribute on the live span.

◆ SetAttribute() [4/5]

void a11::obs::Span::SetAttribute ( std::string_view  key,
std::int64_t  value 
)

Set or replace an integer attribute on the live span.

◆ SetAttribute() [5/5]

void a11::obs::Span::SetAttribute ( std::string_view  key,
std::string_view  value 
)

Set or replace a string attribute on the live span.

◆ SetStatus() [1/2]

void a11::obs::Span::SetStatus ( const absl::Status &  status)

Map an A11 operation status onto the span's OTel outcome.

◆ SetStatus() [2/2]

void a11::obs::Span::SetStatus ( SpanStatus  status,
std::string_view  description = {} 
)

Set an explicit OTel outcome; description explains kError.

◆ SpanIdHex()

std::string a11::obs::Span::SpanIdHex ( ) const

Return the 16-character span id, or empty when inactive.

◆ TraceIdHex()

std::string a11::obs::Span::TraceIdHex ( ) const

Return the 32-character trace id, or empty when inactive.

◆ UpdateName()

void a11::obs::Span::UpdateName ( std::string_view  name)

Replace the name that will be exported when the span ends.

Friends And Related Symbol Documentation

◆ Tracer


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