Skip to content

Commit 038df7c

Browse files
refactor
1 parent 0eefe77 commit 038df7c

File tree

5 files changed

+19
-20
lines changed

5 files changed

+19
-20
lines changed

src/handlers/http/ingest.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ impl actix_web::ResponseError for PostError {
498498
PostError::MissingTimePartition(_) => StatusCode::BAD_REQUEST,
499499
PostError::KnownFormat(_) => StatusCode::BAD_REQUEST,
500500
PostError::IncorrectLogFormat(_) => StatusCode::BAD_REQUEST,
501-
PostError::OtelError(_) => StatusCode::EXPECTATION_FAILED,
501+
PostError::OtelError(_) => StatusCode::BAD_REQUEST,
502502
}
503503
}
504504

src/otel/logs.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ pub const OTEL_LOG_KNOWN_FIELD_LIST: [&str; 16] = [
3737
"scope_log_schema_url",
3838
"scope_dropped_attributes_count",
3939
"resource_dropped_attributes_count",
40-
"resource_schema_url",
40+
"schema_url",
4141
"time_unix_nano",
4242
"observed_time_unix_nano",
4343
"severity_number",
@@ -178,8 +178,8 @@ pub fn flatten_otel_logs(message: &LogsData) -> Result<Vec<Value>, OtelError> {
178178
resource_logs_json.extend(resource_log_json.clone());
179179

180180
let attribute_count = resource_logs_json
181-
.keys()
182-
.filter(|key| !known_fields.contains(key.as_str()))
181+
.iter()
182+
.filter(|(key, _)| !known_fields.contains(key.as_str()))
183183
.count();
184184
// Check if the number of attributes exceeds the allowed limit
185185
if attribute_count > PARSEABLE.options.otel_attributes_allowed_limit {

src/otel/metrics.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use super::otel_utils::{
3232
convert_epoch_nano_to_timestamp, insert_attributes, insert_number_if_some,
3333
};
3434

35-
pub const OTEL_METRICS_KNOWN_FIELD_LIST: [&str; 35] = [
35+
pub const OTEL_METRICS_KNOWN_FIELD_LIST: [&str; 34] = [
3636
"metric_name",
3737
"metric_description",
3838
"metric_unit",
@@ -63,11 +63,10 @@ pub const OTEL_METRICS_KNOWN_FIELD_LIST: [&str; 35] = [
6363
"metric_type",
6464
"scope_name",
6565
"scope_version",
66-
"scope_metrics_schema_url",
66+
"scope_schema_url",
6767
"scope_dropped_attributes_count",
6868
"resource_dropped_attributes_count",
6969
"resource_schema_url",
70-
"resource_metrics_schema_url",
7170
];
7271

7372
/// otel metrics event has json array for exemplar
@@ -544,7 +543,7 @@ pub fn flatten_otel_metrics(message: MetricsData) -> Result<Vec<Value>, OtelErro
544543
}
545544

546545
scope_metrics_json.insert(
547-
"scope_metrics_schema_url".to_string(),
546+
"scope_schema_url".to_string(),
548547
Value::String(scope_metric.schema_url.clone()),
549548
);
550549

@@ -556,7 +555,7 @@ pub fn flatten_otel_metrics(message: MetricsData) -> Result<Vec<Value>, OtelErro
556555
}
557556

558557
resource_metrics_json.insert(
559-
"resource_metrics_schema_url".to_string(),
558+
"resource_schema_url".to_string(),
560559
Value::String(record.schema_url.clone()),
561560
);
562561

@@ -566,8 +565,8 @@ pub fn flatten_otel_metrics(message: MetricsData) -> Result<Vec<Value>, OtelErro
566565
}
567566

568567
let attribute_count = resource_metric_json
569-
.keys()
570-
.filter(|key| !known_fields.contains(key.as_str()))
568+
.iter()
569+
.filter(|(key, _)| !known_fields.contains(key.as_str()))
571570
.count();
572571

573572
// Check if the number of attributes exceeds the allowed limit

src/otel/otel_utils.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ use chrono::DateTime;
2020
use opentelemetry_proto::tonic::common::v1::{
2121
any_value::Value as OtelValue, AnyValue, ArrayValue, KeyValue, KeyValueList,
2222
};
23+
use serde::Serialize;
2324
use serde_json::{Map, Value};
2425

2526
// Value can be one of types - String, Bool, Int, Double, ArrayValue, AnyValue, KeyValueList, Byte
@@ -149,7 +150,7 @@ pub fn value_to_string(value: serde_json::Value) -> String {
149150
}
150151
}
151152

152-
pub fn flatten_attributes(attributes: &Vec<KeyValue>) -> Map<String, Value> {
153+
pub fn flatten_attributes(attributes: &[KeyValue]) -> Map<String, Value> {
153154
let mut attributes_json: Map<String, Value> = Map::new();
154155
for attribute in attributes {
155156
let key = &attribute.key;
@@ -182,7 +183,7 @@ pub fn insert_bool_if_some(map: &mut Map<String, Value>, key: &str, option: &Opt
182183
}
183184
}
184185

185-
pub fn insert_attributes(map: &mut Map<String, Value>, attributes: &Vec<KeyValue>) {
186+
pub fn insert_attributes(map: &mut Map<String, Value>, attributes: &[KeyValue]) {
186187
let attributes_json = flatten_attributes(attributes);
187188
for (key, value) in attributes_json {
188189
map.insert(key, value);
@@ -194,7 +195,7 @@ pub fn convert_epoch_nano_to_timestamp(epoch_ns: i64) -> String {
194195
dt.format("%Y-%m-%dT%H:%M:%S%.6fZ").to_string()
195196
}
196197

197-
#[derive(Debug, thiserror::Error)]
198+
#[derive(Debug, thiserror::Error, Serialize)]
198199
pub enum OtelError {
199200
#[error("Ingestion failed because the attributes count {0} exceeded the threshold of {1}")]
200201
AttributeCountExceeded(usize, usize),

src/otel/traces.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use crate::parseable::PARSEABLE;
3232
use super::otel_utils::convert_epoch_nano_to_timestamp;
3333
use super::otel_utils::insert_attributes;
3434

35-
pub const OTEL_TRACES_KNOWN_FIELD_LIST: [&str; 31] = [
35+
pub const OTEL_TRACES_KNOWN_FIELD_LIST: [&str; 30] = [
3636
"scope_name",
3737
"scope_version",
3838
"scope_schema_url",
@@ -43,7 +43,6 @@ pub const OTEL_TRACES_KNOWN_FIELD_LIST: [&str; 31] = [
4343
"span_span_id",
4444
"span_name",
4545
"span_parent_span_id",
46-
"flags",
4746
"name",
4847
"span_kind",
4948
"span_kind_description",
@@ -96,7 +95,7 @@ fn flatten_scope_span(scope_span: &ScopeSpans) -> Vec<Map<String, Value>> {
9695

9796
for span_json in &mut vec_scope_span_json {
9897
span_json.insert(
99-
"schema_url".to_string(),
98+
"scope_schema_url".to_string(),
10099
Value::String(scope_span.schema_url.clone()),
101100
);
102101
}
@@ -127,7 +126,7 @@ pub fn flatten_otel_traces(message: &TracesData) -> Result<Vec<Value>, OtelError
127126
}
128127

129128
resource_span_json.insert(
130-
"schema_url".to_string(),
129+
"resource_schema_url".to_string(),
131130
Value::String(record.schema_url.clone()),
132131
);
133132

@@ -137,8 +136,8 @@ pub fn flatten_otel_traces(message: &TracesData) -> Result<Vec<Value>, OtelError
137136
}
138137

139138
let attribute_count = resource_spans_json
140-
.keys()
141-
.filter(|key| !known_fields.contains(key.as_str()))
139+
.iter()
140+
.filter(|(key, _)| !known_fields.contains(key.as_str()))
142141
.count();
143142

144143
// Check if the number of attributes exceeds the allowed limit

0 commit comments

Comments
 (0)