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

RAII guard that creates a server-side OpenTelemetry span for the duration of a gRPC handler invocation. Extracts W3C trace context from the incoming gRPC request metadata and starts a child span (or a new root span if no traceparent header is present). When destroyed, ends the span and records the final gRPC status. More...

#include <span_guard.hpp>

Public Member Functions

 ServerSpanGuard (const GrpcServerContext *ctx, const char *method) noexcept
 
::grpc::Status commit (::grpc::Status status) noexcept
 Record the final gRPC status before destruction and return it unchanged.
 
void record_exception (const std::exception &xcp) noexcept
 Record xcp as an "exception" event and set span status to Error. Caller rethrows.
 
void record_unknown_exception () noexcept
 Record an unknown (non-stdexception) failure. Caller rethrows.
 
 ServerSpanGuard (const ServerSpanGuard &)=delete
 
ServerSpanGuardoperator= (const ServerSpanGuard &)=delete
 

Detailed Description

RAII guard that creates a server-side OpenTelemetry span for the duration of a gRPC handler invocation. Extracts W3C trace context from the incoming gRPC request metadata and starts a child span (or a new root span if no traceparent header is present). When destroyed, ends the span and records the final gRPC status.

If OpenTelemetry tracing is not compiled in, or no tracer provider has been configured, uses a no-op implementation.

Note
Instances must be created and destroyed on the same thread (the gRPC handler thread).

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