diff --git a/src/data/attribute.rs b/src/data/attribute.rs index faa25356..1b163ba3 100644 --- a/src/data/attribute.rs +++ b/src/data/attribute.rs @@ -4,6 +4,7 @@ use chrono::{DateTime, FixedOffset}; use log::{debug, error}; use protobuf::well_known_types::Struct; use proxy_wasm::hostcalls; +use serde_json::Value; pub const KUADRANT_NAMESPACE: &str = "kuadrant"; @@ -179,12 +180,25 @@ fn process_metadata(s: &Struct, prefix: String) -> Vec<(String, String)> { format!("{prefix}\\.{key}") }; - if value.has_string_value() { - result.push((current_prefix, value.get_string_value().to_string())); - } else if value.has_struct_value() { + let json: Option = if value.has_string_value() { + Some(value.get_string_value().into()) + } else if value.has_bool_value() { + Some(value.get_bool_value().into()) + } else if value.has_null_value() { + Some(Value::Null) + } else if value.has_number_value() { + Some(value.get_number_value().into()) + } else { + None + }; + + if value.has_struct_value() { let nested_struct = value.get_struct_value(); result.extend(process_metadata(nested_struct, current_prefix)); + } else if let Some(v) = json { + result.push((current_prefix, serde_json::to_string(&v).unwrap())); } + } result }