use serde::{Deserialize, Serialize};
use std::time::Duration;
use kafka::producer::{Producer, Record, RequiredAcks};
use opentelemetry::{global, KeyValue};
#[tokio::main]
async fn main() {
let mut producer =
Producer::from_hosts(vec!("localhost:29092".to_owned()))
.with_ack_timeout(Duration::from_secs(1))
.with_required_acks(RequiredAcks::One)
.create()
.unwrap();
let meter = global::meter("test");
let counter = meter.u64_counter("my_counter").init();
counter.add(1, &[KeyValue::new("cpu", "80")]);
counter.add(1, &[KeyValue::new("cpu", "90")]);
let mut buf = String::with_capacity(2);
for _ in 0..10 {
// producer.send(&Record::from_value("KubeStatistics", serde_json::to_string("test").unwrap())).unwrap();
/* How to pass metrics data over here */
buf.clear();
}
}
In the above Rust code, I am trying to create a counter metrics using opentelemetry and sending it to my kafka.
I have created a "counter", how am I supposed to pass this counter to the Kafka. Am I supposed to write a new exporter for Kafka ? If yes, is there any references available ? OR can I get an example snippet ?