Skip to content

Commit 2b49690

Browse files
update trace field names for events and links
add prefix event_ for event attributes add prefix link_ for links attributes update timestamp to have nanoseconds
1 parent 0c35ecb commit 2b49690

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

src/otel/otel_utils.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,5 +191,5 @@ pub fn insert_attributes(map: &mut Map<String, Value>, attributes: &[KeyValue])
191191

192192
pub fn convert_epoch_nano_to_timestamp(epoch_ns: i64) -> String {
193193
let dt = DateTime::from_timestamp_nanos(epoch_ns).naive_utc();
194-
dt.format("%Y-%m-%dT%H:%M:%S%.6fZ").to_string()
194+
dt.format("%Y-%m-%dT%H:%M:%S%.9fZ").to_string()
195195
}

src/otel/traces.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*
1717
*/
1818
use opentelemetry_proto::tonic::collector::trace::v1::ExportTraceServiceRequest;
19+
use opentelemetry_proto::tonic::common::v1::KeyValue;
1920
use opentelemetry_proto::tonic::trace::v1::ScopeSpans;
2021
use opentelemetry_proto::tonic::trace::v1::Span;
2122
use opentelemetry_proto::tonic::trace::v1::Status;
@@ -24,6 +25,8 @@ use opentelemetry_proto::tonic::trace::v1::span::Event;
2425
use opentelemetry_proto::tonic::trace::v1::span::Link;
2526
use serde_json::{Map, Value};
2627

28+
use crate::otel::otel_utils::flatten_attributes;
29+
2730
use super::otel_utils::convert_epoch_nano_to_timestamp;
2831
use super::otel_utils::insert_attributes;
2932

@@ -197,7 +200,7 @@ fn flatten_events(events: &[Event], span_start_time_unix_nano: u64) -> Vec<Map<S
197200
),
198201
);
199202

200-
insert_attributes(&mut event_json, &event.attributes);
203+
insert_events_attributes(&mut event_json, &event.attributes);
201204
event_json.insert(
202205
"event_dropped_attributes_count".to_string(),
203206
Value::Number(event.dropped_attributes_count.into()),
@@ -224,7 +227,7 @@ fn flatten_links(links: &[Link]) -> Vec<Map<String, Value>> {
224227
Value::String(hex::encode(&link.trace_id)),
225228
);
226229

227-
insert_attributes(&mut link_json, &link.attributes);
230+
insert_links_attributes(&mut link_json, &link.attributes);
228231
link_json.insert(
229232
"link_dropped_attributes_count".to_string(),
230233
Value::Number(link.dropped_attributes_count.into()),
@@ -397,6 +400,20 @@ fn flatten_span_record(span_record: &Span) -> Vec<Map<String, Value>> {
397400
span_records_json
398401
}
399402

403+
pub fn insert_events_attributes(map: &mut Map<String, Value>, attributes: &[KeyValue]) {
404+
let attributes_json = flatten_attributes(attributes);
405+
for (key, value) in attributes_json {
406+
map.insert(format!("event_{}", key), value);
407+
}
408+
}
409+
410+
pub fn insert_links_attributes(map: &mut Map<String, Value>, attributes: &[KeyValue]) {
411+
let attributes_json = flatten_attributes(attributes);
412+
for (key, value) in attributes_json {
413+
map.insert(format!("link_{}", key), value);
414+
}
415+
}
416+
400417
#[cfg(test)]
401418
mod tests {
402419
use super::*;

0 commit comments

Comments
 (0)