Monitoring System 0.1.0
System resource monitoring with pluggable collectors and alerting
Loading...
Searching...
No Matches
kcenon::monitoring::jaeger_span_data Struct Reference

Jaeger-specific span representation. More...

#include <trace_exporters.h>

Collaboration diagram for kcenon::monitoring::jaeger_span_data:
Collaboration graph

Public Member Functions

std::string to_thrift_json () const
 Convert to Jaeger Thrift format (JSON representation)
 
std::vector< uint8_t > to_protobuf () const
 Convert this span to a Jaeger api_v2 Span protobuf message.
 

Public Attributes

std::string trace_id
 
std::string span_id
 
std::string parent_span_id
 
std::string operation_name
 
std::string service_name
 
std::chrono::microseconds start_time
 
std::chrono::microseconds duration
 
std::vector< std::pair< std::string, std::string > > tags
 
std::vector< std::pair< std::string, std::string > > process_tags
 

Detailed Description

Jaeger-specific span representation.

Definition at line 106 of file trace_exporters.h.

Member Function Documentation

◆ to_protobuf()

std::vector< uint8_t > kcenon::monitoring::jaeger_span_data::to_protobuf ( ) const
inline

Convert this span to a Jaeger api_v2 Span protobuf message.

Field numbers follow jaeger-idl/proto/api_v2/model.proto. Trace IDs are zero-padded to 16 bytes and span IDs to 8 bytes, matching the conventions enforced by the Jaeger collector.

Definition at line 162 of file trace_exporters.h.

162 {
163 jaeger_proto::span out;
164 out.trace_id = protobuf_wire::left_pad(
166 out.span_id = protobuf_wire::left_pad(
168 out.operation_name = operation_name;
169
170 if (!parent_span_id.empty()) {
171 jaeger_proto::span_ref ref;
172 ref.trace_id = out.trace_id;
173 ref.span_id = protobuf_wire::left_pad(
175 ref.ref_type = 0; // CHILD_OF
176 out.references.push_back(std::move(ref));
177 }
178
179 // Timestamp / duration split into (seconds, nanos).
180 auto st_ns = std::chrono::nanoseconds(start_time);
181 out.start_time_seconds = static_cast<std::int64_t>(
182 std::chrono::duration_cast<std::chrono::seconds>(st_ns).count());
183 out.start_time_nanos = static_cast<std::int32_t>(
184 (st_ns - std::chrono::seconds(out.start_time_seconds)).count());
185
186 auto du_ns = std::chrono::nanoseconds(duration);
187 out.duration_seconds = static_cast<std::int64_t>(
188 std::chrono::duration_cast<std::chrono::seconds>(du_ns).count());
189 out.duration_nanos = static_cast<std::int32_t>(
190 (du_ns - std::chrono::seconds(out.duration_seconds)).count());
191
192 for (const auto& [key, value] : tags) {
193 jaeger_proto::key_value kv;
194 kv.key = key;
196 kv.v_str = value;
197 out.tags.push_back(std::move(kv));
198 }
199
200 out.proc.service_name = service_name;
201 for (const auto& [key, value] : process_tags) {
202 jaeger_proto::key_value kv;
203 kv.key = key;
205 kv.v_str = value;
206 out.proc.tags.push_back(std::move(kv));
207 }
208
209 return jaeger_proto::encode_span(out);
210 }
std::vector< std::uint8_t > encode_span(const span &s)
std::vector< std::uint8_t > left_pad(const std::vector< std::uint8_t > &in, std::size_t width)
Left-pad bytes to a target width. Used to normalize 8-byte trace IDs to Jaeger's 16-byte on-wire widt...
std::vector< std::uint8_t > hex_to_bytes(const std::string &hex)
Decode a hexadecimal string into bytes. Odd-length strings are zero-padded on the left; non-hex chara...
std::vector< std::pair< std::string, std::string > > process_tags
std::vector< std::pair< std::string, std::string > > tags
std::chrono::microseconds duration
std::chrono::microseconds start_time

References duration, kcenon::monitoring::jaeger_proto::span::duration_nanos, kcenon::monitoring::jaeger_proto::span::duration_seconds, kcenon::monitoring::jaeger_proto::encode_span(), kcenon::monitoring::protobuf_wire::hex_to_bytes(), kcenon::monitoring::jaeger_proto::key_value::key, kcenon::monitoring::protobuf_wire::left_pad(), kcenon::monitoring::jaeger_proto::span::operation_name, operation_name, parent_span_id, kcenon::monitoring::jaeger_proto::span::proc, process_tags, kcenon::monitoring::jaeger_proto::span_ref::ref_type, kcenon::monitoring::jaeger_proto::span::references, kcenon::monitoring::jaeger_proto::process::service_name, service_name, kcenon::monitoring::jaeger_proto::span::span_id, kcenon::monitoring::jaeger_proto::span_ref::span_id, span_id, start_time, kcenon::monitoring::jaeger_proto::span::start_time_nanos, kcenon::monitoring::jaeger_proto::span::start_time_seconds, kcenon::monitoring::jaeger_proto::string_type, kcenon::monitoring::jaeger_proto::process::tags, kcenon::monitoring::jaeger_proto::span::tags, tags, kcenon::monitoring::jaeger_proto::span::trace_id, kcenon::monitoring::jaeger_proto::span_ref::trace_id, trace_id, kcenon::monitoring::jaeger_proto::key_value::v_str, and kcenon::monitoring::jaeger_proto::key_value::v_type.

Referenced by TEST_F(), and TEST_F().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ to_thrift_json()

std::string kcenon::monitoring::jaeger_span_data::to_thrift_json ( ) const
inline

Convert to Jaeger Thrift format (JSON representation)

Definition at line 120 of file trace_exporters.h.

120 {
121 std::ostringstream json;
122 json << "{";
123 json << "\"traceIdHigh\":0,";
124 json << "\"traceIdLow\":" << std::hash<std::string>{}(trace_id) << ",";
125 json << "\"spanId\":" << std::hash<std::string>{}(span_id) << ",";
126 json << "\"parentSpanId\":" << (parent_span_id.empty() ? "0" : std::to_string(std::hash<std::string>{}(parent_span_id))) << ",";
127 json << "\"operationName\":\"" << operation_name << "\",";
128 json << "\"startTime\":" << start_time.count() << ",";
129 json << "\"duration\":" << duration.count() << ",";
130
131 // Tags
132 json << "\"tags\":[";
133 bool first = true;
134 for (const auto& [key, value] : tags) {
135 if (!first) json << ",";
136 json << "{\"key\":\"" << key << "\",\"vType\":\"STRING\",\"vStr\":\"" << value << "\"}";
137 first = false;
138 }
139 json << "],";
140
141 // Process
142 json << "\"process\":{\"serviceName\":\"" << service_name << "\",\"tags\":[";
143 first = true;
144 for (const auto& [key, value] : process_tags) {
145 if (!first) json << ",";
146 json << "{\"key\":\"" << key << "\",\"vType\":\"STRING\",\"vStr\":\"" << value << "\"}";
147 first = false;
148 }
149 json << "]}";
150
151 json << "}";
152 return json.str();
153 }

References duration, operation_name, parent_span_id, process_tags, service_name, span_id, start_time, tags, and trace_id.

Member Data Documentation

◆ duration

std::chrono::microseconds kcenon::monitoring::jaeger_span_data::duration

◆ operation_name

std::string kcenon::monitoring::jaeger_span_data::operation_name

◆ parent_span_id

std::string kcenon::monitoring::jaeger_span_data::parent_span_id

◆ process_tags

std::vector<std::pair<std::string, std::string> > kcenon::monitoring::jaeger_span_data::process_tags

◆ service_name

std::string kcenon::monitoring::jaeger_span_data::service_name

◆ span_id

std::string kcenon::monitoring::jaeger_span_data::span_id

◆ start_time

std::chrono::microseconds kcenon::monitoring::jaeger_span_data::start_time

◆ tags

std::vector<std::pair<std::string, std::string> > kcenon::monitoring::jaeger_span_data::tags

◆ trace_id

std::string kcenon::monitoring::jaeger_span_data::trace_id

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