Skip to content

Commit 2e2d5e1

Browse files
update known attribute list
1 parent dcce86f commit 2e2d5e1

File tree

4 files changed

+31
-14
lines changed

4 files changed

+31
-14
lines changed

src/otel/logs.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ pub const OTEL_LOG_KNOWN_FIELD_LIST: [&str; 6] = [
3535
"span_id",
3636
"trace_id",
3737
];
38-
3938
/// otel log event has severity number
4039
/// there is a mapping of severity number to severity text provided in proto
4140
/// this function fetches the severity text from the severity number
@@ -182,11 +181,17 @@ pub fn flatten_otel_logs(message: &LogsData) -> Vec<Value> {
182181
vec_otel_json.extend(vec_resource_logs_json);
183182
}
184183
// Add common attributes as one attribute in stringified array to each log record
184+
let other_attributes = match serde_json::to_string(&other_attributes) {
185+
Ok(s) => s,
186+
Err(e) => {
187+
tracing::warn!("failed to serialise OTEL other_attributes: {e}");
188+
String::new()
189+
}
190+
};
185191
for log_record_json in &mut vec_otel_json {
186-
let other_attributes = serde_json::to_string(&other_attributes).unwrap();
187192
log_record_json.insert(
188193
"other_attributes".to_string(),
189-
Value::String(other_attributes),
194+
Value::String(other_attributes.clone()),
190195
);
191196
}
192197
vec_otel_json.into_iter().map(Value::Object).collect()

src/otel/metrics.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -548,12 +548,18 @@ pub fn flatten_otel_metrics(message: MetricsData) -> Vec<Value> {
548548
}
549549
vec_otel_json.extend(vec_scope_metrics_json);
550550
}
551-
// Add common attributes as one attribute in stringified array to each log record
552-
for log_record_json in &mut vec_otel_json {
553-
let other_attributes_json_string = serde_json::to_string(&other_attributes).unwrap();
554-
log_record_json.insert(
551+
// Add common attributes as one attribute in stringified array to each metric record
552+
let other_attributes = match serde_json::to_string(&other_attributes) {
553+
Ok(s) => s,
554+
Err(e) => {
555+
tracing::warn!("failed to serialise OTEL other_attributes: {e}");
556+
String::new()
557+
}
558+
};
559+
for metric_record_json in &mut vec_otel_json {
560+
metric_record_json.insert(
555561
"other_attributes".to_string(),
556-
Value::String(other_attributes_json_string),
562+
Value::String(other_attributes.clone()),
557563
);
558564
}
559565
vec_otel_json.into_iter().map(Value::Object).collect()

src/otel/otel_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use opentelemetry_proto::tonic::common::v1::{
2222
};
2323
use serde_json::{Map, Value};
2424

25-
const KNOWN_ATTRIBUTES_PREFIX: [&str; 3] = ["http", "url", "service"];
25+
const KNOWN_ATTRIBUTES_PREFIX: [&str; 6] = ["http", "url", "service", "os", "host", "telemetry"];
2626

2727
// Value can be one of types - String, Bool, Int, Double, ArrayValue, AnyValue, KeyValueList, Byte
2828
pub fn collect_json_from_value(key: &String, value: OtelValue) -> Map<String, Value> {

src/otel/traces.rs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,18 @@ pub fn flatten_otel_traces(message: &TracesData) -> Vec<Value> {
126126

127127
vec_otel_json.extend(vec_resource_spans_json);
128128
}
129-
// Add common attributes as one attribute in stringified array to each log record
130-
for log_record_json in &mut vec_otel_json {
131-
let other_attributes = serde_json::to_string(&other_attributes).unwrap();
132-
log_record_json.insert(
129+
// Add common attributes as one attribute in stringified array to each span record
130+
let other_attributes = match serde_json::to_string(&other_attributes) {
131+
Ok(s) => s,
132+
Err(e) => {
133+
tracing::warn!("failed to serialise OTEL other_attributes: {e}");
134+
String::new()
135+
}
136+
};
137+
for span_record_json in &mut vec_otel_json {
138+
span_record_json.insert(
133139
"other_attributes".to_string(),
134-
Value::String(other_attributes),
140+
Value::String(other_attributes.clone()),
135141
);
136142
}
137143
vec_otel_json.into_iter().map(Value::Object).collect()

0 commit comments

Comments
 (0)