Propagate Open Telemetry context from CRI-O to conmon-rs
saschagrunert opened this issue · comments
We can use the Open Telemetry context propagation to link spans between CRI-O and conmon-rs. This would mean that we have to use the global Text Map Propagator on the client side as well as on the conmon-rs server side to inject/extract the spans.
Since capnproto does neither natively support serializing hash maps nor carrying headers, we have to change each RPC to additionally contain the metadata:
struct VersionRequest {
metadata @0 :Data;
verbose @1 :Bool;
}
I assume that we introduce a new metadata type like:
struct MetadataMap<'a>(HashMap<&'a str, &'a str>);
impl<'a> Extractor for MetadataMap<'a> {
fn get(&self, key: &str) -> Option<&str> {
self.0.get(key).map(|x| x.clone())
}
/// Collect all the keys from the MetadataMap.
fn keys(&self) -> Vec<&str> {
self.0.keys().map(|k| k.clone()).collect::<Vec<_>>()
}
}
And then (for each RPC) restore the spans:
let metadata = pry!(req.get_metadata());
let hashmap: HashMap<&str, &str> = pry_err!(serde_json::from_slice(metadata));
let metadata_map = MetadataMap(hashmap);
let parent_cx = global::get_text_map_propagator(|prop| prop.extract(&metadata_map));
self.tracer().start_with_context("version", &parent_cx);
Examples:
clever!