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

Zipkin-specific span representation. More...

#include <trace_exporters.h>

Collaboration diagram for kcenon::monitoring::zipkin_span_data:
Collaboration graph

Public Member Functions

std::string to_json_v2 () const
 Convert to Zipkin JSON v2 format.
 
std::vector< uint8_t > to_protobuf () const
 Convert this span to a Zipkin Span protobuf message.
 

Public Attributes

std::string trace_id
 
std::string span_id
 
std::string parent_id
 
std::string name
 
std::string kind
 
std::chrono::microseconds timestamp
 
std::chrono::microseconds duration
 
std::string local_endpoint_service_name
 
std::string remote_endpoint_service_name
 
std::unordered_map< std::string, std::string > tags
 
bool shared = false
 

Detailed Description

Zipkin-specific span representation.

Definition at line 265 of file trace_exporters.h.

Member Function Documentation

◆ to_json_v2()

std::string kcenon::monitoring::zipkin_span_data::to_json_v2 ( ) const
inline

Convert to Zipkin JSON v2 format.

Definition at line 281 of file trace_exporters.h.

281 {
282 std::ostringstream json;
283 json << "{";
284 json << "\"traceId\":\"" << trace_id << "\",";
285 json << "\"id\":\"" << span_id << "\",";
286 if (!parent_id.empty()) {
287 json << "\"parentId\":\"" << parent_id << "\",";
288 }
289 json << "\"name\":\"" << name << "\",";
290 json << "\"kind\":\"" << kind << "\",";
291 json << "\"timestamp\":" << timestamp.count() << ",";
292 json << "\"duration\":" << duration.count() << ",";
293
294 // Local endpoint
295 json << "\"localEndpoint\":{\"serviceName\":\"" << local_endpoint_service_name << "\"},";
296
297 // Remote endpoint (if set)
298 if (!remote_endpoint_service_name.empty()) {
299 json << "\"remoteEndpoint\":{\"serviceName\":\"" << remote_endpoint_service_name << "\"},";
300 }
301
302 // Tags
303 json << "\"tags\":{";
304 bool first = true;
305 for (const auto& [key, value] : tags) {
306 if (!first) json << ",";
307 json << "\"" << key << "\":\"" << value << "\"";
308 first = false;
309 }
310 json << "}";
311
312 if (shared) {
313 json << ",\"shared\":true";
314 }
315
316 json << "}";
317 return json.str();
318 }
std::unordered_map< std::string, std::string > tags
std::chrono::microseconds duration
std::chrono::microseconds timestamp

References duration, kind, local_endpoint_service_name, name, parent_id, remote_endpoint_service_name, shared, span_id, tags, timestamp, and trace_id.

◆ to_protobuf()

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

Convert this span to a Zipkin Span protobuf message.

Field numbers follow openzipkin/zipkin-api/zipkin.proto. Trace IDs are expected to be 8 or 16 hex bytes; shorter inputs are zero-padded.

Definition at line 326 of file trace_exporters.h.

326 {
327 zipkin_proto::span out;
328 auto trace_bytes = protobuf_wire::hex_to_bytes(trace_id);
329 // Zipkin accepts 8 or 16 byte trace IDs; normalize the common
330 // shorter/empty/non-hex inputs to 8 bytes so the wire always carries
331 // a valid ID (Zipkin rejects spans without a trace ID).
332 if (trace_bytes.size() == 16) {
333 out.trace_id = std::move(trace_bytes);
334 } else {
335 out.trace_id = protobuf_wire::left_pad(trace_bytes, 8);
336 }
339 if (!parent_id.empty()) {
340 out.parent_id = protobuf_wire::left_pad(
342 }
343 out.kind = zipkin_proto::parse_kind(kind);
344 out.name = name;
345 out.timestamp = static_cast<std::uint64_t>(timestamp.count());
346 out.duration = static_cast<std::uint64_t>(duration.count());
347 out.local_endpoint.service_name = local_endpoint_service_name;
348 out.remote_endpoint.service_name = remote_endpoint_service_name;
349 out.shared = shared;
350 for (const auto& [key, value] : tags) {
351 out.tags.emplace_back(key, value);
352 }
353 return zipkin_proto::encode_span(out);
354 }
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...
span_kind parse_kind(const std::string &value)
Convert a textual Zipkin kind (e.g. "CLIENT") to its enum value.
std::vector< std::uint8_t > encode_span(const span &s)

References kcenon::monitoring::zipkin_proto::span::duration, duration, kcenon::monitoring::zipkin_proto::encode_span(), kcenon::monitoring::protobuf_wire::hex_to_bytes(), kcenon::monitoring::zipkin_proto::span::id, kcenon::monitoring::zipkin_proto::span::kind, kind, kcenon::monitoring::protobuf_wire::left_pad(), kcenon::monitoring::zipkin_proto::span::local_endpoint, local_endpoint_service_name, kcenon::monitoring::zipkin_proto::span::name, name, kcenon::monitoring::zipkin_proto::span::parent_id, parent_id, kcenon::monitoring::zipkin_proto::parse_kind(), kcenon::monitoring::zipkin_proto::span::remote_endpoint, remote_endpoint_service_name, kcenon::monitoring::zipkin_proto::endpoint::service_name, kcenon::monitoring::zipkin_proto::span::shared, shared, span_id, kcenon::monitoring::zipkin_proto::span::tags, tags, kcenon::monitoring::zipkin_proto::span::timestamp, timestamp, kcenon::monitoring::zipkin_proto::span::trace_id, and trace_id.

Referenced by TEST_F(), and TEST_F().

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

Member Data Documentation

◆ duration

std::chrono::microseconds kcenon::monitoring::zipkin_span_data::duration

◆ kind

std::string kcenon::monitoring::zipkin_span_data::kind

◆ local_endpoint_service_name

std::string kcenon::monitoring::zipkin_span_data::local_endpoint_service_name

◆ name

std::string kcenon::monitoring::zipkin_span_data::name

◆ parent_id

std::string kcenon::monitoring::zipkin_span_data::parent_id

◆ remote_endpoint_service_name

std::string kcenon::monitoring::zipkin_span_data::remote_endpoint_service_name

Definition at line 274 of file trace_exporters.h.

Referenced by to_json_v2(), and to_protobuf().

◆ shared

bool kcenon::monitoring::zipkin_span_data::shared = false

Definition at line 276 of file trace_exporters.h.

Referenced by to_json_v2(), and to_protobuf().

◆ span_id

std::string kcenon::monitoring::zipkin_span_data::span_id

◆ tags

std::unordered_map<std::string, std::string> kcenon::monitoring::zipkin_span_data::tags

◆ timestamp

std::chrono::microseconds kcenon::monitoring::zipkin_span_data::timestamp

◆ trace_id

std::string kcenon::monitoring::zipkin_span_data::trace_id

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