Viam C++ SDK current
Loading...
Searching...
No Matches
span.hpp
Go to the documentation of this file.
1
4#pragma once
5
6#include <cstdint>
7#include <exception>
8#include <memory>
9#include <string>
10
11namespace viam {
12namespace sdk {
13
15
33 public:
35 explicit TracingSpan(const char* name) noexcept;
36
37 ~TracingSpan() noexcept;
38
39 TracingSpan(TracingSpan&&) = delete;
40 TracingSpan& operator=(TracingSpan&&) = delete;
41
45 template <typename T>
46 void set_attribute(const char* key, T value) noexcept;
47
49 void add_event(const char* name) noexcept;
50
54 void set_status_ok() noexcept;
55
57 void set_status_error(const char* description = "") noexcept;
58
62 void record_exception(const std::exception& xcp) noexcept;
63
68 void record_unknown_exception() noexcept;
69
71 void end() noexcept;
72
73 private:
74 struct Impl;
75 std::unique_ptr<Impl> impl_;
76};
77
78template <>
79void TracingSpan::set_attribute<std::string>(const char*, std::string) noexcept;
80
81// -- Explicit instantiation declarations for the supported attribute value types -- //
82extern template void TracingSpan::set_attribute<bool>(const char*, bool) noexcept;
83extern template void TracingSpan::set_attribute<std::int64_t>(const char*, std::int64_t) noexcept;
84extern template void TracingSpan::set_attribute<double>(const char*, double) noexcept;
85extern template void TracingSpan::set_attribute<const char*>(const char*, const char*) noexcept;
86extern template void TracingSpan::set_attribute<std::string>(const char*, std::string) noexcept;
87
88} // namespace sdk
89} // namespace viam
RAII child span. Parent is whichever span is active on the current thread, which inside a resource AP...
Definition span.hpp:32
void add_event(const char *name) noexcept
Record a timestamped event on the span.
TracingSpan(const char *name) noexcept
Open a child span named name under the currently-active span.
void record_unknown_exception() noexcept
Record an unknown (non-std::exception) failure as an "exception" event and set span status to Error.
void end() noexcept
Mark the end of the span.
void record_exception(const std::exception &xcp) noexcept
Record xcp as an "exception" event and set span status to Error.
void set_status_error(const char *description="") noexcept
Mark the span as having failed. description is optional context.
void set_attribute(const char *key, T value) noexcept
Attach an attribute to the span. Supported value types: bool, std::int64_t, double,...
void set_status_ok() noexcept
Mark the span as having completed successfully.