Skip to content

Commit 1ce4f57

Browse files
fix: removed pre-compiled otel files
used `opentelemetry-proto` crate deleted compiled rust files and protobuf files
1 parent f58c89a commit 1ce4f57

File tree

19 files changed

+671
-3579
lines changed

19 files changed

+671
-3579
lines changed

Cargo.lock

Lines changed: 92 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ prost = "0.13.3"
106106
prometheus-parse = "0.2.5"
107107
sha2 = "0.10.8"
108108
tracing = "0.1.41"
109+
opentelemetry-proto = "0.27.0"
109110

110111
[build-dependencies]
111112
cargo_toml = "0.20.1"

src/handlers/http/modal/utils/ingest_utils.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,18 +16,17 @@
1616
*
1717
*/
1818

19-
use std::{
20-
collections::{BTreeMap, HashMap},
21-
sync::Arc,
22-
};
23-
2419
use actix_web::HttpRequest;
2520
use anyhow::anyhow;
2621
use arrow_schema::Field;
2722
use bytes::Bytes;
2823
use chrono::{DateTime, NaiveDateTime, Utc};
2924
use itertools::Itertools;
3025
use serde_json::Value;
26+
use std::{
27+
collections::{BTreeMap, HashMap},
28+
sync::Arc,
29+
};
3130

3231
use crate::{
3332
event::{

src/handlers/http/otel.rs

Lines changed: 61 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -15,83 +15,92 @@
1515
* along with this program. If not, see <http://www.gnu.org/licenses/>.
1616
*
1717
*/
18+
1819
pub mod logs;
1920
pub mod metrics;
20-
#[allow(clippy::all)]
21-
pub mod proto;
2221
pub mod traces;
23-
use proto::common::v1::KeyValue;
22+
use opentelemetry_proto::tonic::common::v1::{any_value::Value as OtelValue, AnyValue, KeyValue};
2423
use serde_json::Value;
2524
use std::collections::BTreeMap;
2625
// Value can be one of types - String, Bool, Int, Double, ArrayValue, AnyValue, KeyValueList, Byte
27-
pub fn collect_json_from_any_value(
28-
key: &String,
29-
value: super::otel::proto::common::v1::Value,
30-
) -> BTreeMap<String, Value> {
26+
pub fn collect_json_from_value(key: &String, value: OtelValue) -> BTreeMap<String, Value> {
3127
let mut value_json: BTreeMap<String, Value> = BTreeMap::new();
32-
insert_if_some(&mut value_json, key, &value.str_val);
33-
insert_bool_if_some(&mut value_json, key, &value.bool_val);
34-
insert_if_some(&mut value_json, key, &value.int_val);
35-
insert_number_if_some(&mut value_json, key, &value.double_val);
36-
37-
//ArrayValue is a vector of AnyValue
38-
//traverse by recursively calling the same function
39-
if value.array_val.is_some() {
40-
let array_val = value.array_val.as_ref().unwrap();
41-
let values = &array_val.values;
42-
for value in values {
43-
let array_value_json = collect_json_from_any_value(key, value.clone());
44-
for key in array_value_json.keys() {
45-
value_json.insert(
46-
format!(
47-
"{}_{}",
48-
key.to_owned(),
49-
value_to_string(array_value_json[key].to_owned())
50-
),
51-
array_value_json[key].to_owned(),
52-
);
28+
match value {
29+
OtelValue::StringValue(str_val) => {
30+
value_json.insert(key.to_string(), Value::String(str_val));
31+
}
32+
OtelValue::BoolValue(bool_val) => {
33+
value_json.insert(key.to_string(), Value::Bool(bool_val));
34+
}
35+
OtelValue::IntValue(int_val) => {
36+
value_json.insert(key.to_string(), Value::String(int_val.to_string()));
37+
}
38+
OtelValue::DoubleValue(double_val) => {
39+
if let Some(number) = serde_json::Number::from_f64(double_val) {
40+
value_json.insert(key.to_string(), Value::Number(number));
5341
}
5442
}
55-
}
56-
57-
//KeyValueList is a vector of KeyValue
58-
//traverse through each element in the vector
59-
if value.kv_list_val.is_some() {
60-
let kv_list_val = value.kv_list_val.unwrap();
61-
for key_value in kv_list_val.values {
62-
let value = key_value.value;
63-
if value.is_some() {
64-
let value = value.unwrap();
65-
let key_value_json = collect_json_from_any_value(key, value);
66-
67-
for key in key_value_json.keys() {
43+
OtelValue::ArrayValue(array_val) => {
44+
let values = &array_val.values;
45+
for value in values {
46+
let array_value_json = collect_json_from_anyvalue(key, value.clone());
47+
for key in array_value_json.keys() {
6848
value_json.insert(
6949
format!(
70-
"{}_{}_{}",
50+
"{}_{}",
7151
key.to_owned(),
72-
key_value.key,
73-
value_to_string(key_value_json[key].to_owned())
52+
value_to_string(array_value_json[key].to_owned())
7453
),
75-
key_value_json[key].to_owned(),
54+
array_value_json[key].to_owned(),
7655
);
7756
}
7857
}
7958
}
59+
OtelValue::KvlistValue(kv_list_val) => {
60+
for key_value in kv_list_val.values {
61+
let value = key_value.value;
62+
if value.is_some() {
63+
let value = value.unwrap();
64+
let key_value_json = collect_json_from_anyvalue(key, value.clone());
65+
66+
for key in key_value_json.keys() {
67+
value_json.insert(
68+
format!(
69+
"{}_{}_{}",
70+
key.to_owned(),
71+
key_value.key,
72+
value_to_string(key_value_json[key].to_owned())
73+
),
74+
key_value_json[key].to_owned(),
75+
);
76+
}
77+
}
78+
}
79+
}
80+
OtelValue::BytesValue(bytes_val) => {
81+
value_json.insert(
82+
key.to_string(),
83+
Value::String(String::from_utf8_lossy(&bytes_val).to_string()),
84+
);
85+
}
8086
}
81-
insert_if_some(&mut value_json, key, &value.bytes_val);
8287

8388
value_json
8489
}
8590

91+
pub fn collect_json_from_anyvalue(key: &String, value: AnyValue) -> BTreeMap<String, Value> {
92+
collect_json_from_value(key, value.value.unwrap())
93+
}
94+
8695
//traverse through Value by calling function ollect_json_from_any_value
8796
pub fn collect_json_from_values(
88-
values: &Option<super::otel::proto::common::v1::Value>,
97+
values: &Option<AnyValue>,
8998
key: &String,
9099
) -> BTreeMap<String, Value> {
91100
let mut value_json: BTreeMap<String, Value> = BTreeMap::new();
92101

93102
for value in values.iter() {
94-
value_json = collect_json_from_any_value(key, value.clone());
103+
value_json = collect_json_from_anyvalue(key, value.clone());
95104
}
96105

97106
value_json
@@ -142,11 +151,9 @@ pub fn insert_bool_if_some(map: &mut BTreeMap<String, Value>, key: &str, option:
142151
}
143152
}
144153

145-
pub fn insert_attributes(map: &mut BTreeMap<String, Value>, attributes: &Option<Vec<KeyValue>>) {
146-
if let Some(attrs) = attributes {
147-
let attributes_json = flatten_attributes(attrs);
148-
for (key, value) in attributes_json {
149-
map.insert(key, value);
150-
}
154+
pub fn insert_attributes(map: &mut BTreeMap<String, Value>, attributes: &Vec<KeyValue>) {
155+
let attributes_json = flatten_attributes(attributes);
156+
for (key, value) in attributes_json {
157+
map.insert(key, value);
151158
}
152159
}

0 commit comments

Comments
 (0)