Viam C++ SDK current
Loading...
Searching...
No Matches
Public Member Functions | List of all members
viam::sdk::TracingSpan Class Reference

RAII child span. Parent is whichever span is active on the current thread, which inside a resource API method body is the SDK-managed gRPC handler span. More...

#include <span.hpp>

Public Member Functions

 TracingSpan (const char *name) noexcept
 Open a child span named name under the currently-active span.
 
 TracingSpan (TracingSpan &&)=delete
 
TracingSpanoperator= (TracingSpan &&)=delete
 
template<typename T >
void set_attribute (const char *key, T value) noexcept
 Attach an attribute to the span. Supported value types: bool, std::int64_t, double, const char*, std::string. Other types fail to link.
 
void add_event (const char *name) noexcept
 Record a timestamped event on the span.
 
void set_status_ok () noexcept
 Mark the span as having completed successfully.
 
void set_status_error (const char *description="") noexcept
 Mark the span as having failed. description is optional context.
 
void record_exception (const std::exception &xcp) noexcept
 Record xcp as an "exception" event and set span status to Error.
 
void record_unknown_exception () noexcept
 Record an unknown (non-stdexception) failure as an "exception" event and set span status to Error.
 
void end () noexcept
 Mark the end of the span.
 

Detailed Description

RAII child span. Parent is whichever span is active on the current thread, which inside a resource API method body is the SDK-managed gRPC handler span.

No-op when OpenTelemetry support is not compiled in, no tracer provider is installed, or no parent span is active on the current thread. Must be constructed and destroyed on the same thread, in LIFO order.

std::vector<GeoPoint> MyMovementSensor::get_position(const ProtoStruct& extra) {
viam::sdk::TracingSpan span{"my_module.read_gps"};
span.set_attribute("sensor.model", model_);
return points;
}
RAII child span. Parent is whichever span is active on the current thread, which inside a resource AP...
Definition span.hpp:32
void set_attribute(const char *key, T value) noexcept
Attach an attribute to the span. Supported value types: bool, std::int64_t, double,...

Member Function Documentation

◆ record_exception()

void viam::sdk::TracingSpan::record_exception ( const std::exception & xcp)
noexcept

Record xcp as an "exception" event and set span status to Error.

Remarks
In the event of an exception the parent span will automatically set its status to error. Use this helper if you wish to record failure info within child spans.

◆ record_unknown_exception()

void viam::sdk::TracingSpan::record_unknown_exception ( )
noexcept

Record an unknown (non-stdexception) failure as an "exception" event and set span status to Error.

Remarks
In the event of an exception the parent span will automatically set its status to error. Use this helper if you wish to record failure info within child spans.

◆ set_status_ok()

void viam::sdk::TracingSpan::set_status_ok ( )
noexcept

Mark the span as having completed successfully.

Remarks
Note it is not necessary to call this method to indicate successful completion. See https://opentelemetry.io/docs/concepts/signals/traces/#span-status

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